我曾經幫助編寫這個程序作爲骰子游戲的模擬,但由於語法/括號的情況,我似乎無法讓它運行。我想我在課堂上組織我的方法時遇到了麻煩。有小費嗎?在模擬骰子游戲的課堂中組織類的方法
import java.util.Random;
public class diceGame
{
private class DiceRoll
{
public static Random rng = new Random();
private int a, b, c; //rolls
public DiceRoll()
{
this.a = rng.nextInt(6);
this.b = rng.nextInt(6);
this.c = rng.nextInt(6);
}
public int getScore()
{
if (a ==6 && b == 6 && c ==6)
{
return 500;
System.out.println("Congratulations! You rolled three 6s! You just earned 500 points!!");
}
else if ((a == 6 && b == 6 && b != c) || (b == 6 && c == 6 && c !=a))
{
return 100;
System.out.println("Congratulations! You rolled two 6s! You just earned 100 points!!");
}
else if ((a == b && b != c) || (b == c && c !=a))
{
return 50;
System.out.println("Congratulations! You just earned 50 points!!");
}
else
{
System.out.println("Nice Try!");
}
}
public String toString()
{
return String.format("Rolled a %d, %d, and %d", a, b, c);
}
}
public static void main (String args[])
{
DiceRoll d;
while (true)
{
d = new DiceRoll();
d.getScore(); // gives you how much to change the player score
}
// finish client
}
}
}
/我嘆了口氣......你能_請_格式化你的代碼嗎?請? –
最後還有一個'}'。 – Koshinae
您應該使用像eclipse這樣的IDE來幫助您修復錯誤。 – user2718281