Question
JAVA Programing, i have all the classes but the 6th, cardealership program and i'm having issues with it lol heres the 5 other classess, can
JAVA Programing, i have all the classes but the 6th, cardealership program and i'm having issues with it lol heres the 5 other classess, can someone help?
Also heres the rrequriments:
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 customers 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.
----------------------------
Dealership Program
import java.util.List; import java.util.Scanner; public class DealershipProgram { public static void main(String[] args) { Scanner kbdScanner = new Scanner(System.in); Scanner input = new Scanner(System.in); SalesAssociates employee = null; boolean continueLoop = true; do { if (employee == null) { do { System.out.print("Please enter your associate id: "); String id = kbdScanner.next(); employee = CarDealershipSystem.checkAssociate(id); } while (employee == null); do { System.out.print("Please enter your associate pass: "); String pass = kbdScanner.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 = kbdScanner.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 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("\tVin: " + 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 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 (SalesAssociates 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); kbdScanner.close(); } }
----------------------------
Transaction
public class Transaction { private String date; private String time; private double cost; private Customer customer; private Car car; private SalesAssociates employee; // Constructor public Transaction(Customer customer, Car car, SalesAssociates 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 SalesAssociates getEmployee() { return employee; } public void setSalesAssociate(SalesAssociates employee) { this.employee = employee; } }
----------------------------
Car
public class Car {
private int vin, year, miles;
private String make, model, color;
private double price;
public Car(){
vin = 0000000;
year = 1969;
miles = 0;
price = 0;
make = null;
model = null;
color = null;
}
public Car(int inYear, int inMiles, int inVin,double inPrice, String inMake, String inModel,String inColor){
vin = inVin;
year = inYear;
miles = inMiles;
price = inPrice;
make = inMake;
model = inModel;
color = inColor;
}
public int getVin() {
return vin;
}
public void setVin(int vin) {
this.vin = vin;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getMiles() {
return miles;
}
public void setMiles(int miles) {
this.miles = miles;
}
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 String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
//This constructor is designed to take a line of text,
//in this case from the source text file, and create a
//car class from it. A '+' character is used to separate
//each piece of information in the text file, and knowing this,
//as well as the predetirmined order in which the information is
//written into the file, we can extract the information simply by finding these
//pluses and using the substring method to extract the info between them.
public Car(String inCarInfo){
int current=0;
int next = findNextPlus(current, inCarInfo);
vin = Integer.parseInt(inCarInfo.substring(current, next));
current = next+1;
next = findNextPlus(current,inCarInfo);
year = Integer.parseInt(inCarInfo.substring(current, next));
current = next+1;
next = findNextPlus(current,inCarInfo);
miles = Integer.parseInt(inCarInfo.substring(current, next));
current = next+1;
next = findNextPlus(current,inCarInfo);
make = inCarInfo.substring(current, next);
current = next+1;
next = findNextPlus(current,inCarInfo);
model = inCarInfo.substring(current, next);
current = next+1;
next = findNextPlus(current,inCarInfo);
color = inCarInfo.substring(current);
//The findNextPlus method isnt used here, because there are
//no more pluses in the text, as this is the last piece of information
current = next+1;
price = Double.parseDouble(inCarInfo.substring(current));
}
public String toString(){
return vin+"+"+year+"+"+miles+"+"+make+"+"+model+"+"+color+"+"+price;
}
private int findNextPlus(int x, String input){
return input.indexOf('+',x);
}
}
----------------------------
Customer
public class Customer {
private String name;
private int age;
private int money; //This field is an integer to save on space, as pocket change is irrelevant to
//the cost of a car
public Customer (String inName, int inAge, int inMoney){
name = inName;
age = inAge;
money = inMoney;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getMoney() {
return money;
}
public void setMoney(int money) {
this.money = money;
}
}
----------------------------
SalesAsscioates
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.Scanner;
import java.io.IOException;
public class SalesAssociates {
private int id, totalNumSales;
private double totalNetProfit, totalProfit;
private String username, address, password;
//File cars = new File("Cars.txt");
//PrintWriter out = new PrintWriter(new FileWriter("Cars.txt",true));
public SalesAssociates(int inId, String inUsername, String inAddress, String inPassword){
id = inId;
username = inUsername;
address = inAddress;
password = inPassword;
totalNetProfit = 0;
totalProfit = 0;
totalNumSales = 0;
}
//GETTERS AND SETTERS START
public int getId(){
return id;
}
public String getUsername(){
return username;
}
public String getAddress(){
return address;
}
public String getPassword(){
return password;
}
public double getTotalNetProfit(){
return totalNetProfit;
}
public double getTotalProfit(){
return totalProfit;
}
public int getNumSames(){
return totalNumSales;
}
public void setId(int in){
id = in;
}
public void setUsername(String in){
username = in;
}
public void setPassword(String in){
password = in;
}
public void setAddress(String in){
address = in;
}
public void setTotalNetProfit(double in){
totalNetProfit = in;
}
public void setTotalProfit(double in){
totalProfit =in;
}
public void setNumSales(int in){
totalNumSales = in;
}
//END GETTERS AND SETTERS
public boolean creditCheck(Customer buyer, Car car){
if(buyer.getMoney()>=car.getPrice()){
return true;
}
else{
return false;
}
}
//Adds a car to the inventory
public void addCar(Car inCar){
try {
PrintWriter out = new PrintWriter(new FileWriter("Cars.txt", true));
out.println(inCar.toString());
out.close();
//System.out.println("Done! "+inCar);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started