-4
基本上,我嘗試使用交換機,但是當我運行它時,它不會執行我製作的System.out.println。它編譯沒有問題。我不擅長編程,所以請解釋你的答案。交換機沒有按指令執行
import java.util.*;
public class MrCoffee {
public static void main(String[] args) {
String a;
char d = 'y';
Scanner mock = new Scanner(System.in);
System.out.println("Hi, I am Mr.Coffee what is your name?");
a = mock.nextLine();
System.out.println("Thank you " + a + ".");
System.out.println(a + ", do you have a validate rewards card currrently with you?");
String b = ("y"), c = ("n");
System.out.println("If yes enter the letter y. If no, please enter the letter n.");
d = mock.next().charAt(0);
if (d == 'y') {
Scanner low = new Scanner(System.in);
System.out.println("Ok, " + a + " please enter the amount of coffee you have bought today.");
int coffeeam, none, one, two, three, value = 1, value2 = 4;
coffeeam = low.nextInt();
double total = coffeeam * 2.85;
String start = ("Thank you Alexander, you will recieve"), rat = ("The total due amount is");
none = coffeeam/20;
switch (none) {
case 1:
System.out.println("Unfortunately " + a + ", this is not enough to recieve any free coffee.");
break;
case 2:
System.out.println("Unfortunately " + a + ", this is not enough to recieve any free coffee.");
break;
case 3:
System.out.println("Unfortunately " + a + ", this is not enough to recieve any free coffee.");
break;
case 4:
System.out.println("Unfortunately " + a + ", this is not enough to recieve any free coffee.");
break;
case 5:
System.out.println(start + " 1 free coffee. " + rat + " " + total + " dollars.");
break;
case 6:
System.out.println(start + " 1 free coffee. " + rat + " " + total + " dollars.");
break;
case 7:
System.out.println(start + " 1 free coffee. " + rat + " " + total + " dollars.");
break;
case 8:
System.out.println(start + " 1 free coffee. " + rat + " " + total + " dollars.");
break;
case 9:
System.out.println(start + " 2 free coffee. " + rat + " " + total + " dollars.");
break;
case 10:
System.out.println(start + " 2 free coffee. " + rat + " " + total + " dollars.");
break;
case 11:
System.out.println(start + " 2 free coffee. " + rat + " " + total + " dollars.");
break;
case 12:
System.out.println(start + " 2 free coffee. " + rat + " " + total + " dollars.");
break;
case 13:
System.out.println(start + " 2 free coffee. " + rat + " " + total + " dollars.");
break;
case 14:
System.out.println(start + " 2 free coffee. " + rat + " " + total + " dollars.");
break;
case 15:
System.out.println(start + " 2 free coffee. " + rat + " " + total + " dollars.");
break;
case 16:
System.out.println(start + " 3 free coffee. " + rat + " " + total + " dollars.");
break;
case 17:
System.out.println(start + " 3 free coffee. " + rat + " " + total + " dollars.");
break;
case 18:
System.out.println(start + " 3 free coffee. " + rat + " " + total + " dollars.");
break;
case 19:
System.out.println(start + " 3 free coffee. " + rat + " " + total + " dollars.");
break;
case 20:
System.out.println(start + " 3 free coffee. " + rat + " " + total + " dollars.");
break;
}
} else if (d == 'n') {
System.out.println("Sorry " + a + ", since you do not have a rewards card. I will not be able to decide on the number of free coffee you can get.");
System.out.println("I would reccomend that you go to speak with one of our employees to register for a card.");
}
}
}
給出測試用例。 – Pbd
我縮減了代碼,使其更具可讀性(大多數IDE都可以爲你做,所以你應該在將來自己做)。但讓我們從頭開始。你的代碼如何工作?你期望的是什麼軟件?爲什麼? – Pshemo
從你的代碼中,一個人直到他購買了100個coff時纔會得到一個免費的咖啡,我們需要你解釋你正在努力實現的目標。通過這種方式你可以聲明一堆你永遠不會使用的變量。 – TheBakker