Question

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 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("\n");
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();
}
}

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

I have just override the method of setName from the package java.lang, and it worked, except that I don't have the file app5.java.

Here is the function:

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

Place this in the class salesman and everything should work as expected!!!

Add a comment
Know the answer?
Add Answer to:
Java - Car Dealership Hey, so i am having a little trouble with my code, so...
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
  • Hey guys I am having trouble getting my table to work with a java GUI if...

    Hey guys I am having trouble getting my table to work with a java GUI if anything can take a look at my code and see where I am going wrong with lines 38-49 it would be greatly appreciated! Under the JTableSortingDemo class is where I am having erorrs in my code! Thanks! :) import java.awt.*; import java.awt.event.*; import java.util.*; import java.util.List; import javax.swing.*; public class JTableSortingDemo extends JFrame{ private JTable table; public JTableSortingDemo(){ super("This is basic sample for your...

  • 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...

  • Below are the Car class and Dealership class that I created In the previous lab import...

    Below are the Car class and Dealership class that I created In the previous lab import java.util.ArrayList; class Car { private String make; private String model; private int year; private double transmission; private int seats; private int maxSpeed; private int wheels; private String type; public Car() { } public Car(String make, String model, int year, double transmission, int seats, int maxSpeed, int wheels, String type) { this.make = make; this.model = model; this.year = year; this.transmission = transmission; this.seats =...

  • Hi, I am writing Java code and I am having a trouble working it out. The...

    Hi, I am writing Java code and I am having a trouble working it out. The instructions can be found below, and the code. Thanks. Instructions Here are the methods needed for CIS425_Student: Constructor: public CIS425_Student( String id, String name, int num_exams ) Create an int array exams[num_exams] which will hold all exam grades for a student Save num_exams for later error checking public boolean addGrade( int exam, int grade ) Save a grade in the exams[ ] array at...

  • Java. Java is a new programming language I am learning, and so far I am a...

    Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...

  • I need the following java code commented import java.util.Scanner; public class Main { public static void...

    I need the following java code commented import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner (System.in); int productNo=0; double product1; double product2; double product3; double product4; double product5; int quantity; double totalsales=0; while(productNo !=0) System.out.println("Enter Product Number 1-5"); productNo=input.nextInt(); System.out.println("Enter Quantity Sold"); quantity=input.nextInt(); switch (productNo) { case 1: product1=1.00; totalsales+=(1.00*quantity); break; case 2: product2=2.00; totalsales+=(2.00*quantity); break; case 3: product3=6.00; totalsales+=(6.00*quantity); break; case 4: product4=23.00; totalsales+=(23.00*quantity); break; case 5: product5=17.00; totalsales+=(17.00*quantity); break;...

  • Java Programming Question

    After pillaging for a few weeks with our new cargo bay upgrade, we decide to branch out into a new sector of space to explore and hopefully find new targets. We travel to the next star system over, another low-security sector. After exploring the new star system for a few hours, we are hailed by a strange vessel. He sends us a message stating that he is a traveling merchant looking to purchase goods, and asks us if we would...

  • How to build Java test class? I am supposed to create both a recipe class, and...

    How to build Java test class? I am supposed to create both a recipe class, and then a class tester to test the recipe class. Below is what I have for the recipe class, but I have no idea what/or how I am supposed to go about creating the test class. Am I supposed to somehow call the recipe class within the test class? if so, how? Thanks in advance! This is my recipe class: package steppingstone5_recipe; /** * *...

  • Java Assignment Calculator with methods. My code appears below what I need to correct. What I...

    Java Assignment Calculator with methods. My code appears below what I need to correct. What I need to correct is if the user attempts to divide a number by 0, the divide() method is supposed to return Double.NaN, but your divide() method doesn't do this. Instead it does this:     public static double divide(double operand1, double operand2) {         return operand1 / operand2;     } The random method is supposed to return a double within a lower limit and...

  • CONVERT THIS JAVA CODE WITH THE JAVA DOC GUIDELINES WHERE APPROPRIATE. DO NOT CHANGE THE CODE....

    CONVERT THIS JAVA CODE WITH THE JAVA DOC GUIDELINES WHERE APPROPRIATE. DO NOT CHANGE THE CODE. SAME CODE SHOULD BE USED FOR THE DOCUMENTATION PURPOSES. ONLY INSERT THE JAVA DOC. //Vehicle.java public class Vehicle {    private String manufacturer;    private int seat;    private String drivetrain;    private float enginesize;    private float weight; //create getters for the attributes    public String getmanufacturer() {        return manufacturer;    }    public String getdrivetrain() {        return drivetrain;...

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
ADVERTISEMENT