Hi! I'm sure this is a glaring error but I'm not seeing it. :-) Here's my code, followed by the error messages. Thanks in advance!
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 a number between 0 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 guessed " + guessp1);
guessp2 = p2.number;
System.out.println("Player two guessed " + guessp2);
guessp3 = p3.number;
System.out.println("Player three guessed" + 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("Players will have to try again.");
}
}
}
}
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();
}
}
C:\>javac GameLauncher.java
GameLauncher.java:1: class GuessGame is public, should be declared in a file nam
ed GuessGame.java
public class GuessGame {
^
GameLauncher.java:65: class Player is public, should be declared in a file named
Player.java
public class Player {
^
GameLauncher.java:41: incompatible types
found : int
required: boolean
if (guessp2 = targetNumber) {
^
GameLauncher.java:44: incompatible types
found : int
required: boolean
if (guessp3 = targetNumber) {
^
4 errors