class GameLauncher{
public static void main(String[] args){
GuessGame Game1 = new GuessGame();
Game1.startGame(p1);
Game1.startGame(p2);
Game1.startGame(p3);
}
}
public class GuessGame {
public Player p1 = new Player();
public Player p2 = new Player();
public Player p3 = new Player();
void startGame(Player p){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
p.guess(n);
}
}
class Player{
private int number;
Player(){
number = (int)Math.random();
}
void guess(int n){
if(number == n){
System.out.println("the correct answer");
}
System.out.println("the wrong answer");
}
}
我的代码有一些错误:Game1.startGame(p1); Game1.startGame(p2); Game1.startGame(p3);
编译器说它找不到p1, p2, p3的符号,但我已经在GuessGame类中初始化了Player
如何修复错误?对不起我的英语不好。
海绵宝宝撒
慕盖茨4494581
蓝山帝景
相关分类