Question

Java Create a program for a car dealer to use where you have a class for...

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 of sales

Car class - Year, make, model, vin, color, buying price, and selling price

Record class - Car, Salesman, dealer profit, and date

This program is meant to be a way for a car dealer to track their sales

MENU DETAILS

Buy Car:
Should obtain all information from the user on a car that was purchased by the dealer and store it in a record. Create a new object for the Car that was purchased . Create a new Record. Update the Car and Record arrays accordingly.

Sell Car:
The user should only be able to sell a car that is in the inventory. You may want to show a numbered list of cars in the inventory and let the user choose from the list. Let the user choose a salesman in the same way. Update the Salesmen object that sold the car and update the record array for the sale.

Show Inventory:
Use a for loop and a display() method to show all of the cars and their data. Display the total number of cars and their net worth at the end of the report.

Show Salesmen
Show all stats for each salesman at the dealership. At the end of the report rank the salesmen in order based on highest commissions.

Show Sales Records
Show all records for cars that have been bought and sold. Show the total number of cars purchased, total number of cars sold and total net profit of the dealer.

Exit
Offers a confirmation message and then kills the program if the user agrees.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

package vehicle;

public class Salesmen implements Comparable<Salesmen>{

//private members
private String name;
private int id;
private double commissionRate;
private double totalCommission;
private int totalSales;
//Default Constructor
public Salesmen() {
}
//Argument constructor
public Salesmen(String name, int id, double commissionRate, double totalCommission, int totalSales) {
super();
this.name = name;
this.id = id;
this.commissionRate = commissionRate;
this.totalCommission = totalCommission;
this.totalSales = totalSales;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getCommissionRate() {
return commissionRate;
}
public void setCommissionRate(double commissionRate) {
this.commissionRate = commissionRate;
}
public double getTotalCommission() {
return totalCommission;
}
public void setTotalCommission(double totalCommission) {
this.totalCommission = totalCommission;
}
public int getTotalSales() {
return totalSales;
}
public void setTotalSales(int totalSales) {
this.totalSales = totalSales;
}

public void display() {
System.out.println( "Salesmen \n name=" + name + ", id=" + id + ", commissionRate=" + commissionRate + ", totalCommission="
+ totalCommission + ", totalSales=" + totalSales);
}
@Override
public int compareTo(Salesmen o) {
  
return (int) (o.getTotalCommission()-this.getTotalCommission());
}
  
}

package vehicle;

public class Car {

private int year;
private String model;
private String vin;
private String color;
private double buyingPrice;
private double sellingPrice;
//Default Constructor
public Car() {
  
}
//Argument constructor
public Car(int year, String model, String vin, String color, double buyingPrice, double sellingPrice) {
super();
this.year = year;
this.model = model;
this.vin = vin;
this.color = color;
this.buyingPrice = buyingPrice;
this.sellingPrice = sellingPrice;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getVin() {
return vin;
}
public void setVin(String vin) {
this.vin = vin;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
  
public double getBuyingPrice() {
return buyingPrice;
}
public void setBuyingPrice(double buyingPrice) {
this.buyingPrice = buyingPrice;
}
public double getSellingPrice() {
return sellingPrice;
}
public void setSellingPrice(double sellingPrice) {
this.sellingPrice = sellingPrice;
}
public void display() {
System.out.println( "Car \n year=" + year + ", model=" + model + ", vin=" + vin + ", color=" + color + ", buyingPrice="
+ buyingPrice + ", sellingPrice=" + sellingPrice+"\n");
}
  
}

package vehicle;

import java.util.Date;

public class Record {

private Car car;
private Salesmen salesman;
private String dealer; //A new Class can be created for dealer
private double profit;
private Date date;
public Record() {
  
}
public Record(Car car, Salesmen salesman, String dealer, double profit, Date date) {
  
this.car = car;
this.salesman = salesman;
this.dealer = dealer;
this.profit = profit;
this.date = date;
}
public Car getCar() {
return car;
}
public void setCar(Car car) {
this.car = car;
}
public Salesmen getSalesman() {
return salesman;
}
public void setSalesman(Salesmen salesman) {
this.salesman = salesman;
}
public String getDealer() {
return dealer;
}
public void setDealer(String dealer) {
this.dealer = dealer;
}
public double getProfit() {
return profit;
}
public void setProfit(double profit) {
this.profit = profit;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
  
public void display() {
car.display();
salesman.display();
  
System.out.println("dealer=" + dealer + ", profit=" + profit + ", date="
+ date);
}
  
}

package vehicle;

import java.util.Arrays;
import java.util.Date;
import java.util.Scanner;

public class VehicleTest {
static Salesmen[] salesMan = new Salesmen[3];
static Car[] cars = new Car[50];
static Record[] records = new Record[100];

public static void main(String[] args) {
showMenu();
// initialize array
salesMan[0] = new Salesmen("XYZ", 123, 200, 0, 0);
salesMan[1] = new Salesmen("abc", 456, 300, 0, 0);
salesMan[2] = new Salesmen("pqr", 789, 400, 0, 0);

// Create 4 Cars
Car car1 = new Car(2018, "aaaaa", "11111", "Black", 2500000, 2900000);
Car car2 = new Car(2017, "bbbbb", "22222", "Grey", 2000000, 2500000);
Car car3 = new Car(2016, "ccccc", "33333", "Red", 3000000, 3900000);
Car car4 = new Car(2018, "ddddd", "44444", "White", 4500000, 4900000);
// Add cars to array
cars[0] = car1;
cars[1] = car2;
cars[2] = car3;
cars[3] = car4;

// Create 4 Records
Record record1 = new Record(car1, salesMan[0], "Dealer 1", 400000, new Date());
Record record2 = new Record(car2, salesMan[1], "Dealer 2", 500000, new Date());
Record record3 = new Record(car3, salesMan[2], "Dealer 3", 900000, new Date());
Record record4 = new Record(car4, salesMan[3], "Dealer 4", 400000, new Date());

records[0]=record1;
records[1]=record2;
records[2]=record3;
records[3]=record4;
}

private static void showMenu() {
Scanner scnr = new Scanner(System.in);
while (true) {
System.out.println(
"MENU \n" + " Press 1 - Buy Car" + "\n" + " Press 2 - sell Car" + "\n" + " Press 3 - Show Inventory"
+ "\n" + " Press 4 - Show salesmen" + "\n" + " Press 5 - Show sales records" + "\n"
+ " Press 6 - Exit the program" + "\n" + "Choose an option");

int option = scnr.nextInt();
switch (option) {
case 1:
buyCar();
break;

case 2:
sellCar();
break;

case 3:
showInventory();
break;

case 4:
showSalesMan();
break;

case 5:
showSalesRecord();
break;
case 6:
// ask for confirmation
System.out.println("Do you really want to exit (Y or N) \n");
Scanner sc = new Scanner(System.in);
String choice = sc.next();
if (choice.equalsIgnoreCase("Y")) {
System.exit(0);
} else if (choice.equalsIgnoreCase("N")) {
// Call menu again
showMenu();
}
break;
}
}

}

static void buyCar() {
System.out.println("Please enter Car Details : ");
Scanner sc = new Scanner(System.in);
System.out.println("year");
int year = sc.nextInt();
System.out.println("model");
String model = sc.nextLine();
System.out.println("vin");
String vin = sc.nextLine();
System.out.println("color");
String color = sc.nextLine();
System.out.println("buyingPrice");
double buyingPrice = sc.nextDouble();

// Create a new Car object
Car car = new Car(year, model, vin, color, buyingPrice, 0);
System.out.println("Please enter Dealer Name : ");
String dealer = sc.nextLine();
// Create a Record
Record record = new Record(car, null, dealer, 0, new Date());

// Add these details to array
for (int i = 0; i < cars.length; i++) {
if (cars[i] == null)
cars[i] = car;
}

for (int i = 0; i < records.length; i++) {
if (records[i] == null)
records[i] = record;
}
}

static void sellCar() {
System.out.println("Please enter Car Details : ");
Scanner sc = new Scanner(System.in);
System.out.println("year");
int year = sc.nextInt();
System.out.println("model");
String model = sc.nextLine();
System.out.println("vin");
String vin = sc.nextLine();
System.out.println("color");
String color = sc.nextLine();

System.out.println("sellingPrice");
double sellingPrice = sc.nextDouble();
// Create a new Car object
Car car = new Car(year, model, vin, color, 0, sellingPrice);
System.out.println("Please enter SalesMan Id Who Made the sale : ");
int salesManID = sc.nextInt();
// find out sales man and update the details
Salesmen s = new Salesmen();
for (int i = 0; i < salesMan.length; i++) {
if (salesMan[i].getId() == salesManID) {
s = salesMan[i];
s.setTotalSales(s.getTotalSales()+1);
}
}
// Create a Record
Record record = new Record(car, s, null, car.getSellingPrice() - car.getBuyingPrice(), new Date());

// Car is sold remove it from cars array
// Find car based on vin
for (int i = 0; i < cars.length; i++) {
if (cars[i].getVin().equalsIgnoreCase(car.getVin()))
cars[i] = null;
}

// Add record to array
for (int i = 0; i < records.length; i++) {
if (records[i] == null)
records[i] = record;
}
}

static void showInventory() {
int totalNumberOfCars = 0;
double totalWorth = 0;
for (int i = 0; i < cars.length; i++) {
totalNumberOfCars++;
totalWorth += cars[i].getSellingPrice();
cars[i].display();
}
System.out.println("Total Number of Cars : " + totalNumberOfCars);
System.out.println("Total Net Worth : " + totalWorth);
}

static void showSalesMan() {
for (int i = 0; i < salesMan.length; i++) {
if(salesMan[i]!=null)
{
salesMan[i].display();  
}
}
//Sort the data based on commission , for this we need to
Arrays.sort(salesMan);
  
System.out.println("Sorted Data : ");
for (int i = 0; i < salesMan.length; i++) {
if(salesMan[i]!=null)
{
salesMan[i].display();  
}
}
}
  
static void showSalesRecord()
{
int totalCarsPurchased=0;
int totalCarsSold=0;
double netProfit=0;
//Purchase when buy rate is availebale
//Sell when sell rate is available
for (int i = 0; i < records.length; i++) {
if(records[i]!=null)
{
records[i].display();  
netProfit+=records[i].getProfit();
  
}
}
}
}

//If there are any small mistakes due to time constraints please ignore those. Please co-operate.

Thanks ?

Add a comment
Know the answer?
Add Answer to:
Java Create a program for a car dealer to use where you have a class for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java - Car Dealership Hey, so i am having a little trouble with my code, so...

    Java - Car Dealership Hey, so i am having a little trouble with my code, so in my dealer class each of the setName for the salesman have errors and im not sure why. Any and all help is greatly appreciated. package app5; import java.util.Scanner; class Salesman { private int ID; private String name; private double commRate; private double totalComm; private int numberOfSales; } class Car { static int count = 0; public String year; public String model; public String...

  • Use your Car class from the previous Programming Assignment. For this assignment, create a new class...

    Use your Car class from the previous Programming Assignment. For this assignment, create a new class that represents a Used Car Dealership. Your Java program will simulate an inventory system for the dealership, where the employees can manage the car information. Start by creating an array of 10 cars, with an "ID" of 0 through 9, and use the default constructor to create each car. For example, the third car in an array called cars would have ID 2. You...

  • Java Programming --- complete the given classes DeLand Space Car Dealer needs a new program for...

    Java Programming --- complete the given classes DeLand Space Car Dealer needs a new program for their inventory management system. The program needs the following classes: A main class (SpaceCarDealer.java) that includes the main method and GUI. Two instantiable classes: CarDealer.java o Variables to store the dealer name, and the carsOnLot array in Car type. o A constructor to initialize the name variable with the given dealer name. o An accessor method to return the name of the dealer. o...

  • For Java Program In this lab you will gain experience using all the concepts we learned...

    For Java Program In this lab you will gain experience using all the concepts we learned to this point, which include classes, methods, collections, and file input/output. Also, you will gain experience in team programming. This assignment will be completed by teams of 2. Each member must complete an equal amount of the work in order to receive credit for this assignment. You must write the programmer’s name in a comment for each method you write. You need to create...

  • For Programming Assignment 3 you will be creating a program to manage cars in a dealership....

    For Programming Assignment 3 you will be creating a program to manage cars in a dealership. This will again be a menu driven system. The following is your menu: 1. Display Inventory 2. Add a vehicle 3. Update a vehicle 4. Delete a vehicle 5. Sort inventory by VIN 6. Search inventory by Model 7. Read inventory from file 8. Write inventory to file and exit our program will be class based with the following UML representing the classes: Dealer...

  • Create a python program based on the following requirements the program should also have to have...

    Create a python program based on the following requirements the program should also have to have the following Base Class - Car (Make, Model, year) Sub Class - Gas (Make, Model, year, and gas per mile) Sub Class - Electric (Make, Model, year, and Full Battery charged per mile) 1. Add car 2. View car 3. Delete car 4. Exit program 1. The Car sell manager Application will need to store the car information for gas-powered car members and electric-powered...

  • JAVA PLEASE Create a class called Account with the following instance data Integer id Double balance...

    JAVA PLEASE Create a class called Account with the following instance data Integer id Double balance Provides the following methods Default constructor (defaults balance to 100) Constructor with parameters for the ID and the starting balance Accessor and mutator methods for id and balance Method to perform a withdrawal Method to perform a deposit Create a class called Bank which has an array of Account objects. This class will manage the accounts. It must provide methods Do withdrawal Do deposits...

  • I need an OUTLINE ONLY (pseudocode/comments). DO NOT DO THE PROGRAMMING ASSIGNMENT. Part I: PA3 Outline...

    I need an OUTLINE ONLY (pseudocode/comments). DO NOT DO THE PROGRAMMING ASSIGNMENT. Part I: PA3 Outline (10 points). Create an outline in comments/psuedocode for the programming assignment below. Place your comments in the appropriate files: main.cpp, functions.h, dealer.cpp, dealer.h, dealer.cpp (as noted below). Place into a file folder named LastnamePA3, the zip the content and hand in a zip file to Canvas. Part II: PA3: Car Dealership (40 points) For Programming Assignment 3 you will be creating a program to...

  • (2 bookmarks) In JAVA You have been asked to write a program that can manage candidates...

    (2 bookmarks) In JAVA You have been asked to write a program that can manage candidates for an upcoming election. This program needs to allow the user to enter candidates and then record votes as they come in and then calculate results and determine the winner. This program will have three classes: Candidate, Results and ElectionApp Candidate Class: This class records the information for each candidate that is running for office. Instance variables: first name last name office they are...

  • *Using C++* You will create a program that uses a Critter class to move around a...

    *Using C++* You will create a program that uses a Critter class to move around a Grid, which is also a class. The Critter and the Grid classes will be in separate files. The Critter class will have a data member to count the number of moves made. It will also need data members to hold the current x and y coordinates. It will have a member function that randomly moves it one space in one of 4 directions. You...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT