Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Version Information: Version: 3 Last Edited: June 05, 2022 Changelog: JM_AC_CET-CS Version Description 3 2 1 Requirement to use ArrayList, Sorting Interfaces, Data Persistence.
Version Information: Version: 3 Last Edited: June 05, 2022 Changelog: JM_AC_CET-CS Version Description 3 2 1 Requirement to use ArrayList, Sorting Interfaces, Data Persistence. Your solution will include 4 food items since you created the 4th one in Assignment 1 Added methods that can be added to the classes and sample output Initial Version The Rules 1. You MUST use the default package in your assignment so that we can compile and run your program easily. 2. ALL data members MUST be declared as private (or protected in the Base class when necessary only). 3. Your program must be written using Object Oriented Principles (as outlined in the course notes and previous courses) and with efficiency in mind, you may lose marks for inefficient code. 4. Never leave compile warnings, address them without suppressing them! 5. A solution that does not compile will receive a grade of 0. Problem Description In this assignment, you will modify the solution to Assignment 1. You are to start with your solution to Assignment 1. You must also submit a test plan for the functionality created in this assignment. You must add to your test plan from assignment 1 to include testing the new functionality. All requirements must still behave the same as described in assignment 1 unless overwritten by the requirements here. Requirements 1. Friendly Input: Ensure that your solution accepts spaces in any string input. 2. Efficiency: You will update the inventory data structure in two ways: o Change the inventory declaration in the Inventory class to be an object of ArrayList. Change the insert into the data structure so that the FoodItem objects are in numerical order from smallest to largest by itemCode in the most efficient way possible. Once the inventory structure is sorted, modify your other methods to also make them as efficient as possible. (Note - do NOT use Generic Collection methods yet we will learn to do the coding ourselves first). Do NOT use the built-in binarysearch method - write your own custom-made binary search method. Hint: you can modify and reuse the binary search method you wrote in the earlier labs). You are allowed to use any built-in methods of the ArrayList collection. 3. Saving data: You will add two menu selections to your assignment: o The first will read the contents of a file and add them to the Inventory::inventory ArrayList. (i.e. read). And the second will save the current contents of the Inventory::inventory ArrayList to a file (i.e. write). o File format of both read and write is one line per piece of data, depending on what kind of resource the file is describing, various numbers of lines are required. Many types of FoodItems can be included in the same file. o Each resource will be in the following formats: Fruit Veget f item code item name item code item name Preserve P item code item name quantity of item quantity of item quantity of item item cost item cost item cost item price item price item price name of the orchard farm supplier size of the jar Upon read, if you find a duplicate item Code, you can abort reading in the file. Valid FoodItems before that one should remain in the inventory and an appropriate error message should be displayed. You don't know the name of the file so you cannot hard-code it in your program, you must prompt the user for the filename 4. Search: You will add the ability to view a FoodItem given the item Code. 5. Menu Update: The new menu should look exactly like this: Please select one of the following: 1: Add Item to Inventory 2: Display Current Inventory 3: Buy Item(s) 4: Sell Item(s) 5: Search for Item 6: Save Inventory to File 7: Read Inventory from File 8: To Exit > 6. When '5' is chosen by the user, the program will ask the user to enter the item Code. See table for full details: Enter the code for the item: Code not found in inventory... When code doesn't exist When code is found, display Enter the code for the item: details of the item associated to that code 7. When '6' is chosen by the user, the program will ask the user to enter the filename to save to. See table for full details: Enter the filename to save to: 8. When '7' is chosen by the user, the program will ask the user to enter the filename to read from. See table for full details: Enter the filename to read from: 9. When '8' is chosen by the user, the message "Exiting..." is displayed and the program terminates. Item: 111 Granny Smith Apple 30 price: $0.25 cost: $0.10 orchard supplier: Apple Orchard 10. You can add the following methods to your classes to accomplish the above. If you need any other methods, they must be private helper methods. o Inventory: Updated: public boolean addItem (Scanner scanner, boolean fromFile) Added: public void searchForItem (Scanner scanner) Added: public void saveToFile (Scanner scanner) Added: public void readFromFile (Scanner scanner) o FoodItem: I Updated: public boolean addItem (Scanner scanner, boolean fromFile) Updated: public boolean inputCode (Scanner scanner, boolean fromFile) Added: public int getItemCode () Added: public void outputItem (Formatter writer) o Fruit: Updated: public boolean addItem (Scanner scanner, boolean fromFile) Added: public void outputItem (Formatter writer) Vegetable: Updated: public boolean addItem (Scanner scanner, boolean fromFile) Added: public void outputItem (Formatter writer) o Preserve: Updated: public boolean addItem (Scanner scanner, boolean fromFile) Added: public void outputItem (Formatter writer) 11. You must implement one of the comparison interfaces to compare FoodItems, either Comparator or Comparable. If you are implementing the Comparator interface, you will have a new class, if you are implementing Comparable, you will have a new method in one of your classes. You are permitted to use Collections.sort() but you have to pass to it the comparison object. 12. Remember, you must write EFFICIENT code. The changes above should allow you to improve the efficiency of some of the functionality from Assignment 1, that will be checked, ensure you take full advantage of the changes. Submission [Via Activities menu/Assignments option] You must submit to the assignment link in Brightspace by the due date and time. Your submission should follow the Submission Checklist All source code - i.e. java files with headers NOTE: we will re-compile and run your program.....so all code must be available to us and MUST NOT be in a package. Headers should contain name, student number, assignment number, date, purpose of class Javadoc: A description of each data member and method should be described using Javadoc notation Generate the Javadoc for your solution and upload a zip of the generated folder with a member visibility of Private Test plan In Eclipse, go to Project->Generate Javadoc, select your project and "Create Javadoc for members with Visibility: Private" then click Finish. o Can be in word or pdf format Should contain positive and negative testing (sometimes called happy path and unhappy path) You should indicate which tests your program passes and which one fails Text files: MyInventory2.txt and MyInventory.txt (be sure to include this text files with your submission) Failure to provide any of the above will have an effect on your grade for this assignment. The assignment rubric will be published with the assignment submission link by the end of the week. Marking Scheme Item Data Structure /Syntax and Logic: ArrayList used, Arraylist is used. Add items to inventory and display them Searching: Fully functional custom-built Binary Search method created File I/O, Data Persistence: Write operation: Save inventory to file File I/O, Data Persistence: Read operation: Read inventory from file Comparator or Comparable Sorting done using one of these interfaces of Sorting Function: Comparator class and compare method implemented OR Comparable's compareTo method implemented verify) (check code to Exception handling: Data validation checks implemented Test Plan: Updated, correctly designed and submitted on time Javadoc added in program codes, generated and submitted Assign2Test class Menu works + properly formatted output + code comments, correct names and submission procedures adhered to Total Marks 2 2 3 3 3 2 2 1.5 1.5 20 Sample Output: green is user input Please select one of the following: 1: Add Item to Inventory. 2: Display Current Inventory 3: Buy Item(s) 4: Sell Item(s) 5: Search for Item 6: Save Inventory to File 7: Read Inventory from File 8: To Exit > 2 Inventory: Please select one of the following: 1: Add Item to Inventory 2: Display Current Inventory 3: Buy Item(s) 4: Sell Item(s) 5: Search for Item 6: Save Inventory to File 7: Read Inventory from File 8: To Exit > 5 Enter the code for the item: 123 Code not found in inventory... Please select one of the following: 1: Add Item to Inventory 2: Display Current Inventory 3: Buy Item(s) 4: Sell Item(s) 5: Search for Item 6: Save Inventory to File 7: Read Inventory from File 8: To Exit > 1 Do you wish to add a fruit (f), vegetable (v) or a preserve (p)? f Enter the code for the item: 111 Enter the name for the item: Granny Smith Apple Enter the quantity for the item: 234 Enter the cost of the item: .10 Enter the sales price of the item: .25 Enter the name of the orchard supplier: Niagara Orchard Please select one of the following: 1: Add Item to Inventory 2: Display Current Inventory 3: Buy Item(s) 4: Sell Item(s) 5: Search for Item 6: Save Inventory to File 7: Read Inventory from File 8: To Exit > 1 Do you wish to add a fruit (f), vegetable (v) or a preserve (p)? v Enter the code for the item: 222 Enter the name for the item: Hot House Tomato Enter the quantity for the item: 500 Enter the cost of the item: .15 Enter the sales price of the item: .33 Enter the name of the farm supplier: McDonald's Farm Please select one of the following: 1: Add Item to Inventory 2: Display Current Inventory 3: Buy Item(s) 4: Sell Item(s) 5: Search for Item 6: Save Inventory to File 7: Read Inventory from File 8: To Exit > 1 Do you wish to add a fruit (f), vegetable (v) or a preserve (p)? p Enter the code for the item: 112 Enter the name for the item: Strawberry Jam Enter the quantity for the item: 35 Enter the cost of the item: 2.24 Enter the sales price of the item: 5 Enter the size of the jar in millilitres: 250 Please select one of the following: 1: Add Item to Inventory 2: Display Current Inventory 3: Buy Item(s) 4: Sell Item(s) 5: Search for Item 6: Save Inventory to File 7: Read Inventory from File 8: To Exit > 2 Inventory: Item: 111 Granny Smith Apple 234 price: $0.25 cost: $0.10 orchard supplier: Niagara Orchard Item: 112 Strawberry Jam 35 price: $5.00 cost: $2.24 size: 250mL Item: 222 Hot House Tomato 500 price: $0.33 cost: $0.15 farm supplier: McDonald's Farm Please select one of the following: 1: Add Item to Inventory 2: Display Current Inventory 3: Buy Item(s) 4: Sell Item(s) 5: Search for Item 6: Save Inventory to File 7: Read Inventory from File 8: To Exit > 6 Enter the filename to save to: MyInventory.txt Please select one of the following: 1: Add Item to Inventory 2: Display Current Inventory 3: Buy Item(s) 4: Sell Item(s) 5: Search for Item 6: Save Inventory to File 7: Read Inventory from File 8: To Exit > 7 Enter the filename to read from: MyInventory.txt Item code already exists Error Encountered while reading the file, aborting... Please select one of the following: 1: Add Item to Inventory 2: Display Current Inventory 3: Buy Item(s) 4: Sell Item(s) 5: Search for Item 6: Save Inventory to File 7: Read Inventory from File 8: To Exit > 2 Inventory: Item: 111 Granny Smith Apple 234 price: $0.25 cost: $0.10 orchard supplier: Niagara Orchard Item: 112 Strawberry Jam 35 price: $5.00 cost: $2.24 size: 250mL Item: 222 Hot House Tomato 500 price: $0.33 cost: $0.15 farm supplier: McDonald's Farm Please select one of the following: 1: Add Item to Inventory 2: Display Current Inventory 3: Buy Item(s) 4: Sell Item(s) 5: Search for Item 6: Save Inventory to File 7: Read Inventory from File 8: To Exit > 5 Enter the code for the item: 333 Code not found in inventory... Please select one of the following: 1: Add Item to Inventory 2: Display Current Inventory 3: Buy Item(s) 4: Sell Item(s) 5: Search for Item 6: Save Inventory to File 7: Read Inventory from File 8: To Exit > 5 Enter the code for the item: 112 Item: 112 Strawberry Jam 35 price: $5.00 cost: $2.24 size: 250mL Please select one of the following: 1: Add Item to Inventory 2: Display Current Inventory 3: Buy Item(s) 4: Sell Item(s) 5: Search for Item 6: Save Inventory to File 7: Read Inventory from File 8: To Exit > 7 Enter the filename to read from: NoFile.txt File Not Found, ignoring... Please select one of the following: 1: Add Item to Inventory 2: Display Current Inventory 3: Buy Item(s) 4: Sell Item(s) 5: Search for Item 6: Save Inventory to File 7: Read Inventory from File 8: To Exit > 7 Enter the filename to read from: MyInventory2.txt Please select one of the following: 1: Add Item to Inventory 2: Display Current Inventory 3: Buy Item(s) 4: Sell Item(s) 5: Search for Item 6: Save Inventory to File 7: Read Inventory from File 8: To Exit > 2 Inventory: Item: 100 Barlett Pear 100 price: $0.25 cost: $0.10 orchard supplier: Niagara Orchard Item: 111 Granny Smith Apple 234 price: $0.25 cost: $0.10 orchard supplier: Niagara Orchard Item: 112 Strawberry Jam 35 price: $5.00 cost: $2.24 size: 250mL Item: 212 Raspberry Jam 30 price: $5.50 cost: $2.28 size: 250mL Item: 222 Hot House Tomato 500 price: $0.33 cost: $0.15 farm supplier: McDonald's Farm Item: 311 McIntosh Apple 200 price: $0.25 cost: $0.10 orchard supplier: Niagara Orchard Item: 322 Vine Ripe Tomato 100 price: $0.35 cost: $0.10 farm supplier: McDonald's Farm Please select one of the following: 1: Add Item to Inventory 2: Display Current Inventory 3: Buy Item(s) 4: Sell Item(s) 5: Search for Item 6: Save Inventory to File 7: Read Inventory from File 8: To Exit > 5 Enter the code for the item: 100 Item: 100 Barlett Pear 100 price: $0.25 cost: $0.10 orchard supplier: Niagara Orchard Please select one of the following: 1: Add Item to Inventory 2: Display Current Inventory 3: Buy Item(s) 4: Sell Item(s) 5: Search for Item 6: Save Inventory to File 7: Read Inventory from File 8: To Exit > 8 Exiting...
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