Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. FIRST: Sophie, Sally and Jack's financing for their Car Lot business is going well. The next step is to create a prototype CarLot class.

1. FIRST:

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.

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.

2. SECOND : CarLot Continued

Sophie, Sally and Jack are about to open for business. Their CarLot class needs some enhancements, however. Add to our previous CarLot the following methods:

Accessors

Car getCarHighestMilage() returns the Car with the highest mileage in the CarLot. If the CarLot is empty, return null.

int getTotalMiles() returns the total mileage of all cars on the CarLot

modify toString to include the above information, but don't include the sorted-by-MPG list.

ArrayList getSortedByMPG() returns a new ArrayList that is ordered by MPG (highest MPG first). The returned ArrayList is empty if the CarLot is empty. Note that this is an accessor; the method must not modify the instance variable in any way. Modify the SelectionSort code from the book to perform the sort.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications Dexa 2022 Workshops 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 In Computer And Information Science 33

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Alfred Taudes ,Atif Mashkoor ,Johannes Sametinger ,Jorge Martinez-Gil ,Florian Sobieczky ,Lukas Fischer ,Rudolf Ramler ,Maqbool Khan ,Gerald Czech

1st Edition

3031143426, 978-3031143427

More Books

Students also viewed these Databases questions

Question

Prepare an ID card of the continent Antarctica?

Answered: 1 week ago

Question

What do you understand by Mendeleev's periodic table

Answered: 1 week ago

Question

9. Explain the relationship between identity and communication.

Answered: 1 week ago

Question

a. How do you think these stereotypes developed?

Answered: 1 week ago

Question

a. How many different groups were represented?

Answered: 1 week ago