Question: PROBLEM 2 ArrayLists Write a Java application that uses an ArrayList to store information about new cars. You will write three classes: NewCarListTester, NewCarList, and

PROBLEM 2 ArrayLists

Write a Java application that uses an ArrayList to store information about new cars. You will write three classes: NewCarListTester, NewCarList, and NewCar.

NewCar

The NewCar class is from HW6. Simply copy it from your HW6 solution and use it again here.

NewCarList

This is a class that has no constructors and a single attribute, an instantiated

ArrayList used to store information about NewCars. For example,

ArrayList carList = new ArrayList(); NewCarList will have the following four methods:

The add() method will accept a NewCar object and add it to the ArrayList.

The display() method will display, using toString(), the information about each object in the ArrayList .

The select(double maxPrice) method will do the same thing as display(), except that it will display only the cars with a final price less than or equal to the parameter maxPrice.

The drop(int index) method will delete the NewCar stored in the

ArrayList slot with the given index.

NewCarListTester

In NewCarListTester, the main method will instantiate five NewCars. Hard code the data for each car, using the NewCar constructor and other methods (e.g., calcFinalPrice). The actual data values are in the file HW09Data.xlsx.

For each car, create (i.e. instantiate) a NewCar object using a parameterized constructor for year, make and model (see HW06) and pass this object to the add method in NewCarList that uses that object as a parameter so it can be added to the ArrayList.

Included in NewCar is an attribute, finalPrice, with an appropriate accessor titled

getFinalPrice() accessor. NewCar also will provide the following methods:

calcFinalPrice(double stickerprice, double discount, double salesTaxRate)

calcZeroPctMontlyPayment(int numMonths) getCarName()

getCarAbbrev() toString

Create a NewCarListTester class that will:

Add five cars to the list (run calcFinalPrice for each). Again,the data input is hard-coded; i.e. there is no need to use Scanner input.

Display all the cars in the list.

Display all the cars under a certain final price (inclusive) (use the select method and be sure to test a boundary condition).

Add three more cars (run calcFinalPrice for each) and display the list.

Drop the second item in the list (What is the index?).

Display the cars again.

DETAILS

Submit your files to the MyCourses dropbox.

Carry out all calculations in the within the NewCar and NewCarList classes.

Use appropriate data types

Loop counts should not be hard coded (flexible number of cars in the list)

Output should resemble the following:

----jGRASP exec: java -ea -ea NewCarListTester

*** List of cars

You want to purchase a "2010 Kia Rio" Abbreviation: "10KR" Finalprice: 10800.0

You want to purchase a "2007 Kia Rio" Abbreviation: "07KR" Finalprice: 9720.0

You want to purchase a "2004 Honda Civic" Abbreviation: "04HC" Finalprice: 6480.0

You want to purchase a "2004 Honda Civic" Abbreviation: "04HC" Finalprice: 6480.0

You want to purchase a "2010 Chevrolet Cobalt" Abbreviation: "10CC" Finalprice: 10800.0

*** List of cars under $9720

You want to purchase a "2007 Kia Rio" Abbreviation: "07KR" Finalprice: 9720.0

You want to purchase a "2004 Honda Civic" Abbreviation: "04HC" Finalprice: 6480.0

You want to purchase a "2004 Honda Civic" Abbreviation: "04HC" Finalprice: 6480.0

*** Add three more cars and list

You want to purchase a "2010 Kia Rio" Abbreviation: "10KR" Finalprice: 10800.0

You want to purchase a "2007 Kia Rio" Abbreviation: "07KR" Finalprice: 9720.0

You want to purchase a "2004 Honda Civic" Abbreviation: "04HC" Finalprice: 6480.0

You want to purchase a "2004 Honda Civic" Abbreviation: "04HC" Finalprice: 6480.0

You want to purchase a "2010 Chevrolet Cobalt" Abbreviation: "10CC" Finalprice: 10800.0

You want to purchase a "2000 Honda Accord" Abbreviation: "00HA" Finalprice: 3240.0

You want to purchase a "2009 Suburu Forester" Abbreviation: "09SF"

Finalprice: 23760.0

You want to purchase a "2011 Checrolet Malibu" Abbreviation: "11CM" Finalprice: 23760.0

*** Delete second item in the list

You want to purchase a "2010 Kia Rio" Abbreviation: "10KR" Finalprice: 10800.0

You want to purchase a "2004 Honda Civic" Abbreviation: "04HC" Finalprice: 6480.0

You want to purchase a "2004 Honda Civic" Abbreviation: "04HC" Finalprice: 6480.0

You want to purchase a "2010 Chevrolet Cobalt" Abbreviation: "10CC" Finalprice: 10800.0

You want to purchase a "2000 Honda Accord" Abbreviation: "00HA" Finalprice: 3240.0

You want to purchase a "2009 Suburu Forester" Abbreviation: "09SF" Finalprice: 23760.0

You want to purchase a "2011 Checrolet Malibu" Abbreviation: "11CM" Finalprice: 23760.0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!