Question
Version: 7 Last Edited: Jan 26, 2021 Changelog: Version Description 1 Initial Version 2 Updated Class Diagram - Inventory array was incorrectly defined as an
- Version: 7
- Last Edited: Jan 26, 2021
- Changelog:
Version Description 1 Initial Version 2 Updated Class Diagram - Inventory array was incorrectly defined as an int 3 Removed the phrase " and another dynamically allocated array to hold the on hand items for sale" as I removed that requirement when iterating the assignment. 4 Added expected behavior if a duplicate item code is encountered 5 Quantity at input cannot be negative 6 Added Sample Output 7 Changed wording to mirror requirements in sample output. 8 Student to add and process a product called Sweetener(s) - not shown on UML (choose appropriate instance variables based on provided UML )
The Rules
- You MUST use the default package in your assignment so that we can compile and run your program easily.
- ALL data members MUST be declared as private (or protected in the Base class when necessary only).
- 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.
- Never leave compile warnings, address them without suppressing them!
- A solution that does not compile will receive a grade of 0.
Problem Description
In this assignment, you will write efficient Java code to create a basic inventory system for a produce stand using a dynamically allocated data structure to hold the inventory. Your code must handle every single possible condition and never crash. The inventory system will contain three types of items fruit that is purchased from an orchard for resale; vegetables that are purchased from a farm for resale; and preserves that are made by the produce stand themselves for sale. Our program will run with a basic menu that allows the user to add an item to inventory, display to the screen the inventory, buy an item (i.e. add to the quantity of that item) and sell an item (i.e. subtract from the quantity of that item). You are allowed to buy and sell any item (fruit, vegetable or preserve) in the inventory.
Hint: This assignment needs to be tackled in a structured fashion in order for it to be finished quickly. Do not write more than 20-30 lines of code at a time without running your program. Enjoy!!
Requirements
- You must also submit a test plan for the functionality created in this assignment. You can use this test plan as a template.
- Create classes according to the class diagram below. You must adhere to the exact naming, parameters and return values in the class diagram as we will rely on this when marking.
- All data members must never be public. You should make them all private unless they are in a base class AND they are needed in the child classes
- For this assignment, we will limit the inventory array to a maximum of 20 entries
- Notes on the FoodItem class:
Method Additional Information toString Displays the all data members in the class
addItem Reads from the Scanner object passed in and fills the data member fields of the class with valid data; Method returns true if program successfully reads in all fields, otherwise returns false
updateItem Updates the quantity field by amount (note amount could be positive or negative); Method returns true if successful, otherwise returns false Note: itemQuantityInStock field can never be less than 0.
isEqual Method returns true if the itemCode of the object being acted on and the item object parameter are the same value inputCode Reads a valid itemCode from the Scanner object and returns true/false if successful - Notes on the Fruit, Vegetable and Preserve classes, see above table for additional information on the methods with the same name.
- Notes on the Inventory class:
Method Additional Information addItem Adds an item to the inventory array (uses polymorphism to call addItem method in the correct derived FoodItem class for input of the fields of the FoodItem) alreadyExists Returns the index of a FoodItem in the inventory array with the same itemCode as the FoodItem object in the parameter list, else returns -1 updateQuantity Reads in an itemCode to update and quantity to update by and updates that item by the input quantity in the inventory array. The boolean parameter is used to denote whether buying operation (true) or selling operation (false) is occurring. Method returns true/false on whether update was successful or not - Notes on Assign1 class:
Method Additional Information main Main method of the program displayMenu Displays the main menu to the console
- Create a console application that will display the following menu repeatedly until the user selects the exit item. Ensure that your program will never crash nor exit in any other circumstances. The menu should be displayed again if an incorrect value is entered (i.e. a number that is not between 1-5 or any other character) after displaying the error message "Incorrect value entered". The 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: To Exit >
- When '1' is chosen by the user, the user needs to enter additional information. When the user choses to enter a fruit, the program should ask the user which kind and then ask for follow up data as in the following table:
Do you wish to add a fruit(f), vegetable(v), Sweetener(s) or a preserve(p)? If f selected
Enter the code for the item:
Enter the name for the item: Enter the quantity for the item: Enter the cost of the item: Enter the sales price of the item: Enter the name of the orchard supplier: If s selected
Enter the code for the item:
Enter the name for the item: Enter the quantity for the item: Enter the cost of the item: Enter the sales price of the item: Enter the name of the farm supplier: If v selected Enter the code for the item:
Enter the name for the item: Enter the quantity for the item: Enter the cost of the item: Enter the sales price of the item: Enter the name of the farm supplier: If p selected Enter the code for the item:
Enter the name for the item: Enter the quantity for the item: Enter the cost of the item: Enter the sales price of the item: Enter the size of the jar in millilitres: If item code exists Enter the code for the item:
Item code already exists - When '2' is chosen by the user, the content of the inventory array. Starting with the header "Inventory:" and then one item per line in the following format:
For a fruit item Item: price: $ cost: $ orchard supplier: For a vegetable item Item: price: $ cost: $ farm supplier: For a preserve item Item: price: $ cost: $ size: mL - When '3' is chosen by the user, the program will ask the user to enter the code and then the quantity if the code is present in the inventory array. See table for full details:
When code doesn't exist Enter valid item code:
Code not found in inventory... Error...could not buy item When code is found Enter valid item code:
Enter valid quantity to buy:
If quantity is not valid Enter valid item code:
Enter valid quantity to buy:
Invalid quantity... Error...could not buy item - When '4' is chosen by the user, the program will ask the user to enter the code and then the quantity if the code is present in the inventory array. See table for full details:
When code doesn't exist Enter valid item code:
Code not found in inventory... Error...could not sell item When code is found Enter valid item code:
Enter valid quantity to sell:
If quantity is not valid Enter valid item code:
Enter valid quantity to sell:
Invalid quantity... Error...could not sell item If quantity too large Enter valid item code:
Enter valid quantity to sell:
Insufficient stock in inventory... Error...could not sell item - When '5' is chosen by the user, the message "Exiting..." is displayed and the program terminates.
- Modify your code to be able to add another product Sweetener (S) - test it with appropriate data and should appear in the sample output. See sample output.
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