0
這是我的任務,它要求用戶輸入一週中的某一天,它將顯示成本。我希望通過詢問查看者的數量來獲取用戶的更多信息,以便計算票證的總價格。這是我的代碼。計算查看者數量和門票價格
Scanner keyboard = new Scanner(System.in);
// Prompt user to enter the day of the week
System.out.println("Please enter the day of the week:");
day = keyboard.nextLine();
switch (day){
// User can input the days in different ways and the cost will be printed
case "Monday":
case "monday":
case "MONDAY":
System.out.println("The cost of the movie ticket is RM 5.");
break;
case "Tuesday":
case "tuesday":
case "TUESDAY":
System.out.println("The cost of the movie ticket is RM 5.");
break;
case "Wednesday":
case "wednesday":
case "WEDNESDAY":
System.out.println("The cost of the movie ticket is RM 5.");
break;
case "Thursday":
case "thursday":
case "THURSDAY":
System.out.println("The cost of the movie ticket is RM 10.");
break;
case "Friday":
case "friday":
case "FRIDAY":
System.out.println("The cost of the movie ticket is RM 20.");
break;
case "Saturday":
case "saturday":
case "SATURDAY":
System.out.println("The cost of the movie ticket is RM 30.");
break;
case "Sunday":
case "sunday":
case "SUNDAY":
System.out.println("The cost of the movie ticket is RM 20.");
break;
default:
System.out.println("Please make sure you made the correct input.");
keyboard.close();
}
}
}
而你面對的問題是什麼? –
我對這個問題是什麼感到困惑。另外,只需使用toLowerCase(),這樣就不會複製日子。 – kinezu
它不是問題。我想通過計算總價來添加額外的信息 –