import java.text.DecimalFormat;

public class FarmStore {
    private double bankAccount;
    private double BEEFCOST = 10; // Cost per pound
    private double PORKCOST = 5; // Cost per pound
    private double CHICKENCOST = 2; // Cost per pound
    private double EGGSCOST = 2; // Cost per dozen
    
    protected double beefQuantity; // Quantity in pounds
    protected double porkQuantity; // Quantity in pounds
    protected double chickenQuantity; // Quantity in pounds
    protected double eggQuantity; // Quantity in dozens

    public FarmStore() {
        this.bankAccount = 0;
        this.beefQuantity = 0;
        this.porkQuantity = 0;
        this.chickenQuantity = 0;
        this.eggQuantity = 0;
    }

    public String doTransaction(double beef, double pork, double chicken, double eggs) {
        DecimalFormat df = new DecimalFormat("#.##");

        if (this.beefQuantity < beef) {
            beef = Math.max(this.beefQuantity, 0);
            System.out.println("We are out of beef");
        }
        else {beef = Double.parseDouble(df.format(beef));}
        if (this.porkQuantity < pork) {
            pork = Math.max(this.porkQuantity, 0);
            System.out.println("We are out of pork");
        }
        else {pork = Double.parseDouble(df.format(pork));}
        if (this.chickenQuantity < chicken) {
            chicken = Math.max(this.chickenQuantity, 0);
            System.out.println("We are out of chicken");
        }
        else {chicken = Double.parseDouble(df.format(chicken));}
        if (this.eggQuantity < eggs) {
            eggs = Math.max(this.eggQuantity, 0);
            System.out.println("We are out of eggs");
        }
        else {eggs = Double.parseDouble(df.format(eggs));}

        this.beefQuantity -= beef;
        this.porkQuantity -= pork;
        this.chickenQuantity -= chicken;
        this.eggQuantity -= eggs;

        double cost = beef * BEEFCOST + pork * PORKCOST + chicken * CHICKENCOST + eggs * EGGSCOST;
        cost = Double.parseDouble(df.format(cost));
        this.bankAccount += cost;

        return "Product purchased:\nBeef: " + beef  + " lbs\nPork: " + pork  + " lbs\nChicken: " + chicken  + " lbs\nEggs: " + eggs  + " dozen\nTransaction total: $" + cost;
    }

    public String doResupply(double beef, double pork, double chicken, double eggs) {
        this.beefQuantity += beef;
        this.porkQuantity += pork;
        this.chickenQuantity += chicken;
        this.eggQuantity += eggs;

        return "Product received:\nBeef: " + beef  + " lbs\t\tCurrent Stock: " + beefQuantity + " lbs\nPork: " + pork  
        + " lbs\tCurrent Stock: " + porkQuantity + " lbs\nChicken: " + chicken  + " lbs\tCurrent Stock: " + chickenQuantity 
        + " lbs\nEggs: " + eggs  + " dozen\tCurrent Stock: " + eggQuantity + " dozen\nCurrent Profit: $" + bankAccount;
    }
}