Question: 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
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 String getModel() // returns cars model
public int getYear() // returns cars year
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 which is of ArrayList
1234567CS2 Subaru Impreza 27000 2018
1233219CS2 Toyota Camry 31000 2004
9876543CS2 Ford Mustang 45000 1960
3456789CS2 Toyota Tercel 20000 2004
4567890CS2 Crysler Royal 21000 1960
Add remaining two non-antique cars of your choice.
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
// complete data for each expensive car
- public Car oldestCar() // Method returns oldest Car (which has smallest year.)
// In case of multiple cars with the same smallest year
// return first such car in the list.
- public int countCarsWithMake(String make) // Method accepts a makel
//and returns count of cars with given make.
- public ArrayList
antiqueExpensiveCarList() // Returns ArrayList
// of all cars from the list that are both antique and expensive.
// The method antiqueExpensiveCarList is extra credit .
The last three methods just return the specified data type. Do not print anything within those methods. Just return the requred result, and have explanation printed at the place where those methods are invoked.
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. If method countCarsWithMake returns zero, report that there are no cars with specified make, otherwise provide count with full sentence.
NOTE: Do not forget to append throws IOException to the constructor of CarList class and main method header in class TestCarList. In addition, you have to provide
import java.io.*;
import java.util.*;
in order to use Scanner and ArrayList classes from Java.
SUBMIT a single word or PDF document named p1_yourLastName_CS152 with the following:
- Your name, class section and project number and date of submission in the upper left corner
- Copy of the code for each class in separate rectangle
- Copy of your input file
- Picture of program run from BlueJ.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
