Question: Car Dealership ArrayList Lab ( IN JAVA ) You are the new owner of Paradise Cars, a start-up car dealership. Your lot is small its
Car Dealership ArrayList Lab ( IN JAVA )
You are the new owner of Paradise Cars, a start-up car dealership. Your lot is small its only large enough to hold a maximum of 5 cars right now. However, your business has been very busy, and you need a computer program to track the cars moving off and on your lot.
Write a Java program to manage the cars on your lot. Your assignments are:
Create a subdirectory called Car Dealership. Be sure to save all of your work for this lab in the Car Dealership directory.
Given the following UML diagram, write the Car class.
| Car |
| - vin : String - year : int - make : String - model : String - price : double |
| + Car(vin: String) + Car(vin: String, year : int, make: String, model : String, price: double) |
| + setPrice(newPrice : double) + getVin() : String + getYear() : int + getMake() : String + getModel() : String + getPrice() : double + toString() : String |
Write the CarDealership class. This class should allow the user to buy and sell cars, as well as print out the current car inventory.
Declare an array of Car objects to represent the 5-car capacity lot.
Declare an attribute of type int to keep track of how many cars are currently on the lot.
Declare an attribute of type int to hold the maximum capacity of the lot. We hope that our business grows someday and our current capacity of 5 increases.
Provide a constructor accepts the maximum capacity of our dealership and initializes all the attributes declared in steps a-c.
Write a method called setMaxCapacity that allows us to change the maximum number of cars our lot can hold.
Write a method called buyCar that accepts a Car object as a parameter. This method needs to check to make sure there is room on the lot for another car. If space is available then add the car to the inventory list in the first available space and increment the number of cars on the lot. If there is no room on the lot, then print out a message indicating that the lot is full.
Write a method call sellCar that accepts the vehicle identification number (vin) of the car being sold. Search the array for the appropriate car. If it is found, then remove it from the inventory by setting the reference in the array to null and decrement the number of cars on the lot. If the car is not found, then print out an error message.
Write a method called printInventory that prints out the information for each car on the lot.
Write the RunDealership class. This class will be used to test the CarDealership class.
Declare a main method.
In the main method perform the following tasks:
Create the CarDealership object and initialize the capacity to 3.
Purchase a new car with the following detais:
VIN: A1B2C3
Year: 2010
Make: Honda
Model: Accord
Price: $18899
Purchase a new car with the following detais:
1.VIN: XYZ123
Year: 2013
Make: Volkswagen
Model: Passat
Price: $19998
Purchase a new car with the following detais:
VIN: JNL246
Year: 2014
Make: Ford
Model: Fusion
Price: $16905
Print out the inventory list. Verify that all 3 cars are listed.
Try to sell car ABCDEF that does not exist.
Try to sell car XYZ123 that does exist.
Print out the inventory again. Verify that only car A1B2C3 and car JNL246 are listed.
Feel free to do any additional testing.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
