Question
CarLot CarLot Sophie, Sally and Jack's financing for their Car Lot business is going well. The next step is to create a prototype CarLot class.
CarLot
CarLot
Sophie, Sally and Jack's financing for their Car Lot business is going well. The next step is to create a prototype CarLot class.
Write a class CarLot
A CarLot has only one instance variable, an ArrayList of Car elements
CarLot has a single, no argument constructor.
Accessors
Car find(String carId) returns the Car whose identifier matches carId, or null if there is no such Car.
Car get(int position) returns the Car occupying the given position in the CarLot. The first car added to the CarLot is position 0, the next car added is position 1, etc. If there is no Car at the specified position, return null. .
double getCarAverageMPG() returns the average MPG of all cars on the CarLot. If the CarLot is empty, return -1.
Car getCarBestMPG() returns the Car with the best MPG on the CarLot. If more than one Car has the best MPG, return the Car with at the lowest position. (So if Cars at positions 5 and 8 both have the best MPG, return the Car at position 5). If the CarLot is empty, return null.
int size() returns the number of Cars on the CarLot
String toString() returns a String representation of the CarLot
Mutators
boolean add(Car carToAdd) that adds a Car to the CarLot. add returns true if the Car was added successfully, false otherwise.
Test Class
Write a CarLotMain class that has only a main method. CarLotMain is a console program that asks the user for the number of cars to be added to a CarLot. For each Car, the program asks the user for that Car's information and adds the Car to the CarLot. When all the cars have been entered, it prints the size of the CarLot, and the contents of CarLot ordered by position. Finally, the program asks the user for one Car identifier, and displays the Car with that identifier.
Grading Elements
CarLot has a single instance variable of type ArrayList
CarLot has a single no argument constructor
All methods return the designated type and have the correct signature
All methods return the correct values
Accessors do not change the state of the CarLot (i.e., they do not change the instance variable)
add places Cars into the CarLot at the correct position
CarLotMain provides the specified operation to allow CarLot to be tested.
Sanity Check - To help avoid these issues you'll find attached file StringSetSanityCheck.java. Place this file in your StringSet project and compile your program. If there are any problems with your method signatures, you'll get a compile error in StringSetSanityCheck. Correct your code to in StringSet as necessary.
public class CarLotSanityCheck { //This code verifies that the signatures for CarLot class //methods are correct. This code does not validate //the code in those methods. public static void SanityCheck(){ CarLot objCarLot0 = new CarLot(); objCarLot0.add(new Car()); objCarLot0.find(""); Car objCar0 = objCarLot0.get(0); double avg0 = objCarLot0.getCarAverageMPG(); objCar0 = objCarLot0.getCarBestMPG(); int size0 = objCarLot0.size(); String str0 = objCarLot0.toString(); } }
public class CarSanityCheck { //This code verifies that the signatures for Car class //methods are correct. This code does not validate //the code in those methods. public static void SanityCheck(){ Car objCar0 = new Car(); Car objCar1 = new Car(""); Car objCar2 = new Car("",0,0,0,0); objCar0.addMiles(0); int comp0 = objCar0.compareId(objCar1); comp0 = objCar0.compareMPG(objCar1); comp0 = objCar0.comparePrice(objCar1); comp0 = objCar0.compareMiles(objCar1); comp0 = objCar0.getCost(); String str0 = objCar0.getIdentifier(); comp0 = objCar0.getProfit(); boolean sold0 = objCar0.isSold(); objCar0.setCost(0); objCar0.setIdentifier(""); objCar0.setMiles(0); objCar0.setMPG(0); objCar0.setPrice(0); objCar0.setSold(true); str0 = objCar0.toString(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started