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

You need to create a JAVA program to manage a car dealership. The program should

ID: 3713054 • Letter: Y

Question

You need to create a JAVA program to manage a car dealership. The program should maintain a list of cars that are currently in their inventory, a list of sales associates, a list of transactions (information related to the sale of a car), and allow the user to find and buy a car. The cars and information regarding each car should be stored in a text file. The sales associates and information regarding each sales associate should be stored in a separate text file. Your program needs to use these text files to load the inventory of cars and sales associate along their information into the lists maintained by the system. It should also update these text files when the program exits. The user of the program will be a sales associate who can search for cars, and record the purchase of a car they sold. Requirements: • The program must allow the user to login to the program using a username and password before using the program. o The users of the program will be the sales associates. • The program must provide a menu that allows the sales associate to perform all the required operations for the system. • It must allow the sales associate to add cars to the system. • The program should allow the sales associate to modify existing cars and delete cars from the system. • The program must allow the sales associate to record the sale of a car (transaction). o This transaction should allow the sales associate to enter the customer’s information, find and select a car, and record the sale of the car. • The program needs to allow the user the ability to find a car by make and model. o The CarDealershipSystem should use the list of cars it manages to find all the currently available cars. • The program needs to record a sales transaction by storing it in a text file that contains all previous sale transactions (you should use append mode to add new information to an existing file). • The application should display all the cars sold by the sales associate. o This should be one of the main menu options presented to the user after login. • The application should display the sales associates with their total sales. o This should be one of the main menu options presented to the user after login. • The program code inside the DealershipProgram class should use one instance of the CarDealershipSystem class to manage all operations. The three classes (Sales associate, Transaction, Car, CarDealershipSystem) shouldn’t rely on elements of the user interface for input or output. This means only the DealershipProgram class will handle input/output using the user interface. The other classes should not perform any operations involving user input or displaying output to the screen. • The program should be able to store cars in a text file, so they can be used the next time the program runs. o The text file that contains the cars should use one line per car. This means the car’s information (vin#, make, model, year, color, etc…) should be written to one line in the text file. So, if there were 20 cars, the text file would have 20 lines of text where each line contains all the information about a particular car. • The program should write the sale transaction (information related to it) to a text file. o This should be a method in the CarDealershipSystem class. o The text file that contains the sale transactions should use one line per transaction. This means the transaction’s information (date, time, sales associate, customer, car, etc…) should be written to one line in the text file. So, if there were 10 transactions, the text file would have 10 lines of text. o The transactions should be added using the append mode, so previous transactions aren’t overwritten. • There program requires input validation for all operations that require user input. • The user interface design is completely your choice, but make sure you provide clear instructions to help the user complete each task. • This application requires creating 5 classes: o DealershipProgram class represents the program and user interface. This is the only class that should contain code that gets user input and delivers output to the screen. o Customer class that will contain information related to a customer who will be purchasing a car from the system, and necessary fields/methods for working with that data. This class should also contain a field like CustomerID that uniquely identifies a customer. o SalesAssociate class that will contain information related to a salesperson (name, address, total sales, etc…) who will be logging into the system, searching for a car, and recording the purchase of a car in the system, and necessary fields/methods for working with that data. This class should also contain a field like SalesAssociateID that uniquely identifies a customer. o Car class that will contain information related to a car, and necessary methods/properties for working with that data. This class should store a car’s make, model, vin#, year, color, etc. This class should also contain a field like VIN that uniquely identifies a car. o Transaction class that will contain information related to an actual transaction where a sales associate sold a car to a customer. This class should store the date, time, customer info, car info, and any other important information related to the sale of a single car. o CarDealershipSystem class that will manage a collection of cars, a collection of sales associates, searching for a car, and process the sales transaction. ? This class needs a method that takes strings for a make and model as input, searches through a collection of car objects to find all cars that meet this criteria, and return a collection of cars that fit the criteria passed to the method. ? This class needs a method that reads a text file (cars.txt), creates a Car object for each car stored in the file, and stores the newly created Car object in a collection of cars. This method is used to load cars into a list of cars for the CarDealershipSystem to manage. This should be done in the class’ constructor. ? This class needs a method that reads a text file (employee.txt), creates a SalesAssociate object for each sales person stored in the file, and stores the newly created SalesAssociate object in a collection of sales associates. This method is used to load sale associates into a list of sales associates for the CarDealershipSystem to manage. This should be done in the class’ constructor. ? This class needs a method that takes a Car, SalesAssociate, and a Customer object as input, creates a Transaction object that stores the information about the transaction, and stores the Transaction object in the collection of transactions that were performed since the program started. A transaction should store the customer’s information, the car that was purchased, the sales associate who sold the car, and the date and time of this transaction. It should also update the specific sales associates total sales since they just sold another car. ? This class needs a method that adds the new transactions stored in the CarDealershipSystem transactions collection to the text file with all the other transactions (transactions.txt). ? This class needs a method that writes the cars stored in the cars collection to the cars text file (cars.txt). You should overwrite the original car text file since the system contains the latest information for all the cars in the system. ? This class needs a method that writes the sales associates stored in the sales associate collection to the employee text file (employees.txt). You should overwrite the original employee text file since the system contains the latest information for all the employees in the system.

Explanation / Answer


import java.util.List;
import java.util.Scanner;

public class DealershipProgram {

    public static void main(String[] args) {
        Scanner scannerin = new Scanner(System.in);
        Scanner input = new Scanner(System.in);
        SalesAssociate employee = null;

        boolean continueLoop = true;
        do {

            if (employee == null) {
                do {
                    System.out.print("Please enter your associate id: ");
                    String id = scannerin.next();
                    employee = CarDealershipSystem.checkAssociate(id);
                } while (employee == null);

                do {
                    System.out.print("Please enter your associate pass: ");
                    String pass = scannerin.nextLine();

                    if (employee.getPassword().equals(pass))
                        break;
                } while (true);
            }

            System.out.println("Please enter a number to complete one of the following action(1-7): ");
            System.out.println("1) Search inventory");
            System.out.println("2) Remove cars from inventory");
            System.out.println("3) Add cars to inventory");
            System.out.println("4) Record transaction");
            System.out.println("5) View sold cars");
            System.out.println("6) View total sales");
            System.out.println("7) Exit");

            int option = scannerin.nextInt();
            switch (option) {
                case 1:
                    System.out.println("Please enter the make: ");
                    String CarModel = input.nextLine().trim();
                    System.out.println("Enter the model: ");
                    String CarMake = input.nextLine();

                    List<Car> matched = CarDealershipSystem.FindCars(CarMake,
                            CarModel);

                    if (matched.isEmpty()) {
                        System.out
                                .println("No cars with that precedent were found.");
                    } else {
                        System.out.println("List of matched cars: ");
                    }
                    for (Car car : matched) {
                        System.out.println(" Vin: " + car.getVin() + ", Model: "
                                + car.getModel() + ", Color: " + car.getColor()
                                + ", Make: " + car.getMake() + ", Year: "
                                + car.getYear() + ", Price: " + car.getPrice());
                    }
                    break;

                case 2:

                    Car car = null;
                    do {
                        System.out
                                .print("Enter the VIN Number of the car you are removing: ");
                        String vin = input.nextLine();
                        car = CarDealershipSystem.getCar(vin);
                        if (car == null)
                            System.out.println("Car cannot be found: ");
                    } while (car == null);

                    CarDealershipSystem.removeCar(car);
                    break;

                case 3:
                    System.out.print("Enter a car VIN Number: ");
                    String Vin = input.nextLine();
                    System.out.print("Enter the car model: ");
                    String Model = input.nextLine();
                    System.out.print("Enter the car color: ");
                    String color = input.nextLine();
                    System.out.print("Enter the car make: ");
                    String Make = input.nextLine();
                    System.out.print("Enter the car's year: ");
                    int year = input.nextInt();
                    System.out.print("Enter the cars' price: ");
                    double price = input.nextDouble();

                    Car newCar = new Car(Make, Model, year, color, Vin, price);
                    Car anotherCar = new Car (Make, Model, year, color, Vin, price);
                    CarDealershipSystem.setCar(newCar, anotherCar);
                    break;

                case 4:
                    System.out.println("Enter a VIN Number for the car being sold: ");
                    String vin = input.nextLine();
                    car = CarDealershipSystem.getCar(vin);

                    System.out.print("Please enter the customer's name: ");
                    String name = input.nextLine();

                    System.out.print("Please enter the customer's address: ");
                    String address = input.nextLine();
                    System.out.print("Please enter the customer's account number: ");
                    int acn = input.nextInt();
                    System.out.print("Please enter the customer's phone number: ");
                    String phoneNumber = input.nextLine();

                    String id = null;
                    Customer customer = new Customer(name, address, id, acn,phoneNumber);

                    CarDealershipSystem.transactionCollection(car, employee,
                            customer);
                    break;

                case 5:
                    List<Car> soldCars = CarDealershipSystem.getSoldCars();

                    System.out.println("Cars Sold: ");

                    for (Car c : soldCars) {
                        System.out.println("Vin: " + c.getVin() + ", Model: "
                                + c.getModel() + ", Color: " + c.getColor()
                                + ", Make: " + c.getMake() + ", Year: "
                                + c.getYear() + ", Price: " + c.getPrice());
                    }
                    break;

                case 6:
                    int total = 0;
                    for (SalesAssociate s : CarDealershipSystem.people) {
                        System.out.println(s.getName() + ", " + s.gettotalSales());
                        total += s.gettotalSales();
                    }


                    System.out.println("Total cars sold:" + total);
                    break;

                case 7:
                    System.out.println("Thank you for shopping!");
                    continueLoop = false;
                    System.exit(0);
                default:
                    continueLoop = false;
            }

        } while (continueLoop);

        scannerin.close();
    }
}
-----------------------------------------------------------------------------
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Scanner;

public class CarDealershipSystem {

    public static ArrayList<Car> cars = new ArrayList<Car>();
    public static ArrayList<SalesAssociate> people = new ArrayList<SalesAssociate>();
    public static ArrayList<Transaction> trades = new ArrayList<Transaction>();

    public static SalesAssociate getAssociate(String id) {
        for (SalesAssociate s : people) {
            if (s.getId().equals(id))
                return s;
        }
        return null;
    }

    // 1st bullet point
    public static ArrayList<Car> FindCars(String make, String model) {

        ArrayList<Car> foundCar = new ArrayList<Car>();
        foundCar.clear();
        for (Car car : carCollection()) {
            if (car.getModel().equals(model) && car.getMake().equals(make))
                foundCar.add(car);
        }
        return foundCar;
    }

    // 2nd bullet point
    public static ArrayList<Car> carCollection() {
        String file = "cars.txt";
        Scanner reader = null;

        try {
            reader = new Scanner(new FileReader(file));

            while (reader.hasNext()) {
                String nextLine = reader.nextLine();
                String[] parse = nextLine.split(",");

                String vin = parse[0];
                String make = parse[1];
                String model = parse[2];
                String color = parse[3];
                int year = Integer.parseInt(parse[4]);
                double price = Double.parseDouble(parse[5]);

                cars.add(new Car(make, model, year, color, vin, price));
            }

            reader.close(); // closes the stream
        } catch (FileNotFoundException e) {
            System.out.println("Error opening file!");
            System.exit(0);
        }
        return cars;
    }

    // 3rd bullet point
    public static ArrayList<SalesAssociate> employeeCollection() {
        String file = "employees.txt";
        Scanner reader = null;

        try {
            reader = new Scanner(new FileReader(file));
            while (reader.hasNext()) {
                String nextLine = reader.nextLine();
                String[] split = nextLine.split(",");

                String name = split[0];
                String address = split[1];
                double sales = Double.parseDouble(split[2]);
                String id = split[3];
                String pass = split[4];

                people.add(new SalesAssociate(name, address, sales, id, pass));
            }
            reader.close(); // closes the stream
        } catch (FileNotFoundException e) {
            System.out.println("Error opening file!");
            System.exit(0);
        }
        return people;
    }

    // 4th bullet point
    public static void transactionCollection(Car car, SalesAssociate employee,
                                             Customer person) {
        String date = "", time = "";
        SimpleDateFormat mdyDate = new SimpleDateFormat("MM-dd-yyyy");
        SimpleDateFormat hmTime = new SimpleDateFormat("hh:mm a");
        Calendar c = Calendar.getInstance();
        time = hmTime.format(c.getTime());
        date = mdyDate.format(c.getTime());
        Transaction transaction = new Transaction(person, car, employee, date + time);
        trades.add(transaction);
    }

    // 5th bullet point
    public static void addNewTransactions(Transaction transaction) {
        Calendar c = Calendar.getInstance();

        try {
            File file = new File("./transactions.txt");

            if (!file.exists())
                file.createNewFile();

            PrintWriter fileWriter = new PrintWriter(new FileOutputStream(file,
                    true));

            String output = transaction.getDate() + ","
                    + c.getTime().toString() + "," + transaction.getCustomer()
                    + "," + transaction.getCar() + ","
                    + transaction.getEmployee();

            fileWriter.write(output);

            fileWriter.flush();
            fileWriter.close();

        } catch (IOException e) {
        }
    }

    // 6th bullet point
    public void addCars(Car car) {

        cars.add(car);

        try {
            String file = "./cars.txt";

            PrintWriter fileWriter = new PrintWriter(new FileOutputStream(file,
                    true));

            for (Car c : cars) {
                String output = c.getMake() + "," + c.getModel() + ","
                        + c.getYear() + "," + "," + c.getColor()
                        + "," + c.getVin();

                fileWriter.write(output);
                fileWriter.flush();
            }

            fileWriter.close();

        } catch (IOException e) {
        }
    }

    // 7th bullet point
    public static void addSAssociates(SalesAssociate employee) {
        people.add(employee);
        try {
            String file = "./employees.txt";

            PrintWriter fileWriter = new PrintWriter(new FileOutputStream(file,
                    true));

            for (SalesAssociate workers : people){

                String output = workers.getName() + "," + workers.getAddress()
                        + "," + workers.gettotalSales() + "," + workers.getId()
                        + "," + workers.getPassword();

                fileWriter.write(output);
                fileWriter.flush();
            }
            fileWriter.close();

        } catch (IOException e) {
        }
    }

    public static Car getCar(String vin) {
        for (Car car : carCollection()) {
            if (car.getVin().equals(vin))
                return car;
        }
        return null;
    }

    public static void removeCar(Car vehicle) {
        cars.remove(vehicle);

        try {
            PrintWriter words = new PrintWriter("./cars.txt");
            for (Car car : cars)
                words.println(car.getVin() + "," + car.getMake() + "," + car.getModel() +
                        "," + car.getColor() + "," + car.getYear() + "," + car.getPrice());
            words.close();

        } catch (FileNotFoundException e) {
        }
    }

    public static Transaction getTrade(Car car) {
        for (Transaction trade : trades) {
            if (trade.getCar() == car)
                return trade;
        }
        return null;
    }

    public static List<Car> getSoldCars() {
        ArrayList<Car> soldCars = new ArrayList<Car>();
        for (Car car : cars) {
            Transaction transaction = getTrade(car);
            if (transaction == null)
                continue;
            soldCars.add(car);
        }
        return soldCars;
    }

    public static void setCar(Car oldCar, Car newCar) {
        if (oldCar != null && cars.contains(oldCar))
            cars.set(cars.indexOf(oldCar), newCar);
        else
            cars.add(newCar);

        try {
            PrintWriter pWriter = new PrintWriter("./cars.txt");
            for (Car automobile : cars)
                pWriter.println(automobile.getVin() + "," + automobile.getMake() + "," + automobile.getModel() +
                        "," + automobile.getColor() + "," + automobile.getYear() + "," + automobile.getPrice());
            pWriter.close();
        } catch (FileNotFoundException e) {
        }
    }

    public static SalesAssociate checkAssociate(String id) {
        for (SalesAssociate workers : employeeCollection()) {
            if (workers.getId().equalsIgnoreCase(id))
                return workers;
        }
        return null;
    }
}
--------------------------------------------------------------------------------
public class Car {
    // private class variables
    private String make;
    private String model;
    private int year;
    private String color;
    private String vin;
    private double price;

    // Constructor
    public Car(String m, String mo, int y, String co, String v, double p) {
        make = m;
        model = mo;
        year = y;
        color = co;
        vin = v;
        price = p;
    }

    // Getters and Setters below
    public String getMake() {
        return make;
    }

    public void setMake(String make) {
        this.make = make;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String getVin() {
        return vin;
    }

    public void setVin(String vin) {
        this.vin = vin;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}
---------------------------------------------------------------------------------
public class Customer {
    private String name;
    private String address;
    private String customerID;
    private int accountNumber;
    private String phoneNumber;

    // Constructor
    public Customer(String n, String ad, String id, int ac, String pn) {
        name = n;
        address = ad;
        customerID = id;
        accountNumber = ac;
        phoneNumber = pn;
    }

    // Getters and Setters below
    public String getName() {
        return name;
    }

    public String setname(String name) {
        this.name = name;
        return this.name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getId() {
        return customerID;
    }

    public void setcustomerID(String id) {
        customerID = id;
    }

    public double getAccountNumber() {
        return accountNumber;
    }

    public void setAccountNumber(int ac) {
        accountNumber = ac;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String number) {
        phoneNumber = number;
    }

}
-------------------------------------------------------------------------
public class SalesAssociate {
    private String name;
    private String address;
    private double totalSales;
    private String salesAssociateID;
    private String password;

    // Constructor
    public SalesAssociate(String n, String ad, double sales, String id,
                          String pword) {
        name = n;
        address = ad;
        totalSales = sales;
        salesAssociateID = id;
        password = pword;
    }

    // Getters and Setters below
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public double gettotalSales() {
        return totalSales;
    }

    public void setTotalSales(double sales) {
        totalSales += sales;
    }

    public String getId() {
        return salesAssociateID;
    }

    public void setSalesAssociateID(String id) {
        salesAssociateID = id;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String pword) {
        password = pword;
    }
}


-------------------------------------------------------------------
public class Transaction {
    private String date;
    private String time;
    private double cost;
    private Customer customer;
    private Car car;
    private SalesAssociate employee;

    // Constructor
    public Transaction(Customer customer,
                       Car car, SalesAssociate employee, String time) {
        this.customer = customer;
        this.car = car;
        this.employee = employee;
        this.time = time;
    }

    // Getters and Setters below
    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public double getCost() {
        return cost;
    }

    public void setCost(double cost) {
        this.cost = cost;
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public Car getCar() {
        return car;
    }

    public void setCar(Car car) {
        this.car = car;
    }

    public SalesAssociate getEmployee() {
        return employee;
    }

    public void setSalesAssociate(SalesAssociate employee) {
        this.employee = employee;
    }

}

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