Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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 »
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 a
ay was inco
ectly defined as an int
        3        Removed the phrase " and another dynamically allocated a
ay to hold the on hand items for sale" as I removed that requirement when iterating the assignment.
        4        Added expected behaviour if a duplicate item code is encountered
        5        Quantity at input cannot be negative
        6        Added Sample Output
        7        Changed wording to mi
or 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
        9        Expanded 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 [A
ayList, 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 A
ayList and then convert that a
ayList 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 a
ay 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 a
ay – (uses polymorphism to call addItem method in the co
ect derived FoodItem class for input of the fields of the FoodItem)
        alreadyExists        Returns the index of a FoodItem in the inventory a
ay 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 a
ay.
The boolean parameter is used to denote whether buying operation (true) or selling operation (false) is occu
ing.
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 inco
ect value is entered (i.e. a number that is not between 1-6 or any other character) after displaying the e
or message "Inco
ect value entered".
The menu should look exactly like this: 
        
Please select one of the following:
1: Add Item to Inventory
2: Display Cu
ent Inventory
3: Buy Item(s)
4: Sell Item(s)
5: Convert A
ayList 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 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 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 e
or 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 a
ay. 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
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 a
ay. See table for full details:
        When code doesn't exist        
Enter valid item code: Code not found in inventory...
E
or...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...
E
or...could not buy item
When no e
ors 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 a
ay. See table for full details:
        When code doesn't exist        
Enter valid item code: Code not found in inventory...
E
or...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...
E
or...could not sell item
        If quantity too large        
Enter valid item code: Enter valid quantity to sell: Insufficient stock in inventory...
E
or...could not sell item
        When '5' is selected by the user, the a
ayList 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 After Mar 08, 2021

Solution

Kshitij answered on Mar 10 2021
163 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.A
ayList;
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(int 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;
}
@Ove
ide
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.A
ayList;
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;
}
@Ove
ide
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.A
ayList;
import java.util.LinkedList;
import java.util.Scanner;
public class Inventory {
A
ayList godown = new A
ayList();
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