Java Language please Use the classes Q3 and Car provided, and write a class call
ID: 3851971 • Letter: J
Question
Java Language please
Use the classes Q3 and Car provided, and write a class called CarDealership which adheres to the following class description.
-Each dealership has an array of Cars called “cars”
-Each dealership has a number of cars called “numberOfCars”
-Each dealership has a “dealershipID”, and the ID for the first CarDealership made is zero and increments by one every time a dealership is made (as in, when CarDealership’s constructor is called)
-Each dealership has a maximum number of cars it can hold on the lot, called “maxNumberOfCars”
-Each dealership has a name, called “dealerName”
-CarDealership has a single constructor that accepts the maximum number of cars on the lot and the name of the dealer (it must also assign the dealershipID and initialize the cars array)
-Each dealership has a method called addNewCar, which accepts the colour and make of the car as strings, as well as the year and the price of the car, as ints
-if the car was successfully added to the lot, it should print “Added ” followed by the toString of the car, followed by “ to ” followed by the name of the dealer
-if it was not successfully added, it should print “Cannot add ” followed by the toString of the car, followed by “ to ” followed by the name of the dealer, followed by “ – Lot is full!”
-Each dealership has a sellCar method which accepts a car, and this method returns a boolean (true if the car was found on the lot and sold successfully, false otherwise)
-A car is successfully sold if it is found on the lot, and sellCar is unsuccessful if the car does not exist on the lot (as in, it was not found in the cars array)
-This must traverse the cars array, and if it finds a match for the supplied car, it must remove the car from the array and shift all other elements of the array over so there are no gaps (as you’ve done in a previous assignment)
-Of course, this must also decrease the number of cars
-Finally, CarDealership must have a toString method that prints “Dealer: ” followed by the dealer name, followed by “ID: ” and the ID of the dealership on a new line, followed by “Number of Cars on Lot: ” and the number of cars, followed by “/” and the max number of cars for that dealership on a separate line, followed by “Car Inventory:”, followed by all of the toStrings of all of the cars on the lot, all on separate lines
car class
Q3 class
Explanation / Answer
car class
Q3 class
//CarDealship.java
//output:-->
"C:Program FilesJavajdk1.8.0_92injava" "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA Community Edition 2017.1libidea_rt.jar=8640:C:Program FilesJetBrainsIntelliJ IDEA Community Edition 2017.1in" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJavajdk1.8.0_92jrelibcharsets.jar;C:Program FilesJavajdk1.8.0_92jrelibdeploy.jar;C:Program FilesJavajdk1.8.0_92jrelibextccess-bridge.jar;C:Program FilesJavajdk1.8.0_92jrelibextcldrdata.jar;C:Program FilesJavajdk1.8.0_92jrelibextdnsns.jar;C:Program FilesJavajdk1.8.0_92jrelibextjaccess.jar;C:Program FilesJavajdk1.8.0_92jrelibextjfxrt.jar;C:Program FilesJavajdk1.8.0_92jrelibextlocaledata.jar;C:Program FilesJavajdk1.8.0_92jrelibext ashorn.jar;C:Program FilesJavajdk1.8.0_92jrelibextsunec.jar;C:Program FilesJavajdk1.8.0_92jrelibextsunjce_provider.jar;C:Program FilesJavajdk1.8.0_92jrelibextsunmscapi.jar;C:Program FilesJavajdk1.8.0_92jrelibextsunpkcs11.jar;C:Program FilesJavajdk1.8.0_92jrelibextzipfs.jar;C:Program FilesJavajdk1.8.0_92jrelibjavaws.jar;C:Program FilesJavajdk1.8.0_92jrelibjce.jar;C:Program FilesJavajdk1.8.0_92jrelibjfr.jar;C:Program FilesJavajdk1.8.0_92jrelibjfxswt.jar;C:Program FilesJavajdk1.8.0_92jrelibjsse.jar;C:Program FilesJavajdk1.8.0_92jrelibmanagement-agent.jar;C:Program FilesJavajdk1.8.0_92jrelibplugin.jar;C:Program FilesJavajdk1.8.0_92jrelib esources.jar;C:Program FilesJavajdk1.8.0_92jrelib t.jar;C:UsersNarendraIdeaProjectscar Dealershipoutproductioncar Dealership" com.company.Q3
Added red 2016 Lambo Aventador worth $400000 to Ryan's Cool Cars
Added yellow 2014 Ferrari Enzo worth $500000 to Ryan's Cool Cars
Added blue 1968 Chevy Camaro worth $120000 to Ryan's Cool Cars
Added white 2016 Nissan GTR Nismo worth $200000 to Ryan's Cool Cars
Added blue 2017 Mustang Shelby worth $120000 to Ryan's Cool Cars
Cannot Addblack 2016 Nissan GTR worth $180000 to Ryan's Cool Cars Lot is full
Added yellow 2012 Toyota Echo worth $6000 to World's Smallest Car Dealership
Added red 2017 Mini Cooper worth $40000 to World's Smallest Car Dealership
Added silver 2017 Dodge Ram worth $60000 to Billy's Truck Emporium
Added black 2017 Ford Explorer worth $60000 to Billy's Truck Emporium
Added white 2017 GMC Sierra worth $60000 to Billy's Truck Emporium
Dealer : Ryan's Cool Cars
ID : 0
Numbers of Cars on Lot: 5/5
For that dealership
Car Inventory :-- [red 2016 Lambo Aventador worth $400000, yellow 2014 Ferrari Enzo worth $500000, blue 1968 Chevy Camaro worth $120000, white 2016 Nissan GTR Nismo worth $200000, blue 2017 Mustang Shelby worth $120000]
Dealer : World's Smallest Car Dealership
ID : 1
Numbers of Cars on Lot: 2/2
For that dealership
Car Inventory :-- [yellow 2012 Toyota Echo worth $6000, red 2017 Mini Cooper worth $40000]
Dealer : Billy's Truck Emporium
ID : 2
Numbers of Cars on Lot: 3/6
For that dealership
Car Inventory :-- [silver 2017 Dodge Ram worth $60000, black 2017 Ford Explorer worth $60000, white 2017 GMC Sierra worth $60000, null, null, null]
Sold a red Lambo Aventador! (you got it right)
That's strange, we just sold our only Lambo Aventador so how can we sell another?
They don't have this car in stock! (you probably got it right)
Why can't I have the yellow Ferrari?! :(
Dealer : Ryan's Cool Cars
ID : 0
Numbers of Cars on Lot: 3/5
For that dealership
Car Inventory :-- [red 2016 Lambo Aventador worth $400000, yellow 2014 Ferrari Enzo worth $500000, blue 1968 Chevy Camaro worth $120000, white 2016 Nissan GTR Nismo worth $200000, blue 2017 Mustang Shelby worth $120000]
Process finished with exit code 0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.