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

You\'ve taked a part-time job as a used car salesperson. Your the following cars

ID: 3596342 • Letter: Y

Question

You've taked a part-time job as a used car salesperson. Your the following cars on his lot: employer, Discount Dave's Used Cars, has YEAR MAKE MODEL MILEAGE LIST PRICE 2015 Chevy Nova 40000 $18950.00 2013 Chevy Astro 80000 $17950.00 2017 Toyota Rav4 50000 $22950.00 2014 Toyota Supra 110000 $16950.00 Write a class called UsedCarlookup that asks the customer to select a car manufacturer maximum mileage, and a maximum list price. The program then checks if a car matching that description is available using the table above, then prints either the matching carls), or the message "No cars matching that description are available" to select a car manufacturer, a For example, if a customer asks for $20000 or less, your program would report that a 2015 Chevy Nova with 40000 miles is available for $18950.00. However, if a customer asks for a Toyota, with 100000 miles or less for a list price of $20000 or less, your program would report the message "No cars matching that description are available" You may use either a Scanner or JOptionPane to read user input. The program performs no input validation. Write the code to minimize the number of paths in the conditional logic. The message "No cars matching that description are available" should be printed at only one place in your code

Explanation / Answer

import java.io.*;
import java.util.*;


class UsedCar{

private int year;
private String make;
private String model;
private int mileage;
private double list_price;
public UsedCar(int yr, String mk, String md,int ml,double price){

     year = yr;
     make = mk;
     model = md;
     mileage = ml;
     list_price = price;
}
int getYear(){
      return year;
}
String getMake(){
      return make;
}
String getModel(){
      return model;
}
int getMileage(){
      return mileage;
}
double getListPrice(){
      return list_price;
}

}


public class UsedCarLookup{

     public static void main(String[] args){

      UsedCar[] list = new UsedCar[4];
      list[0] = new UsedCar(2015,"Chevy", "Nova",40000, 18950.00);
      list[1] = new UsedCar(2013,"Chevy", "Astro",80000, 17950.00);
      list[2] = new UsedCar(2017,"Toyota", "Rav4",50000, 22950.00);
      list[3] = new UsedCar(2014,"Toyota", "Supra",110000, 16950.00);

      Scanner sc = new Scanner(System.in);
      int found = 0;
      System.out.print("Enter Make:");
      String make = sc.next();
      System.out.print("Enter list price: $");
      double price = sc.nextDouble();
      System.out.print("Enter Mileage: ");
      int mileage = sc.nextInt();
      for (int i = 0; i<4; i++){
        
         if (list[i].getMake().equals(make) && list[i].getListPrice() <= price && list[i].getMileage() <= mileage){
            found = 1;
            System.out.println(list[i].getYear() + " " + list[i].getMake() + " " + list[i].getModel() + " is available with " + list[i].getMileage() + " for " + list[i].getListPrice());
         }
      }
      if (found == 0){
         System.out.println("No cars matching that description is avaialable ");
      }
    
    
     }
}

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