Create a simple java program that reads all the content in a .txt file, the user will enter the filename to be opened. In this case, the file will contain multiple lines of Car details with each line containing a single car detail. Your task is to then create a Car class that models the Make, Colour, type and year manufactured. The Car class should further be able to assign every car created with a unique serial number using a class variable[format is AAAYYYYCXX, AAA is the first 3 letters of the make, YYYY is the year it was manufactured, C is the first letter of the colour and XX is the value provided by the class variable(in form 01) all in upper caps see samples]. Within the driver class add all the cars read from the file onto a stack following LIFO approach and then print details of 2 cars from the stack that are older then 5 years. You are additionally expected to deal with most common exceptions(See samples below) [HINT: DO NOT PROVIDE A PATH BUT RATHER ONLY OPEN THE FILE WITH RELATIVE PATH/FILENAME] Sample run 1: Enter filename: input.txt sample output 1: 2 Cars from the stack: Car Make: Ford Colour: Blue Year Manufactured: 2016 Car Type: Sedan Serial No.: FOR2016B02 Car Make: Toyota Colour: White Year Manufactured: 2001 Car Type: SUV Serial No.: TOY2001W01 NB: input.txt contains "Toyota White SUV 2001" and "Ford Blue Sedan 2016" as the data in different lines [See sample file] Sample run 2: Enter filename: OldCars.txt sample output 2: Invalid file : OldCars.txt could not be found in the current directory NB: OldCars.txt is not a valid file Requested files InClass02.java input.txt 1 2 Toyota White SUV 2001 Ford Blue Sedan 2016 Car.java
Create a simple java program that reads all the content in a .txt file, the user will enter the filename to be opened. In this case, the file will contain multiple lines of Car details with each line containing a single car detail. Your task is to then create a Car class that models the Make, Colour, type and year manufactured. The Car class should further be able to assign every car created with a unique serial number using a class variable[format is AAAYYYYCXX, AAA is the first 3 letters of the make, YYYY is the year it was manufactured, C is the first letter of the colour and XX is the value provided by the class variable(in form 01) all in upper caps see samples]. Within the driver class add all the cars read from the file onto a stack following LIFO approach and then print details of 2 cars from the stack that are older then 5 years. You are additionally expected to deal with most common exceptions(See samples below)
[HINT: DO NOT PROVIDE A PATH BUT RATHER ONLY OPEN THE FILE WITH RELATIVE PATH/FILENAME]
Sample run 1:
Enter filename: input.txt
sample output 1:
2 Cars from the stack:
Car Make: Ford
Colour: Blue
Year Manufactured: 2016
Car Type: Sedan
Serial No.: FOR2016B02
Car Make: Toyota
Colour: White
Year Manufactured: 2001
Car Type: SUV
Serial No.: TOY2001W01
NB: input.txt contains "Toyota White SUV 2001" and "Ford Blue Sedan 2016" as the data in different lines [See sample file]
Sample run 2:
Enter filename: OldCars.txt
sample output 2:
Invalid file : OldCars.txt could not be found in the current directory
NB: OldCars.txt is not a valid file
Requested files
InClass02.java
input.txt
Car.java
Step by step
Solved in 2 steps with 1 images