Answer To: Assign #2 - Inventory Management.html Version Information: Version: 7 Last Edited: Mar 5, 2021...
Kshitij answered on Mar 10 2021
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(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;
}
@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);
}
...