두 답변이 모두 수정 됨으로 게시되었습니다. 고맙습니다. 얼마나 간단한 지 당혹 스럽네요.메서드 호출에서 구문 오류가 발생했습니다.
이런 기본적인 질문을 게시 해 주셔서 죄송하며 시간 내 주셔서 감사합니다.
상단의 메뉴 방법에서 입력을 기반으로 작업을 완료하기 위해 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) 정확히 오류가 무엇입니까? 오류 메시지는 항상 잘못된 것을 알려줍니다. –