我应该构建一个有 3 个显示窗口的老虎机,每个窗口有 6 个可以显示的选项。
我很困惑在术语 switch 之后使用什么“测试表达式”?然后如何让程序比较 6 个案例或选项(樱桃、橙子、李子、铃铛、甜瓜、酒吧),看看它们是否匹配并提供他们赢得的回报。
import java.util.Random;
import java.util.Scanner;
public class SlotMachine
{
//This is the main method
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
Random random = new Random();
String cont = "y" or "Y";
char answer;
int money = 0;
int totalEntered = 0;
int a;
int n;
int amountWon = 0;
int dbl = money * 2;
int trpl = money * 3;
while (cont.equals("y"))OR (cont.equals("Y"))
{
a = random.nextInt(6);
n = random.nextInt(991) +10;
totalEntered += money;
System.out.println("How much money would you like to bet? ");
money = keyboard.nextInt();
switch (TestExpression????)
{
case 0:
System.out.println("Cherry");
break;
case 1:
System.out.println("Orange");
break;
case 2:
System.out.println("Plum");
break;
case 3:
System.out.println("Bell");
break;
case 4:
System.out.println("Melon");
break;
default:
System.out.println("Bar");
}
if ()
{
System.out.println("You have won $0");
}
else if ()
{
System.out.println("Congratulations, you have won $" + dbl);
amountWon += dbl;
}
else if ()
{
System.out.println("Congratulations, you have won $" + trpl);
amountWon += trpl;
}
System.out.println("Continue? Enter y = yes");
cont = keyboard.nextLine();
}
}
}