@AlexKost5
Front-end Developer

В чем причина ошибок?

У меня есть следующий код:
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("random number from 0 to 9");

		while(true) {
			System.out.println("number, that you need to guess - " + targetNumber);

			p1.guess();
			p2.guess();
			p3.guess();

			guessp1 = p1.number;
			System.out.println("P1 think, that is " + guessp1);

			guessp2 = p2.number;
			System.out.println("P2 think, that is " + guessp2);

			guessp3 = p3.number;
			System.out.println("P3 think, that is " + 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("Did the first player guess?" + p1isRight);
				System.out.println("Did the second player guess?" + p2isRight);
				System.out.println("Did the third player guess?" + p3isRight);
				System.out.println("Game over.");
				break;
			} else {
				System.out.println("Players should to try again.");
			}
		}
	}
}


Объясните, пожалуйста, почему компилятор выдает ошибки:
GuessGame.java:2: error: cannot find symbol
        Player p1;
        ^
  symbol:   class Player
  location: class GuessGame
GuessGame.java:3: error: cannot find symbol
        Player p2;
        ^
  symbol:   class Player
  location: class GuessGame
GuessGame.java:4: error: cannot find symbol
        Player p3;
        ^
  symbol:   class Player
  location: class GuessGame
GuessGame.java:7: error: cannot find symbol
                p1 = new Player();
                         ^
  symbol:   class Player
  location: class GuessGame
GuessGame.java:8: error: cannot find symbol
                p2 = new Player();
                         ^
  symbol:   class Player
  location: class GuessGame
GuessGame.java:9: error: cannot find symbol
                p3 = new Player();
                         ^
  symbol:   class Player
  location: class GuessGame
6 errors
  • Вопрос задан
  • 356 просмотров
Решения вопроса 1
@red-barbarian
не находит класс Player
возможно нет такого файла. не в этом пакете. и проч.
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
@ZaitsevM
Так и в чем была прорблема?
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы