Question

In: Computer Science

in java pls Write a Car Dealership management program. This program will allow the employees of...

in java pls
Write a Car Dealership management program. This program will allow the employees of the Dealership to add cars to their database and sell them.

You will be implementing two classes: Car and CarDealership. Car will store data associated with the cars and CarDealership will be the management program.

Note: 5 points of your grade is based on Coding Style. You will need to update the Starter Code to follow the standards described here. Use the "Run" button to check your Coding Style without using a submission.

Instructions
Follow the instructions for each class.

Car class
Implement the Car class using the specifications below. There is no Javadoc for this assignment.

FIELDS
Name Type Modifier
make String private
model String private
year int private
CONSTRUCTOR
Parameters (order matters) Modifier
String make, String model, int year public
METHODS
Name Return Type Parameters Description
getMake String None Returns the make field.
getModel String None Returns the model field.
getYear int None Returns the year field.
setMake void String Sets the make field to the argument.
setModel void String Sets the model field to the argument.
setYear void int Sets the year field to the argument.
toString String None Returns a String in a specific format.
For example, if a car object has make "Honda", model "Accord", and year "2019", the returned string should be: "Make: Honda | Model: Accord | Year: 2019"
CarDealership class
Our car dealership has a very small parking lot and can only sell three vehicles at a time.

Every time a financial transaction occurs, the dailyTransactions field needs to be updated. Selling services or vehicles are positive increases, while purchasing vehicles are negative decreases. For the purposes of this assignment, you can assume that every car sells for $15,000 and cars are purchased for $10,000. Service prices are listed in the services menu.

FIELDS
Name Type Modifier
carOne Car private
carTwo Car private
carThree Car private
dailyTransactions double private
CONSTRUCTOR
Parameters (order matters) Modifier
Car carOne, Car carTwo, Car carThree public
None public
METHODS
Name Return Type Parameters Description
performMaintenance void Scanner scan Uses a series of prompts to calculate the cost of the maintenance the user wants performed. Updates dailyTransactions accordingly.
sellCar void Scanner scan Uses a series of prompts to sell the customer a car, if one is available. If the user chooses to make the purchase, remove the selected car from the inventory. If the user does not make the purchase, return to the main menu. Updates dailyTransactions accordingly.
buyCar void Scanner scan If one of the car spots is open, purchases a car and saves its information in the open field. If all of the spots are full, returns to the main menu. Updates dailyTransactions accordingly.
printInventory void None Print the current inventory using the formatting described in the next section.
menu void None Implement the user interface described in the next section.
Note: You must create a Scanner object in menu() and pass it as a parameter to the other methods.

performMaintenance
Welcome to the Maintenance Menu!
Please select the service you wish to record:
1. Oil Change ($50)
2. Tire Rotation ($30)
3. Detailing ($100)
4. Tune-up ($200)
[1]
Your selection has been recorded!
Did you sell another service?
1. Yes
2. No
[1]
Please select the service you wish to record:
1. Oil Change ($50)
2. Tire Rotation ($30)
3. Detailing ($100)
4. Tune-up ($200)
[2]
Your selection has been recorded!
Did you sell another service?
1. Yes
2. No
[2]
Thank you! Now returning to the Main Menu...
sellCar
Welcome to the Sales Menu!
Current Inventory is Listed Below:
Make: Honda | Model: Accord | Year: 2019
Make: Toyota | Model: Camry | Year: 2017
Make: Saab | Model: 9-3 | Year: 2005
Did you sell a vehicle?
1. Yes
2. No
[1]
Which vehicle was sold? Please enter the Make, Model, and Year separated by commas.
[Honda,Accord,2019]
The vehicle list has been updated!
Current Inventory is Listed Below:
Make: Toyota | Model: Camry | Year: 2017
Make: Saab | Model: 9-3 | Year: 2005
Did you sell another vehicle?
1. Yes
2. No
[1]
Which vehicle was sold? Please enter the Make, Model, and Year separated by commas.
[Toyota,Camry,2017]
The vehicle list has been updated!
Current Inventory is Listed Below:
Make: Saab | Model: 9-3 | Year: 2005
Did you sell another vehicle?
1. Yes
2. No
[1]
Which vehicle was sold? Please enter the Make, Model, and Year separated by commas.
[Saab,9-3,2005]
The vehicle list has been updated!
No vehicles currently available.
Thank you! Now returning to the Main Menu...
Note: If there are no vehicles in the inventory and the user calls sellCar, the output should be as follows:

Welcome to the Sales Menu!
No vehicles currently available.
Thank you! Now returning to the Main Menu...
buyCar

Welcome to the Purchasing Menu!
Current Inventory is Listed Below:
Make Saab | Model: 9-3 | Year: 2005
Did you purchase a vehicle?
1. Yes
2. No
[1]
Please enter the Vehicle Details!
Make:
[Subaru]
Model:
[Forester]
Year:
[2020]
Current Inventory is Listed Below:
Make: Saab | Model: 9-3 | Year: 2005
Make: Subaru | Model: Forester | Year: 2020
Did you purchase another vehicle?
1. Yes
2. No
[1]
Please enter the Vehicle Details!
Make:
[Chevrolet]
Model:
[Camero]
Year:
[2012]
Current Inventory is Listed Below:
Make: Saab | Model: 9-3 | Year: 2005
Make: Subaru | Model: Forester | Year: 2020
Make: Chevrolet | Model: Camero | Year: 2012
The Vehicle Inventory is now full.
Thank you! Now returning to the Main Menu...
Note: If no cars are in the inventory, you should not attempt to print the inventory. Additionally, if the user selects "No", return to the Main Menu. An example is below.

Welcome to the Purchasing Menu!
Did you purchase a vehicle?
1. Yes
2. No
[2]
Thank you! Now returning to the Main Menu...
printInventory
Current Inventory is Listed Below:
Make: Honda | Model: Accord | Year: 2019
Make: Toyota | Model: Camry | Year: 2017
Make: Saab | Model: 9-3 | Year: 2005
You will need to determine a way to identify which of the car fields is currently storing a car.

menu
Welcome to the Main Menu!
The Daily Transactions value is currently: $0.00
Please select an Option:
1. Perform Maintenance
2. Sell Car
3. Buy Car
4. Print Inventory
5. Quit
[5]
Thank you for using the Car Dealership program!
Print the entire menu for every time you return to it, including the welcome statement. Make sure to keep the daily transactions value up to date in every method.

HINTS
dailyTransactions can be negative. Update it with every transaction.
When printing dailyTransactions, be sure to print two decimal places.
This project does not have a main method. Feel free to create one if you'd like to test your implementation.
You cannot sell cars with an empty inventory.
You must create your Scanner in the menu method and pass it as a parameter to the other methods. Verify that the Scanner is only instantiated once (that is, you should not call menu from any other method).
Note: Your methods will be tested independently of one another. You also need to implement error checking. If an invalid input is passed at any point, print the error message "An error occurred!" and print the main menu. For example:

Welcome to the Main Menu!
The Daily Transactions value is currently: $0.00
Please select an Option:
1. Perform Maintenance
2. Sell Car
3. Buy Car
4. Print Inventory
5. Quit
[7]
An error occurred!
Welcome to the Main Menu!
The Daily Transactions value is currently: $0.00
Please select an Option:
1. Perform Maintenance
2. Sell Car
3. Buy Car
4. Print Inventory
5. Quit
Thank you for using the Car Dealership program!h

Solutions

Expert Solution

import java.util.Scanner;
class Car{
    private String make;
    private String model;
    private int year;
    
    public Car(String make,String model,int year){
        this.make=make;
        this.model=model;
        this.year=year;
    }
    public String getMake(){
        return make;
    }
    public String getModel(){
        return model;
    }
    public int getYear(){
        return Year;
    }
    public void setMake(String make){
        this.make=make;
    }
    public void setModel(String model){
        this.model=model;
    }
    public void setYear(int year){
         this.year=year;
    }
    public String toString(){
        return "Make: "+make+" | Model: "+model+" | Year: "+year;
    }
    
}
class CarDealership{
    private Car carOne;
    private Car carTwo;
    private Car carThree;
    int amount=0;
    public CarDealership(Car carOne,Car carTwo,Car carThree){
         this.carOne=carOne;
         this.carTwo=carTwo;
         this.carThree=carThree;
    }
    public void performMaintenance(Scanner scan){
        System.out.println("Welcome to the Maintenance Menu!")
        System.out.println("Please select the service you wish to record:");
        System.out.println("1. Oil Change ($50)\n2. Tire Rotation ($30)");
        System.out.println("3. Detailing ($100)\n4. Tune-up ($200)");
        int i=sc.nextInt();
        int j=0;
        while(j==0){
        System.out.println("Your selection has been recorded!");
        System.out.println("Did you sell another service?");
        System.out.println("1. Yes\n2. No");
        String s=sc.nextLine();
        if(s.equalsIgnoreCase("No")){
            System.out.println("Thank you! Now returning to the Main Menu...")
            break;
        }
        }
        
    }
    public void sellCar(Scanner scan){
         System.out.println("Welcome to the Sales Menu!");
         int k=0;
         int j=0;
         int count++;
          while(j==0){
         System.out.println("Current Inventory is Listed Below:");
         String str[]=new String[3];
         str[0]=null;
         str[1]=null; str[2]=null;
         if(k!=1){str[0]=carOne.toString();}
         else if(k!=2){str[1]=carTwo.toString();}
         else if(k!=3){str[2]=carThree.toString();}
       
        for(int i=0;i<3;i++){
             if(!(str[i].equals(null))){
             System.out.println(str[i]);}
        }
        System.out.println("Did you sell a vehicle");
        System.out.println("1. Yes\n2. No");
        String s=sc.nextLine();
        if(s.equalsIgnoreCase("Yes")){
            if(count==3){
                System.out.println("No vehicles currently available.Thank you! Now returning to the Main Menu...")
            }
            else{
            System.out.println("Which vehicle was sold? Please enter the Make, Model, and Year separated by commas.");
            String sold=sc.nextLine();
            String arr[]=sold.split(",");
            System.out.println("The vehicle list has been updated!");
            amount+=15000;
            if(carOne.getMake().equals(arr[0])&&carOne.getModel().equals(arr[1])&&Integer.parseInt(carOne.getYear()).equals(arr[2]){
                k=1;
                count++;
            }
            else if(carTwo.getMake().equals(arr[0])&&carTwo.getModel().equals(arr[1])&&Integer.parseInt(carTwo.getYear()).equals(arr[2]){
                k=2;
                count++;
            }
            else if(carThree.getMake().equals(arr[0])&&carThree.getModel().equals(arr[1])&&Integer.parseInt(carThree.getMake()).equals(arr[2]){
                k=3;
                count++;
            }
            else{
                k=0;
            }
            }
            
        }
        else if(s.equalsIgnoreCase("No")){
            System.out.println("Thank you! Now returning to the Main Menu...")
            break;
        }
    }
    public void buyCar(Scanner scan){
        System.out.println("Current Inventory is Listed Below:");
        int k=0;
         int j=0;
          while(j==0){
         System.out.println("Current Inventory is Listed Below:");
         String str[]=new String[3];
         str[0]=null;
         str[1]=null; str[2]=null;
         if(k!=1){str[0]=carOne.toString();}
         else if(k!=2){str[1]=carTwo.toString();}
         else if(k!=3){str[2]=carThree.toString();}
       
        for(int i=0;i<3;i++){
             if(!(str[i].equals(null))){
             System.out.println(str[i]);}
        }
        System.out.println("Did you purchase a vehicle");
        System.out.println("1. Yes\n2. No");
        String s=sc.nextLine();
        if(s.equalsIgnoreCase("Yes")){
            amount-=10000;
            System.out.println("Please enter the vehicle Details!");
            System.out.println("Make: ");
            String Make=sc.nextLine();
            System.out.println("Model: ");
            String Model=sc.nextLine();
            System.out.println("Year: ");
            String Year=sc.nextInt();
            int count=0;
            if(count==0){
            carOne.setMake(Make);
             carOne.setModel(Model);
              carOne.setYear(Year);
                k=1;
                count++;
            }
            else if(count==1){
                carTwo.setMake(Make);
             carTwo.setModel(Model);
              carTwo.setYear(Year);
                k=2;
                count++;
            }
             else if(count==2){
                carThree.setMake(Make);
             carThree.setModel(Model);
              carThree.setYear(Year);
                k=3;
                count++;
            }
            
        }
        else if(s.equalsIgnoreCase("No")){
            System.out.println("Thank you! Now returning to the Main Menu...");
             break;
        }
    }
    public void printInventory(){
        Scanner sc=new Scanner(System.in);
    System.out.println("Welcome to Main Menu!\nThe Daily Transactions value is currently: "+amount);
    System.out.println("Please select an Option:");
    System.out.println("1. Perform Maintenance\n2. Sell Car\n3. Buy Car\n4. Print Inventory\n5. Quit");
    int ch=sc.nextInt();
    switch(ch){
        case 1: performMaintenance();break;
        case 2: sellCar();break;
        case 3: buyCar();break;
        case 4:  printInventory();break;
        case 5: System.out.println("Thank you for using the Car Dealership program!");
                 break;
    }
    
    }
}

Thank you!, if you have any queries post it below in the comment section i will try my best to resolve your queries and i will add it to my answer if required. Please give upvote if you like.


Related Solutions

Write an inventory program in java for a used car lot. You should have one Car...
Write an inventory program in java for a used car lot. You should have one Car parent class and child classes for 3 vehicle types (convertible, SUV, Classic, etc). The parent class should have 3 variables and 3 functions, each child class should have 1 variable unique to it and 1 function. Your program should allow the user to store up to 100 cars in the inventory and write the cars out to a file when done.
In this assignment you are to make an inventory management system for a car dealership. The...
In this assignment you are to make an inventory management system for a car dealership. The dealerships current method of tracking inventory is using a list which has the color and name of each car they have in inventory. There current inventory list will look like the example below. RED TOYOTAWHITE HONDA...BLACK BMW The types of cars that they order are as follows: TOYOTA, HONDA, BMW, NISSAN, TESLA, DODGE The colors they purchase are as follows: RED, WHITE, BLUE, BLACK,...
You manage a car dealership in a large city. Many of your sales employees are very...
You manage a car dealership in a large city. Many of your sales employees are very successful and have purchased their own vehicles from your dealership.   Your dealership finances the sale of some of these vehicles. One employee recently paid off the balances on a couple of new vehicles purchased from your dealership. You discover this information after investigating complaints from customers about this particular employee’s actions. His sales are down, and customer complaints about his attitude abound. He previously...
Design and implement a Java program that creates a GUI that will allow a customer to...
Design and implement a Java program that creates a GUI that will allow a customer to order pizza and other items from a Pizza Paarlor. The customer should be able to order a variety of items which are listed below. The GUI should allow the customer (viaJavaFX UI Controls - text areas, buttons, checkbox, radio button, etc.) to input the following information: Name of the customer First Name Last Name Phone number of the customer Type of food being order...
(JAVA PLS)You will create a program that will follow the queuing theory of the Barbershop Problem....
(JAVA PLS)You will create a program that will follow the queuing theory of the Barbershop Problem. In this you will use ques and random number generator to complete this project. You will create three queues Couch - the area where patron will wait just prior to getting their hair cut; Line - the area where patron will form a line just before reaching the couch; and Cashier - the area where patrons will line up to pay just before exiting...
***USING JAVA Scenario: You will be writing a program that will allow a user to find...
***USING JAVA Scenario: You will be writing a program that will allow a user to find and replace misspelled words anywhere in the phrase, for as many words as the user wishes. Once done (see example runs below), the program will print the final phrase and will show the Word Count, Character Count, the Longest Word and the Shortest Word. Requirements: Do not use Arrays for this assignment. Do not use any String class methods (.phrase(), replace methods, regex methods)...
Using java you have to create a simple program that will allow for the storage of...
Using java you have to create a simple program that will allow for the storage of requests for money. Each request will consist of a person's name and dollar amount (US dollars). The business rules are straight forward. Each name should be a first and last name. The first letter of each element in the name should be capitalized. The dollar amount should be between 1 and 1000 dollars and include cents (2 decimals). You should include validations, but it...
Calvin borrows $20,000 from a car dealership to purchase a vehicle. The car dealership charges 12%...
Calvin borrows $20,000 from a car dealership to purchase a vehicle. The car dealership charges 12% interest, compounded monthly. Calvin is expected to pay off the loan principal and all interest charged with equal monthly payments over a 3-year period. a. What will Calvin’s monthly payment need to be? (4 points) b. With the first monthly payment, how much of this payment will be “interest”, and how much of this payment will be “principal”? (4 points) c. Once the loan...
Calvin borrows $20,000 from a car dealership to purchase a vehicle. The car dealership charges 12%...
Calvin borrows $20,000 from a car dealership to purchase a vehicle. The car dealership charges 12% interest, compounded monthly. Calvin is expected to pay off the loan principal and all interest charged with equal monthly payments over a 3-year period. a. What will Calvin’s monthly payment need to be? (4 points) b. With the first monthly payment, how much of this payment will be “interest”, and how much of this payment will be “principal”? (4 points) c. Once the loan...
We are to make a program about a car dealership using arrays. I got the code...
We are to make a program about a car dealership using arrays. I got the code to display all cars in a list, so I'm good with that. What I'm stuck at is how to make it so when a user inputs x for search, it allows them to search the vehicle. We need two classes, one that shows the car information and another that shows the insert, search, delete, display methods. Here is what I have so far package...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT