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 array Car[]list . Capacity of the list is 100. Actual number of cars in the list depends on the input file. Program should work for input file containing info for any number of cars. 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, and 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 CarCollection that has no instance variables and has the following four recursive methods. In each method input parameter n is number of occupied positions in the list.
public String toString(Car[] list, int n) //returns String of all cars in the list
public int countAntique(Car[] list, int n) //returns number of antique cars in the list
public void printExpensive(Car[] list, int n) //prints all expensive cars in the list
public void printCarsWithMake(Car[] list, int n, String make)
//prints all cars of given make from the list
EXTRA CREDIT (1 point)
public Car cheapestCar(Car[] list, int n) //returns the cheapest car in the list.
//In case of multiple cars with the same lowest cost return first such car in the list.
Use input file which you will create in notepad. 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 and add additional three rows of your choice of cars.
1234567CS2 Subaru Impreza 27000 2017
1233219CS2 Toyota Camry 31000 2010
9876543CS2 Ford Mustang 55000 1966
3456789CS2 Toyota Tercel 7000 2009
4567890CS2 Crysler Royal 11000 1938
Class TestCarList will have main method. In it, read cars from the input file and store them in Car[] myCars. Also count cars as you read from an input file in variable int carCount. Invoke each of the four methods, plus extra credit if done, from CarCollection class by passing myCars and carCount .
Do not forget to append throws IOException to the main method header in class TestCarList. In addition, you have to provide
import java.io.*;
import java.util.*;
in order to input data from input file and use Scanner class.
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