Assign #2 - Inventory Management.html Version Information: Version: 7 Last Edited: Mar 5, 2021 Changelog: Version Description 1 Initial Version 2 Updated Class Diagram - Inventory array was...

1 answer below »
java


Assign #2 - Inventory Management.html Version Information: Version: 7 Last Edited: Mar 5, 2021 Changelog: VersionDescription 1Initial Version 2Updated Class Diagram - Inventory array was incorrectly defined as an int 3Removed the phrase " and another dynamically allocated array to hold the on hand items for sale" as I removed that requirement when iterating the assignment. 4Added expected behaviour if a duplicate item code is encountered 5Quantity at input cannot be negative 6Added Sample Output 7Changed 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 ) You will run a buy transaction and a sell transaction during the demo session 9Expanded requirements to include List and Linkedlist implementation  The Rules  You MUST use the default package in your assignment so that the professor 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 [ArrayList, List and LinkedList] 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: To begin with have your inventory hosted in an ArrayList and then convert that arrayList to a Linkedlist when implementing requirement #9. Use the features of Java Collections Framework - collections, interfaces, methods, Linkedlist etc. 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. You may disregard the green file symbol in the UML. Its an indication that the entity created goes to some sort of storage. Student to add and process a product called Sweetener(s) - not shown on UML (choose appropriate instance variables based on provided UML ). If you did this in Assignment 1, then thats great, continue down here.  You will run a buy transaction and a sell transaction for sweetener during the demo session. 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: MethodAdditional 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. isEqualMethod returns true if the itemCode of the object being acted on and the item object parameter are the same value inputCodeReads 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: MethodAdditional Information addItemAdds 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) alreadyExistsReturns the index of a FoodItem in the inventory array with the same itemCode as the FoodItem object in the parameter list, else returns -1 updateQuantityReads 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: MethodAdditional Information mainMain method of the program displayMenuDisplays 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-6 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: Convert ArrayList to Linkedlist and print it. 6. 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) 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 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 s selectedEnter 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 Food Processing Plant: 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 If an invalid entry is entered, display the message "Invalid entry" and ask again for the same input.  If the user tries to enter a code that already exists, an error message should be displayed, entry should not continue, the program should go back to the main menu and display it again. 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 itemItem:

price: $ cost: $ orchard supplier: For a vegetable itemItem:

price: $ cost: $ farm supplier: For a preserve itemItem:

price: $ cost: $ size: mL Price and cost should be formatted to 2 decimal places. 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 no errors are encountered, the quantity for the item with the specified code is increased by the amount the user specified.   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 selected by the user, the arrayList containing the inventory data is converted to a LinkedList which is then printed out. When '6' is chosen by the user, the message "Exiting..." is displayed and the program terminates. Submission You must submit your solution to Brightspace by the due date and time. The link to submit is shown at the bottom of this page. Your submission should follow the Submission Checklist All source code – i.e. .java files with headers NOTE: I will re-compile and run your program….so all code must be available to the professor 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







Answered 1 days AfterMar 08, 2021

Answer To: Assign #2 - Inventory Management.html Version Information: Version: 7 Last Edited: Mar 5, 2021...

Kshitij answered on Mar 10 2021
161 Votes
Base package:--
Class FoodItem:-
/* Created by IntelliJ IDEA.
* Author: Kshitij Varshney (kshitijvarshne1)
* Date: 09-Mar-21
* Time: 3:45 PM
* File: FoodItem.java
*/
package base_class;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Scanner;
public class FoodItem {
private int itemCode;
private String itemName;
private float itemPrice;
private int quantityInStock;
private float itemCost;
public FoodItem(i
nt itemCode, String itemName, float itemPrice, int
quantityInStock, float itemCost) {
this.itemCode = itemCode;
this.itemName = itemName;
this.itemPrice = itemPrice;
this.quantityInStock = quantityInStock;
this.itemCost = itemCost;
}
public FoodItem() {
this.itemCode = 0;
this.itemName = null;
this.itemPrice = 0;
this.quantityInStock = 0;
this.itemCost = 0;
}
public int getItemCode() {
return itemCode;
}
public void setItemCode(int itemCode) {
this.itemCode = itemCode;
}
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
public float getItemPrice() {
return itemPrice;
}
public void setItemPrice(float itemPrice) {
this.itemPrice = itemPrice;
}
public int getQuantityInStock() {
return quantityInStock;
}
public void setQuantityInStock(int quantityInStock) {
this.quantityInStock = quantityInStock;
}
public float getItemCost() {
return itemCost;
}
public void setItemCost(float itemCost) {
this.itemCost = itemCost;
}
@Override
public String toString() {
return "Item{ " +
"itemCode= " + itemCode +
", itemName= " + itemName + '\'' +
", itemPrice= $" + itemPrice +
", quantityInStock= " + quantityInStock +
", itemCost= $" + itemCost ;
}
public boolean equals(int code) {
return this.getItemCode()==code;
}
public FoodItem addItem(){
Scanner sc= new Scanner(System.in);
System.out.println("Enter the code for the item: ");
int itemCode = sc.nextInt();
System.out.println("Enter the name for the item: ");
String itemName = sc.next();
System.out.println("Enter the quantity for the item: ");
int quantityInStock= sc.nextInt();
System.out.println("Enter the cost of the item: ");
int itemCost = sc.nextInt();
System.out.println("Enter the sell price of the item: ");
int itemPrice= sc.nextInt();
FoodItem obj = new
FoodItem(itemCode,itemName,itemPrice,quantityInStock,itemCost);
return obj;
}
}
Class FruitItem
/* Created by IntelliJ IDEA.
* Author: Kshitij Varshney (kshitijvarshne1)
* Date: 09-Mar-21
* Time: 4:01 PM
* File: FruitItem.java
*/
package base_class;
import java.util.ArrayList;
import java.util.Scanner;
public class FruitItem extends FoodItem {
private String orchardname;
public FruitItem(int itemCode, String itemName, float itemPrice, int
quantityInStock, float itemCost, String orchardname) {
super(itemCode, itemName, itemPrice, quantityInStock, itemCost);
this.orchardname = orchardname;
}
public FruitItem(String orchardname) {
this.orchardname = orchardname;
}
public FruitItem() {
this.orchardname = null;
}
public String getOrchardname() {
return orchardname;
}
public void setOrchardname(String orchardname) {
this.orchardname = orchardname;
}
@Override
public String toString() {
return super.toString()+" orchardname= " + orchardname + " }";
}
public FruitItem addItem(){
FoodItem obj =super.addItem();
System.out.println("Enter the name of the orchard supplier: ");
Scanner sc= new Scanner(System.in);
this.orchardname = sc.nextLine();
FruitItem ftBucket = new
FruitItem(obj.getItemCode(),obj.getItemName(),obj.getItemPrice(),obj.getQuant
ityInStock(),obj.getItemCost(),this.orchardname);
return ftBucket;
}
}
Invertory class
/* Created by IntelliJ IDEA.
* Author: Kshitij Varshney (kshitijvarshne1)
* Date: 09-Mar-21
* Time: 10:25 PM
* File: Inventory.java
*/
package base_class;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;
public class Inventory {
ArrayList godown = new ArrayList();
public Inventory() {
}
public void addItem(FruitItem f) {
godown.add(f);
}
public void addItem(Preserve p) {
godown.add(p);
}
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here