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

Create an Object Oriented application used to manage and search for cars. Your t

ID: 3661571 • Letter: C

Question

Create an Object Oriented application used to manage and search for cars.

Your task is to create an Object Oriented application used to maintain a catalog of used cars. The catalog keeps track of each car's make, model, year, and sale price. The user is prompted to enter one of these possible commands:

Add - add a single car to the catalog
Import - allows you to import a file of cars into the catalog (CSV file)
List - list all cars in the catalog
Search by make, model, year or price
Quit - quit the application

If an unknown command is entered, the user should be informed and asked to enter another command. The user is prompted for another command after completing the current task. The application continues until the quit command is entered.

The add command -

If the add command is entered, the user will then be prompted to enter the car's make, model, year, and sales price. The make and model can be arbitrary strings, while the year (e.g. 2000) should be an integer and the sales price (e.g. 2599.99) should be a floating point value. After the data is entered, the record should be stored so it can be recalled later by the list command.

OO REQUIREMENTS:

Must be Object Oriented with at least 1 logic and 1 client class.

Explanation / Answer

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

class Car{
   String make;
   String model;
   int year;
   double price;
   public Car(String make,String model,int year,double price){
       this.make = make;
       this.model = model;
       this.year = year;
       this.price = price;
   }
}

class main{
   public static ArrayList<Car> all_cars = new ArrayList<Car>();
   public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
       int n;
       while (true){
           System.out.println("1. ADD A CAR");
           System.out.println("2. IMPORT CARS");
           System.out.println("3. LIST ALL CARS");
           System.out.println("4. SEARCH BY MAKE, MODEL, YEAR or PRICE");
           System.out.println("5. QUIT");
           int n = sc.nextInt();
           if (n == 1){
               System.out.println("Enter the make of the car ");
               String make = sc.nextLine();

               System.out.println("Enter the model of the car ");
               String model = sc.nextLine();              
              
               System.out.println("Enter the year of the car ");
               int year = sc.nextInt();

               System.out.println("Enter the price of the car ");
               double price = sc.nextDouble();

               Car car = new Car(make,model,year,price);
               all_cars.add(car);
           }
           else if (n == 2){
               ReadCVS obj = new ReadCVS();
               obj.run();
           }
           else if (n == 3){
               for (int i = 0; i < all_cars.size(); i++){
                   System.our.println("MAKE : "+all_cars.get(i).make);
                   System.our.println("MODEL : "+all_cars.get(i).model);
                   System.our.println("YEAR : "+all_cars.get(i).year);
                   System.our.println("PRICE : "+all_cars.get(i).price);
               }
           }
           else if (n == 4){
               System.out.println("1. SEARCH BY MAKE");
               System.out.println("2. SEARCH BY MODEL");
               System.out.println("3. SEARCH BY YEAR");
               System.out.println("4. SEARCH BY PRICE");
               int ch = sc.nextInt();
               if (ch == 1){
                   System.out.println("Enter the make of the car : ");
                   String make = sc.nextLine();
                   for (int i = 0; i < all_car.size(); i++){
                       if (all_cars.get(i).make == make){
                           System.our.println("MAKE : "+all_cars.get(i).make);
                           System.our.println("MODEL : "+all_cars.get(i).model);
                           System.our.println("YEAR : "+all_cars.get(i).year);
                           System.our.println("PRICE : "+all_cars.get(i).price);
                       }
                   }
               }
               else if (ch == 2){
                   System.out.println("Enter the model of the car ");
                   String model = sc.nextLine();              
                   for (int i = 0; i < all_car.size(); i++){
                       if (all_cars.get(i).model == model){
                           System.our.println("MAKE : "+all_cars.get(i).make);
                           System.our.println("MODEL : "+all_cars.get(i).model);
                           System.our.println("YEAR : "+all_cars.get(i).year);
                           System.our.println("PRICE : "+all_cars.get(i).price);
                       }
                   }
               }
               else if (ch == 3){
                   System.out.println("Enter the year of the car ");
                   int year = sc.nextInt();
                   for (int i = 0; i < all_car.size(); i++){
                       if (all_cars.get(i).year == year){
                           System.our.println("MAKE : "+all_cars.get(i).make);
                           System.our.println("MODEL : "+all_cars.get(i).model);
                           System.our.println("YEAR : "+all_cars.get(i).year);
                           System.our.println("PRICE : "+all_cars.get(i).price);
                       }
                   }
               }
               else{
                   System.out.println("Enter the price of the car ");
                   double price = sc.nextInt();
                   for (int i = 0; i < all_car.size(); i++){
                       if (all_cars.get(i).price == price){
                           System.our.println("MAKE : "+all_cars.get(i).make);
                           System.our.println("MODEL : "+all_cars.get(i).model);
                           System.our.println("YEAR : "+all_cars.get(i).year);
                           System.our.println("PRICE : "+all_cars.get(i).price);
                       }
                   }
               }
           }
           else
               break;
       }  
   }
   public void run(){
       String csvFile = "cars.csv";
       BufferedReader br = null;
       String line = "";
       String cvsSplitBy = ",";
       try{
           br = new BufferedReader(new FileReader(csvFile));
           while ((line = br.readLine()) != null) {
               String[] car_data = line.split(cvsSplitBy);
               String make = car_data[0];
               String model = car_data[1];
               int year = Integer.parseInt(car_data[2]);
               double price = Double.parsedouble(car_data[3]);

               Car car = new Car(make,model,year,price);
               all_cars.add(car);
           }
       }
       catch (FileNotFoundException e) {
           e.printStackTrace();
       }
   }
}

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