Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java - Car Dealership Hey, so i am having a little trouble with my code, so in my dealer class each of the setName for

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 make; public String vin; public String color; public double buyPrice; public double sellPrice;

Car() { count++; }

Car(String year, String model) { this.year = year; this.model = model; count++;}

public void display() { System.out.println(" "); System.out.println("Car: " + year + " " + make + " " + model); // display for case 3 System.out.println("Vin: " + vin); System.out.println("Color: " + color); System.out.println("Pricer: " + sellPrice); System.out.println(); }}

class Record { public Car car; public Salesman salesman; public String date; public double dealerProfit;

public Record() {}

public Record(Car car, Salesman salesman) { this.car = car; //THIS MAY HAVE TO BE CHANGED TO this.c OR = c WE WILL SEE LATER this.salesman = salesman; } }

class Dealer { Salesman salesman[] = new Salesman[3]; Car car[] = new Car[50]; Record record[] = new Record[100]; Dealer() { Salesman fred = new Salesman(); //heres the salesman fred.setName("Fred"); Salesman sally = new Salesman(); sally.setName("sally"); Salesman jordan = new Salesman(); jordan.setName("Jordan"); car[0] = new Car("1993", "Corrola"); //all the base cars car[1] = new Car("1989", "Mustang"); car[2] = new Car("1991", "F-150"); car[3] = new Car("1992", "Toyota"); record[0] = new Record(car[0], fred); //each salesman selling that car record[1] = new Record(car[1], fred); record[2] = new Record(car[2], sally); record[3] = new Record(car[3], jordan); } void menu() { Scanner s = new Scanner(System.in); System.out.println("1. Buy Car"); System.out.println("2. Sell Car"); System.out.println("3. Show Inventory"); System.out.println("4. Show Salesmen"); System.out.println("5. Show Sales Records"); System.out.println("6. Exit"); System.out.println("Choice: "); int menuChoice = s.nextInt();

while (menuChoice <= 0 || menuChoice >= 7) { System.out.println("Invalid Input, needs to be either 1, 2, or 3."); } switch (menuChoice) { case 1: //Buy Car - obtain all info from user on the car bought by //the dealer and store it in a record. make a new object //for the car bought, make a new record, update car and record arrays

//have user enter the info //then validate info to make sure ALL of it is entered //then add it one by one in the order the array is going to Car c = new Car(); System.out.println("Enter year: "); c.year = s.next(); System.out.println("Enter Make: "); c.make = s.next(); System.out.println("Enter Model: "); c.model = s.next(); System.out.println("Enter VIN#: "); c.vin = s.next(); System.out.println("Enter Color: "); c.color = s.next(); System.out.println("Enter Buy Price: "); c.buyPrice = s.nextDouble(); System.out.println("Enter Sell Pricel: "); c.sellPrice = s.nextDouble(); car[Car.count - 1] = c; //adds the input to the array //record would be done the same way Record r = new Record(); r.car = c;

break; /*The user should ONLY be able to buy a car that is in inventory Show a numbered list of cars in the inventory asnd let the user choose a car and a salesman. Update the salesman object that sold the car and update the record array for the sale.*/ case 2: //SELL CAR System.out.println("---------------------INVENTORY---------------------"); System.out.println("To select the car you want choose the number next to the listing."); for (int i = 0; i < Car.count; i++) { System.out.println("Car # " + Car.count); car[i].display(); } int sellmenuChoice = s.nextInt(); //here you need to have it then display that car. System.out.println("You have chosen car # " + sellmenuChoice + "!"); System.out.println("Details about this vehicle will be shown below."); System.out.println("-----------------------------------------------"); //USE DISPLAY METHOD FOR THIS break;

case 3: //SHOW INVENTORY System.out.println("INVENTORY");

for (int i = 0; i < Car.count; i++) { car[i].display(); }

break;

case 4: //SHOW SALESMAN

break;

case 5: //SHOW SALESMAN RECORDS

break;

case 6: //EXIT System.exit(0); break; } } }

public class App5 { public static void main(String[] args) {

Dealer d = new Dealer(); d.menu(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

More Books

Students also viewed these Databases questions

Question

What are the benefits and drawbacks of loyalty promotions?

Answered: 1 week ago

Question

4-6 Is there a digital divide? If so, why does it matter?

Answered: 1 week ago