Please let me know if you have any doubts or you want me to modify the answer. And if you find this answer useful then don't forget to rate my answer as thumps up. Thank you! :)
import java.util.List;
import java.util.Scanner;
public class DealershipProgram {
public static void main(String[] args)
{
Scanner scannerInput =
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 = scannerInput.next();
employee = CarDealershipSystem.checkAssociate(id);
} while (employee == null);
do {
System.out.print("Please enter your associate pass: ");
String pass = scannerInput.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 = scannerInput.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("\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<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);
scannerInput.close();
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class Car {
private String make;
private String model;
private int year;
private String color;
private String vin;
private double price;
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;
}
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;
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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;
}
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;
}
public static ArrayList<Car>
carCollection() {
String file =
"/Users/swapnil/IdeaProjects/CarDealershipProgram/src/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;
}
public static ArrayList<SalesAssociate>
employeeCollection() {
String file =
"/Users/swapnil/IdeaProjects/CarDealershipProgram/src/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();
} catch
(FileNotFoundException e) {
System.out.println("Error opening file!");
System.exit(0);
}
return people;
}
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);
}
public static void
addNewTransactions(Transaction transaction) {
Calendar c =
Calendar.getInstance();
try {
File file = new
File("/Users/swapnil/IdeaProjects/CarDealershipProgram/src/employees.txttransactions.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) {
}
}
public void addCars(Car car) {
cars.add(car);
try {
String file =
"/Users/swapnil/IdeaProjects/CarDealershipProgram/src/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) {
}
}
public static void
addSAssociates(SalesAssociate employee) {
people.add(employee);
try {
String file =
"/Users/swapnil/IdeaProjects/CarDealershipProgram/src/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("/Users/swapnil/IdeaProjects/CarDealershipProgram/src/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("/Users/swapnil/IdeaProjects/CarDealershipProgram/src/employees.txtcars.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 Customer {
private String name;
private String address;
private String customerID;
private int accountNumber;
private String phoneNumber;
public Customer(String n, String ad, String
id, int ac, String pn) {
name = n;
address = ad;
customerID = id;
accountNumber =
ac;
phoneNumber = pn;
}
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;
public SalesAssociate(String n, String ad,
double sales, String id,
String pword) {
name = n;
address = ad;
totalSales =
sales;
salesAssociateID =
id;
password = pword;
}
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;
public Transaction(Customer customer,
Car car, SalesAssociate employee, String time) {
this.customer =
customer;
this.car = car;
this.employee =
employee;
this.time = time;
}
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;
}
}
For Java Program In this lab you will gain experience using all the concepts we learned...
Write a Java program to read customer details from an input text file corresponding to problem under PA07/Q1, Movie Ticketing System The input text file i.e. customers.txt has customer details in the following format: A sample data line is provided below. “John Doe”, 1234, “Movie 1”, 12.99, 1.99, 2.15, 13.99 Customer Name Member ID Movie Name Ticket Cost Total Discount Sales Tax Net Movie Ticket Cost Note: if a customer is non-member, then the corresponding memberID field is empty in...
The goal of this assignment is to give you some experience building a program that uses objects. You must work in teams of 2 to complete this assignment. You will use the BankAccount class you created in Lab 3 to create a banking program. The program must display a menu to the user to allow the user to select a transaction like deposit, withdraw, transfer, create a bank account, and quit the program. The program should allow a user to...
JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...
*** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J IN CLASS (IF IT DOESNT MATTER PLEASE COMMENT TELLING WHICH PROGRAM YOU USED TO WRITE THE CODE, PREFERRED IS BLUE J!!)*** ArrayList of Objects and Input File Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info...
Java Create a program for a car dealer to use where you have a class for Salesman, Cars, and the Records of sale. 4 salesman and 4 cars to start with but have array size for 50 cars, have space for 100 records in array. The program should have 6 options in the menu. buy car, sell car, show inventory, show salesman, show sales records, and exit. Salesman class - Name, ID number, Commision rate, Total commisions earned, Totals number...
Program Description: A Java program is to be created to produce Morse code. The Morse code assigns a series of dots and dashes to each letter of the alphabet, each digit, and a few special characters (such as period, comma, colon, and semicolon). In sound-oriented systems, the dot represents a short sound and the dash represents a long sound. Separation between words is indicated by a space, or, quite simply, the absence of a dot or dash. In a sound-oriented...
Java program
Program: Grade Stats In this program you will create a utility to calculate and display various statistics about the grades of a class. In particular, you will read a CSV file (comma separated value) that stores the grades for a class, and then print out various statistics, either for the whole class, individual assignments, or individual students Things you will learn Robustly parsing simple text files Defining your own objects and using them in a program Handling multiple...
use JOptionPane to display output Can someone please help write a program in Java using loops, not HashMap Test 1 Grades After the class complete the first exam, I saved all of the grades in a text file called test1.txt. Your job is to do some analysis on the grades for me. Input: There will not be any input for this program. This is called a batch program because there will be no user interaction other than to run the program....
What to submit: your answers to exercises 2. Write a Java program to perform the following tasks: The program should ask the user for the name of an input file and the name of an output file. It should then open the input file as a text file (if the input file does not exist it should throw an exception) and read the contents line by line. It should also open the output file as a text file and write...
In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the document to be spellchecked. The program will read in the words for the dictionary, then will read the document and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is or type in a replacement word and add...