-3

I'm just getting into java and have a program I need to write with a Class and ClassDriver. I'm supposed to write a program to calculate the total for cheesecake orders (four different kinds) based on price and count. The price given for each is constant. The count is based on user input. There can be only one subTotal method to calculate the subtotal of all the cheesecakes bought.

I'm not sure of the concept I need to do for this and I've been trying to do this for some hours now. Please help as soon as you are able to.

public class CheesecakeOrder {

    private final double PLAIN_CHEESECAKE_PRICE=10.0;
    private final double MARBLE_CHEESECAKE_PRICE=15.0;
    private final double CHOCO_CHIP_CHEESECAKE_PRICE=18.0;
    private final double VARIETY_CHEESECAKE_PRICE=22.0;
    private final double SCHOOL_SHARE_RATE=.12;
    private int plainCheesecakeCount=0;
    private int marbleCheesecakeCount=0;
    private int chocoChipCheesecakeCount=0;
    private int varietyCheesecakeCount=0;

    public double getPLAIN_CHEESECAKE_PRICE()
    {
        return PLAIN_CHEESECAKE_PRICE;
    }

    public double getMARBLE_CHEESECAKE_PRICE()
    {
        return MARBLE_CHEESECAKE_PRICE;
    }

    public double getCHOCO_CHIP_CHEESECAKE_PRICE()
    {
        return CHOCO_CHIP_CHEESECAKE_PRICE;
    }

    public double getVARIETY_CHEESECAKE_PRICE()
    {
        return VARIETY_CHEESECAKE_PRICE;
    }

    public int getPlainCheesecakeCount()
    {
        return plainCheesecakeCount;
    }

    public int getMarbleCheesecakeCount()
    {
        return marbleCheesecakeCount;
    }

    public int getChocoChipCheesecakeCount()
    {
        return chocoChipCheesecakeCount;
    }

    public int getVarietyCheesecakeCount()
    {
        return varietyCheesecakeCount;
    }

    public void setPlainCheesecake(int plainCheesecakeCount)
    {
        this.plainCheesecakeCount=plainCheesecakeCount;
    }

    public void setMarbleCheesecake(int marbleCheesecakeCount)
    {
        this.marbleCheesecakeCount=marbleCheesecakeCount;
    }

    public void setChocoChipCheesecakeCount(int chocoChipCheesecakeCount)
    {
        this.chocoChipCheesecakeCount=chocoChipCheesecakeCount;
    }

    public void setVarietyCheesecakeCount(int varietyCheesecakeCount)
    {
        this.varietyCheesecakeCount=varietyCheesecakeCount;
    }

    public double calculateSubTotal()
    {
        double subTotal;
        subTotal = price * count;
        return subTotal;
    }

    public double calculateDonation()
    {
        double donation;
        donation = (calculateSubTotal()*SCHOOL_SHARE_RATE);
        return donation;
    }

    public double calculateTotal()
    {
        double total;
        total = donation+calculateSubTotal();
        return total;
    }
}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Mr_Traum
  • 11
  • 3

1 Answers1

0

Try using a method that uses variable arguments as its parameter. Find the argument count from the passed variable, then loop through and calculate each one until you reach the end of the collection.

wafflesausage
  • 295
  • 5
  • 14