Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in

Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList list .

Program should work for input file containing info for any number of cars. (You should not assume that it will always be seven lines in the input file). Use notepad to create input file "inData.txt". File should be stored in the same folder where all files from BlueJ for this program are located.

Class Car describes one car object and has variables vin, make , model of String type, cost of type double, and year of int type. Variable vin is vehicle identification number and consist of digits and letters . In addition, class Car has methods:

public double getCost() // returns cars cost

public String getMake() // returns cars make

public boolean isExpensive() // returns true if car has cost above 30000 and false //otherwise

public boolean isAntique() // returns true if cars year is before 1968, and false // otherwise

public String toString() // returns string with all cars data in one line // separated by tabs.

Design class CarList that has instance variable list of ArrayList type. Variable list is initialized in the constructor by reading data for each car from an input file. Each line of input file "inData.txt" has vin, make, model, cost, and year data in this order, and separated by a space. The data for the first five cars in the input file should be as follows:

1234567CS2 Subaru Impreza 27000 2018

1233219CS2 Toyota Camry 31000 2010

9876543CS2 Ford Mustang 55000 1966

3456789CS2 Toyota Tercel 20000 2004

4567890CS2 Crysler Royal 11000 1938

Class CarList also has the following methods:

public void printList() // Prints title followed by list of all cars (each row has data //for one car)

public void printExpensiveCars() //Prints "List of expensive cars:" followed by // data for each expensive car

public Car cheapestCar() // Method returns Car object with lowest cost

. public int countCarsWithMake(String make) // Method accepts a make and // returns count of cars with given make.

public ArrayList antiqueCarList () // Returns ArrayList of all antique //cars from the list.

The last three methods just return the specified data type. Do not print anything within those methods. Class TestCarList will have main method. In it, instantiate an object from CarList class and use it to invoke each of the five methods from CarList class.

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

Step: 3

blur-text-image

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 Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions

Question

5. Benchmark current training practices.

Answered: 1 week ago