Question: Java based programming. The Car Class Create class Car with following fields and methods: Class fields: String make; int year; int price; Constructor method: Car(String
Java based programming.
The Car Class
Create class Car with following fields and methods: Class fields: String make; int year; int price; Constructor method: Car(String make, int year, int price) Mutator (setter) methods: setMake(String make) setYear(int year) setPrice(int price) Accessor (getter) methods: String getMake() int getYear() int getPrice() Class fields must be private, and methods must be public.
The CarInventory Class
Then, create application class CarInventory which does the following tasks: 1) Opens text file cars.txt (the text file is provided containing initial info). 2) Makes an ArrayList of type Car 3) Adds elements to the list using all info in the text file (each element includes info of a car in the text file) 4) Shows a menu of 4 options to the user: 1- Enter 1 to display the list 2- Enter 2 to add a new item to the list 3- Enter 3 to delete an item from the list 4- Enter 4 to sort the list 5- Enter 5 to exit If user enters 1, program shows the entire list to the user. Info of each element in a separate line. If user enters 2, it asks for info of a new car (make, year, and price) and adds it to the end of list. If user enters 3, it asks for a number and deletes the element from the list located in that location (1 to delete first element, 2 to delete second element, etc.). If user enters 4, it shows following message: Enter m to sort based on make-year-price, or y to sort based on year-make-price, or p to sort based on price-make-year: Then, it will sort the list based on user input. (For example, if m is entered list will be sorted based on make, and if there are elements with same make, they will be sorted based on year, and if there are elements with same year they will be sorted based on price. You need to define 3 different Comparator classes) If user enters 5, it replaces the current cars.txt file with a new one including all info in the list and then terminates the program execution.
Notes: After finishing each task (menu items 1 to 4), program shows the menu again to the user and waits for the input. Program should manage possible exceptions and provide user with proper messages. The code should be provided with appropriate comments. The output of the program should be clear, nice and neat The displayed list must be aligned correctly as shown in the cars.txt file.
Cars.txt
Toyota 2012 23500
Honda 2010 18850
BMW 2005 9300
Volvo 2015 27250
Toyota 2003 5100
BMW 2005 11450
Honda 2015 19800
Ford 2012 18850
Audi 2017 32500
GMC 2016 28900
Toyota 2012 14750
Ford 2014 17400
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
