【发布时间】:2014-01-04 05:28:11
【问题描述】:
发布的 2 个答案都修复了它。非常感谢,我为它的简单程度感到尴尬。
很抱歉发布这样一个基本问题,感谢您抽出宝贵时间。
从顶部的菜单方法中,我希望调用 2 个不同的方法来完成基于输入的操作。我在任何地方都找不到如何调用 void 方法。
我不知道为什么第二个不起作用,因为我之前使用过类似的东西。
public void CheckOutMenu(ArrayList basket )
{
choice = 0;
while ( choice !=4 ) {
Scanner in = new Scanner ( System.in);
{
switch(in.nextInt()){
//print the number of items in the basket
case 1:
//working
break;
case 2:
//dont know how to call on option 2 the listBasket method
break;
case 3:
//to call the method
//error and wont compile
double totalCost = CalcTotalCost(totalCost = 0);
//printing what the method returns
System.out.print("The total price of your basket is £" );
break;
case 4:
choice = 4;
break;
default:
System.out.println("please enter a whole number that represents you're choice");
}
}
}
}
protected void listBasket(ArrayList basket )
{
//code inside works fine
}
public double CalcTotalCost(double total, ArrayList basket)
{
//code inside works fine
return total;
}
【问题讨论】:
-
两件事:1)请格式化您的代码;它会节省你和其他人的时间。 2)究竟是什么错误?错误消息总是试图告诉你出了什么问题。
标签: java object methods syntax-error bluej