Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

18. Aused car lot contains cars of vario makes and models. The size of a car lot

ID: 3839942 • Letter: 1

Question

18. Aused car lot contains cars of vario makes and models. The size of a car lotisfixed. The owner of the car lo wants to inventory the cars he has available. For the inventory, he/she needs the following information about each car: Make (Toyota, Ford, etc.) Year (1997, 2001, etc.) eage(120734.6, 23555.2, etc.) Cost (20000.00, 24500.00, etc.) When a new car is created, the make, the car year, and the mileage are given. The cars are occasionally taken fortest rides. A test ride alters the mileage of the car. The price of the car is set by the owner of the car lot. The car dealer will eventually need to print all of the information about each car in the lot. It will also be necessary for the car dealer to request and print a list of all cars with a specified year and make. Implement the Car class. In implementing the class, you should: Choose appropriate variable names, parameter names, and method names. Properly identify access modifiers (private, public) of each method and instance field. Include a tostring that will print the information about a car. Consider the CarLot class partially implemented below. public class CarLotf public CarLot 0H lot new Car[MAX CARS]; //Prints the information about the cars in the car lot. public void addCar (Car aNewCar) public void printCarsInLot (00...) Fills the array list with cars in the car lot that have the same year and make as the parameters passed to the method. private ArrayList

Explanation / Answer

Question 19

Answer:

public void printCarsInLot() {
       for(Car car: lot) {
       System.out.println("Make: "+car.getMake()+" Year: "+car.getYear()+" Mileage: "+car.getMileage()+" Cost: "+car.getCost());
       }
   }

Question 20

Answer:

private ArrayList findMatchingCars(int year, String make) {
       ArrayList list = new ArrayList();
       for(Car car: lot){
           if(car.getMake().equalsIgnoreCase(make) && car.getYear() == year) {
               list.add(car);
           }
       }
       return list;
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote