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 various and of Make can he available. The car Th

ID: 3839938 • Letter: 1

Question



18. Aused car lot contains cars various and of Make can he available. The car The owner of car (Toyota, the helshe needs the Ford, bout etc.) Year 2001, etc) cost (20000.00, etc.) 24soo etc) for n a new car is created, the make the car year, and the mileage are given. The test rides. A test ride the milea The car dealer will eventually of the The the car set by the owner of the necessary need to car for the car dealer print all of the information about each car in the lot. win also be Implement to request and print a of all cars with a specified year and make list the Car the should: Choose appropriate variable names, parameter names, and method Properly identify access modifiers names. include a tostring0 that (private, of each method and instance print the information about a car field Consider the Carlot class partially implemented below public class Carlotf public CarLot (if lota new CarlMAX CARS]; //Prints the information about the cars in the car lot. public void addCar (Car aNe wcar)(...) public void printCarslnLot (01...) Fills the array list with cars in the car lot that have the same year and make as the parameters passed to method. private ArrayList

Explanation / Answer

The Car class implementation is as follows:

public class Car {
     private String Make;
     private int Year;
     private double Mileage;
     private double Cost;
     public Car(String mk, int yr, double ml, double cs){
          Make = mk;
          Year = yr;
          Mileage = ml;
          Cost = cs;
     }
     public void setMake(String s){
            Make = s;
     }
     public void setYear(int a){
            Year = a;
     }
     public void setMileage(double a){
            Mileage = a;
     }
     public void setCost(double a){
            Cost = a;
     }
     public String getMake(){
            return Make;
     }
     public int getYear(){
            return Year;
     }
     public double getMileage(){
            return Mileage;
     }
     public double getCost(){
            return Cost;
     }
     public void toString(){
          System.out.println(Make + " " + Year + " " + Mileage + " " + Cost);
     }
}

public class CarLot {
      private static final int NUM_CARS = 100;
      private Car[] lot;
      private static int numberOfCars = 0;    // Current size of the lot.Can not be more that MAX_CARS
      public CarLot(){
         lot = new Car[MAX_CARS];
        
      }
     
      public void addCar (Car a){
         if (numberOfCars == MAX_CARS)
            System.out.println("Lot is Full, can not add");
         if (numberOfCars < MAX_CARS){
             lot[lotsize] = a;
             lotsize++;  
         }
      }
      public ArrayList<Car> findMatchingCars(int year, String make){
          int i;
          ArrayList<Car> list = new ArrayList<Car>();
          for (i = 0; i<numberOfCars; i++){
              if (lot[i].getMake() == make && lot[i].getYear() == year)
                  list.add(lot[i]);
          }
          return list;
      }
      public void printMatchingCars(int year, String make){
          int i;
          for (i = 0; i<numberOfCars; i++){
              if (lot[i].getMake() == make && lot[i].getYear() == year)
                  lot[i].toString();
          }
           
      }
}

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