【发布时间】:2013-12-03 10:50:08
【问题描述】:
Dice2 myDice2;
myDice2 = new Dice();
公共类 RecordDice {
public static void main (String [] args) {
//Declaring the variables of sides and choice
int i;
int choice;
//Declaring the dice2
Dice2 myDice2;
myDice2 = new Dice();
//Asking the user for input
System.out.println("How many sides do you want your dice to have?");
Scanner sc = new Scanner(System.in);
i = sc.nextInt();
if (i!= 4 )//|| 6|| 8|| 12|| 20|| 100)
{
System.out.println("You have entered an incorrect number");
}
else
{
//myDice2= new Dice(i);
}
//Starting the do statement
do {
System.out.print("1- Reroll the dice");
System.out.print("2- Get the value");
System.out.print("4- Get the minimum");
System.out.print("Please make a choice");
//Gathering the choice for the switch statement
Scanner s= new Scanner (System.in);
choice = s.nextInt();
//Starting the switch statement with varying cases dependent on entry
switch(choice){
case '1':
myDice2.reroll();
System.out.print("1- Reroll the dice");
System.out.print("2- Get the value");
System.out.print("4- Get the minimum");
System.out.print("Please make a choice");
break;
case '2':
myDice2.getValue();
System.out.print("1- Reroll the dice");
System.out.print("2- Get the value");
System.out.print("4- Get the minimum");
System.out.print("Please make a choice");
break;
/*case '3':
myDice.getMaxValue();
System.out.print("1- Reroll the dice");
System.out.print("2- Get the value");
System.out.print("4- Get the minimum");
System.out.print("Please make a choice");
break;
case '4':
myDice.getMinValue();
System.out.print("1- Reroll the dice");
System.out.print("2- Get the value");
System.out.print("4- Get the minimum");
System.out.print("Please make a choice");
*/
default:
System.out.println("Invalid choice entered");
}
//If the choice entered isn't the right value it exits the program
}while( choice < 0);
System.exit(0);
} }
RecordDice.java:9:错误:需要类、接口或枚举 骰子2我的骰子2; ^ RecordDice.java:10:错误:需要类、接口或枚举 myDice2 = 新骰子(); ^ 2 个错误
退出代码:1
当我尝试编译程序时出现上述两个错误。对不起,很长的帖子和业余代码,我只是一个初学者。任何帮助将不胜感激。
【问题讨论】:
-
myDice2 = new Dice();也许应该写成new Dice2()