Answer :
Answer:
the code isnt complete but you get the idea ,just complete it. All the major method and classes have been written but go ahead and see if it works.Do consider giving brainliest if this ans helped you.
Explanation:
class InventoryItem
{
private String name;
private double cost;
private int currqnt;
private int itempur;
private int itemret;
InventoryItem(String name, double cost, int curr, int pur, int ret)
{
this.name=name;
this.cost=cost;
this.currqnt=curr;
this.itempur=pur;
this.itemret=ret;
}
public String getName()
{
return this.name;
}
public double getCost()
{
return this.cost;
}
public int getCurrQnt()
{
return this.currqnt;
}
public int getItemPur()
{
return this.itempur;
}
public int getItemRet()
{
return this.itemret;
}
}
class Customer
{
private String name;
private double balance;
private ArrayList<InventoryItem> purhist;
private ArrayList<InventoryItem> cart;
Customer(String name, double bal, ArrayList<InventoryItem> hist, ArrayList<InventoryItem> cart)
{
this.name=name;
this.balance=bal;
this.purhist=pur;
this.cart=cart;
}
public String getName()
{
return this.name;
}
public double getBalance()
{
return this.balance;
}
public ArrayList<InventoryItem> getPurHist()
{
return this.purhist;
}
public ArrayList<InventoryItem> getCart()
{
return this.cart;
}
public void setPurHist(ArrayList<InventoryItem> it)
{
for(InventoryItem in: this.cart)
{
this.purhist.add(in);
}
this.setCart(null,0);
}
public void setCart(ArrayList<InventoryItem> it, int i)
{
if(it==null)
this.cart=null;
int j=0;
for(InventoryItem in: it)
{
if(i==j)
{
if(this.getBalance()>=in.getCost())
{
this.cart.add(in);
}
}
j++;
}
}
}
class Purchasing
{
public void addItem(ArrayList<InventoryItem> it, Customer c)
{
System.out.println("inventory list is, x to leave");
int i=0;
for(InventoryList inv: it)
{
System.out.println((i+1)+": "+inv.getName()+" "+inv.getCost()+" "+inv.getCurrQnt());
i++;
}
int choice = scr.nextInt();
c.setCart(it, choice-1);
}
public void removeItem(ArrayList<InventoryItem> it, Customer c)
{
System.out.println("inventory list is, x to leave");
int i=0;
for(InventoryList inv: it)
{
System.out.println((i+1)+": "+inv.getName()+" "+inv.getCost()+" "+inv.getCurrQnt());
i++;
}
int choice = scr.nextInt();
it.remove(choice);
}
public void purchaseItem(InventoryItem it, Customer c)
{
c.setPurHist();
}
public void returnItem(InventoryItem it, Customer c)
{
System.out.println("purchase history list is, x to leave");
int i=0;
for(InventoryList inv: c.getPurHist())
{
System.out.println((i+1)+": "+inv.getName()+" "+inv.getCost()+" "+inv.getCurrQnt());
i++;
}
int choice = scr.nextInt();
c.getPurHist().remove(choice);
}
public static void main(String[] args)
{
Scanner scr=new Scanner(System.in);
ArrayList<InventoryItem> inven = new ArrayList<InventoryItem>();
ArrayList<Customer>L cust = new ArrayList<Customer>();
System.out.println("Enter your name");
String name=scr.nextLine();
Customer obj=null;
for(Customer c: cust)
{
if(c.getName().equals(name))
{
obj = new Customer(c.getName(), c.getBalance(), c.getPurHist(), c.getCart());
break;
}
}
if(obj==null)
{
obj = new Customer(name, 0.0, null, null);
}
System.out.println("Enter choice");
System.out.println("a - add an item");
System.out.println("b - remove an item");
System.out.println("c - purchase items");
System.out.println("d - return an item");
char choice = scr.nextChar();
switch(choice)
{
case 'a':
addItem();
break;
case 'b':
removeItem();
break;
case 'c':
purchaseItem();
break;
case 'd':
returnItem();
break;
}
}
}