Question: A working program implemented in Java. As a minimum, it must enable the user to enter data, which must be stored (so it persists between

A working program implemented in Java. As a minimum, it must enable the user to enter data, which must be stored (so it persists between application launches), and it must be able to retrieve the data from storage and present it to the user. Your program code should be self-documenting this means it must use meaningful class, method, and variable names; be clearly commented where necessary and indented to reflect the logic of the program, and control mechanisms such as loops, conditions and data validation routines should be implemented correctly. The submitted project should include 5 records which must be loaded from a saved file when the application is run (Do not include these items in the Java code) The application must allow the user to enter details pertaining to an item in a collection. More than one piece of data must be stored in relation to each item (the name of the item will not suffice). A class must be used to represent the item being stored. o This class must have at least two properties, and a maximum of 5 o There must be at least two different types of properties o It must have a constructor with parameters which must be used o It must have appropriate getters (accessors) o Fields in the class must be private o The class must be in its own file, separate from the rest of the program logic Data must persist between launches of the operation (i.e., it must be stored in a file). o This functionality must be implemented using Serializable. The user must be able to display a list of all items previously added to the collection. The user must be able to choose to exit the application and the application must only terminate when the user chooses to exit (i.e., they should be presented with some form of menu once they have completed any given operation, rather than having to relaunch the application multiple times) You should not set a limit on the number of items that can be stored (you can, however, assume it will be fine to write an entire collection to persistent storage in one go, and should not worry about the performance implications this could have for large collections). The application must not throw exception that is not caught (i.e., crash) if the user were to input a value that is not in the format expected When values are entered by the user in the wrong format, the application will allow them to try again until they get it correct, without losing any data entered so far. A user must be able to remove individual items from the collection. A user must be able to edit individual properties of individual items. Replacement of one object with another does not constitute editing for the purpose of this criteria, therefore, to meet this criterion, the class must have at least one setter (mutator) One of the properties must store an enum value Unit tests must adequately test a fair proportion of the code. The user must be able to sort the items in the collection on one of its properties (for example, for a Blu-ray this could be Title, Rating, Price etc.) This functionality must be implemented using by implementing the Comparable interface. There must not be repeated code in the implementation, nor should there be any particularly large methods1 (i.e., code should be refactored into (small) methods where appropriate) To obtain a first-class mark, in addition to the above functionality One or more of the following elements of functionality will be implemented: The ability to sort on more than one property of the item being stored (using Comparator) The ability to perform operations on the data in the collection (for example a Blu-Ray collection might allow you to calculate the total value of all records based on the purchase price, or identify average release year, or most commonly appearing actress / actor). Allow the user to store more specific versions of the thing stored in the collection with additional attributes implemented using inheritance. For example, if the primary type of item stored in a collection was Car then there could be subclasses of ElectricCar with a property of batteryCapacity, and a subclass of InternalCombustionEngineCar with a property of fuelType I have the answer of the above question but it is not complete please complete the code given below: import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class CollectionApp implements Serializable { // List to store collection items private static final ArrayList collectionList = new ArrayList<>(); public static void main(String[] args) { // Load collection items from file loadCollectionList(); // Scanner to get user input Scanner input = new Scanner(System.in); int option = 0; // Menu loop while (option != 4) { // Print menu System.out.println("1. Add a new item to the collection"); System.out.println("2. Remove an item from the collection"); System.out.println("3. List items in the collection"); System.out.println("4. Exit"); System.out.print("Please enter an option: "); // Get user input option = input.nextInt(); input.nextLine(); switch (option) { case 1: addItem(input); break; case 2: removeItem(input); break; case 3: listItems(); break; case 4: System.out.println("Exiting..."); break; default: System.out.println("Please enter a valid option"); break; } } // Save collection items to file saveCollectionList(); } // Method to add a new item to the collection private static void addItem(Scanner input) { System.out.println("Enter the item information:"); System.out.print("Title: "); String title = input.nextLine(); System.out.print("Description: "); String description = input.nextLine(); System.out.print("Rating (1-5): "); int rating = input.nextInt(); input.nextLine(); System.out.print("Price ($): "); double price = input.nextDouble(); input.nextLine(); System.out.print("Type (Blu-ray, DVD, CD): "); String type = input.nextLine(); // Create new collection item CollectionItem newItem = new CollectionItem(title, description, rating, price, type); // Add to collection list collectionList.add(newItem); System.out.println("Item added!"); } // Method to remove an item from the collection private static void removeItem(Scanner input) { // Check if list is empty if (collectionList.isEmpty()) { System.out.println("Collection is empty!"); return; } // List items listItems(); System.out.print("Please enter the index of the item to remove: "); int index = input.nextInt(); input.nextLine(); // Error checking if (index < 0 || index >= collectionList.size()) { System.out.println("Invalid index!"); return; } // Remove item collectionList.remove(index); System.out.println("Item removed!"); } // Method to list items in the collection private static void listItems() { // Sort collection list Collections.sort(collectionList); // List items for (int i = 0; i < collectionList.size(); i++) { System.out.println(i + ". " + collectionList.get(i)); } } // Method to load collection list from file private static void loadCollectionList() { } // Method to save collection list to file private static void saveCollectionList() { } } // Class to represent a collection item class CollectionItem implements Serializable, Comparable { // Properties private final String title; private final String description; private int rating; private final double price; private final Type type; // Constructor public CollectionItem(String title, String description, int rating, double price, String type) { this.title = title; this.description = description; this.rating = rating; this.price = price; this.type = Type.valueOf(type); } // Getters (accessors) public String getTitle() { return title; } public String getDescription() { return description; } public double getPrice() { return price; } public Type getType() { return type; } // Setter (mutator) public void setRating(int rating) { this.rating = rating; } // To String method @Override public String toString() { return "Title: " + title + " Description: " + description + " Rating: " + rating + " Price: $" + price + " Type: " + type; } // Comparable interface method @Override public int compareTo(CollectionItem o) { return title.compareToIgnoreCase(o.getTitle()); } } // Enum to represent type of collection item enum Type { Blu_ray, DVD, CD }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!