public class GuessGame{
player p1;
player p2;
player p3;
public void startGame(){
p1=new player();
p2=new player();
p3=new player();
int guessp1=0;
int guessp2=0;
int guessp3=0;
boolean p1isRight=false;
boolean p2isRight=false;
boolean p3isRight=false;
int targetNumber=(int) (Math.random()*10);
System.out.println("I'm thinking of number between o and 9...");
while (true){
System.out.println("Number to guess is"+targetNumber);
p1.guess();
p2.guess();
p3.guess();
guessp1=p1.number;
System.out.println("Player one guess"+guessp1);
guessp2=p2.number;
System.out.println("Player one guess"+guessp2);
guessp3=p3.number;
System.out.println("Player one guess"+guessp3);
if(guessp1==targetNumber){
p1isRight=true;
}
if (guessp2==targetNumber){
p2isRight=true;
}
if (guessp3==targetNumber){
p3isRight=true;
}
if(p1isRight||p2isRight||p3isRight){
System.out.println("we have a winner!");
System.out.println("Player one got it right?"+p1isRight);
System.out.println("Player two got it right?"+p2isRight);
System.out.println("Player three got it right?"+p3isRight);
System.out.println("Game Over.");
break; //游戏结实,终止循环
}
else{
//都没有猜到,所以要继续下去
System.out.println("Palyers will have to try again.");
}//结束if/else
}//循环结束
}//方法结束
}//类结束
public class player{
int number=0;//要被猜的饿数字
public void guess(){
number=(int)(Math.random()*10);
System.out.println("I'm guessing"+number);
}
}
public class GameLauncher{
public static void main(String[] args){
GuessGame game=new GuessGame();
game.startGame();
}
}
帮我看看这段代码错误在那里?我用的JCreator调试的提示错误为:
--------------------配置: <--------------------
F:\r-JCreator_pro\MyProjects\firstest\GameLauncher.java:1: 类 GuessGame 是公共的,应在名为 GuessGame.java 的文件中声明
public class GuessGame{
^
F:\r-JCreator_pro\MyProjects\firstest\GameLauncher.java:63: 类 player 是公共的,应在名为 player.java 的文件中声明
public class player{
^
2 错误
处理已完成。
类 GuessGame 是公共的,应在名为 GuessGame.java 的文件中声明
类 player 是公共的,应在名为 player.java 的文件中声明
这段程序应该怎么改??本人刚开始学JAVA不知道怎么修改请懂的朋友说明下!谢谢~