-3

我刚刚进入 java 并且有一个我需要用 Class 和 ClassDriver 编写的程序。我应该编写一个程序来根据价格和数量计算芝士蛋糕订单(四种不同类型)的总数。每个给定的价格是不变的。计数基于用户输入。只有一种 subTotal 方法来计算所有购买的芝士蛋糕的小计。

我不确定我需要为此做的概念,我已经尝试了几个小时。请尽快提供帮助。

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;
    }
}
4

1 回答 1

0

尝试使用使用可变参数作为其参数的方法。从传递的变量中找到参数计数,然后遍历并计算每个参数,直到到达集合的末尾。

于 2015-09-25T18:43:39.733 回答