Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Based Programming. The CarInventory Class 1) Opens text file cars.txt (the text file is provided containing initial info). 2) Makes an ArrayList of type

Java Based Programming.

The CarInventory Class

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

//Code for Class Car is done

public class Car { // Class fields private String make; private int year; private int price; // Constructor method: public Car(String make, int year, int price) { this.make = make; this.year = year; this.price = price; } // Mutator methods public void setMake(String make) { this.make = make; } public void setYear(int year) { this.year = year; } public void setPrice(int price) { this.price = price; } // Accessor methods public String getMake() { return make; } public int getYear() { return year; } public int getPrice() { return price; } }//END CLASS Car

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_2

Step: 3

blur-text-image_3

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

Relational Database And Transact SQL

Authors: Lucy Scott

1st Edition

1974679985, 978-1974679980

More Books

Students also viewed these Databases questions