Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The Rules 1. You MUST use the default package in your assignment so that we can compile and run your program easily. 2. ALL
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 and addressing any feedback you have received. 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. Efficiency: You will update the inventory data structure in two ways: 2. 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). 3. Saving data: You will add two menu selections to your assignment: O O Do NOT use the built-in binarysearch method - use 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. 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). 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: O Fruit f item code item name Vegetable V item code item name Preserve P item code item name quantity of item quantity of item quantity of item item cost item cost item price item price name of the orchard farm supplier 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 > item cost item price size of the jar Upon read, if you find a duplicate itemCode, 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 itemCode. 5. Menu Update: The new menu should look exactly like this: 6. When '5' is chosen by the user, the program will ask the user to enter the itemCode. See table for full details: When code doesn't exist When code is found, display 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: O 9. When '8' is chosen by the user, the message "Exiting..." is displayed and the program terminates. 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: Enter the code for the item: Code not found in inventory... Enter the code for the item: Item: 111 Granny Smith Apple 30 price: $0.25 cost: $0.10 orchard supplier: Apple Orchard FoodItem: Fruit: 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) 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 Vegetable: Updated: public boolean addItem (Scanner scanner, boolean fromFile) Added: public void outputItem (Formatter writer) 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. 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] Preserve: You must submit to the assignment link in Brightspace by the due date and time. Your submission should follow the Submission Checklist O Added: public void outputItem (Formatter writer) Updated: public boolean addItem (Scanner scanner, boolean fromFile) 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 O O Javadoc: o 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 In Eclipse, go to Project->Generate Javadoc, select your project and "Create Javadoc for members with Visibility: Private" then click Finish. Test plan O o Can be in word or pdf format Should contain positive and negative testing (sometimes called happy path and unhappy path) o You should indicate which tests your program passes and which one fails 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 ArrayList: Marks 3
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