我所应该做的事:调用Java中的方法和返回啤酒成本
添加一些必要的语句到
printOrderCost()
方法在 主类,以这种方法计算并打印的 总成本订单中的所有啤酒项目。 (此方法调用getCost()
方法 每个啤酒项,累积全部getCost()
值的总和,然后打印的总和 - 所有啤酒对象的总成本。)
代码:
public static void printOrderCost(Beer[] order)
{
double totalCost;
int count;
}
}
public double getCost()
{
double cost;
cost = quantity * itemCost;
return (cost);
}
public String toString() // not necessary to format the output
{
String s;
s = brand + " ";
s += quantity + " " ;
s += itemCost + " ";
s += getCost();
return s;
}
输出:
Bud 5 3.0 15.0
Canadian 5 1.0 5.0
Blue 3 2.0 6.0
White Seal 4 1.0 4.0
Bud Light 1 2.0 2.0
1),看它是否工作,编写代码来测试它。 2)调用'toString()'中的方法,只需调用它。让我们看看你想出了什么。 –
不要删除你的问题后,它已被回答... –