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:错误:类、接口或枚举期望的Dice2 myDice2;^ RecordDice.java:10:错误:类、接口或枚举预期的myDice2 =新的Dice();^2错误
出口代码:1
当我试图用上述两个错误编译程序时。不好意思,我只是一个新手,很长的帖子和业余代码。任何帮助都将不胜感激。
发布于 2013-11-19 10:24:59
在java中,您必须将字段声明为中的一个类,不能在外部对它们进行分层处理
public class RecordDice {
public Dice2 myDice2 = new Dice();
似乎你的遗产是向后的。如果没有实际看到Dice
和Dice2
的类声明,我就不能确定,但是命名约定表明Dice2
继承了Dice
public class RecordDice {
public Dice myDice2 = new Dice2();
发布于 2013-11-19 10:25:00
将Dice2
更改为Dice
。我假设在某个地方有,一个Dice
类,而Dice
没有 extends
Dice2
类。否则,请张贴Dice
和Dice2
类的完整代码。我的意思是改变
Dice2 myDice2;
myDice2 = new Dice();
至
Dice myDice2;
myDice2 = new Dice();
甚至更好
Dice myDice2 = new Dice();
发布于 2013-11-19 10:24:50
如果Dice
不extends
Dice2
,则编译时出错。
Dice2 myDice2 = new Dice2();// This is right.
Dice2 myDice2 = new Dice();// This is wrong
https://stackoverflow.com/questions/20079098
复制相似问题