Hi code ranchers, i'm a beginner so i am having a little problem in resolving the cannot find symbol error, i'm learning from headfirst
java so here is the code:
public class GuessGame {
public void startGame(){
Player p1 = new Player(); //player objects
Player p2 = new Player();
Player p3 = new Player();
int guessp1 = 0; //variable to hold players answers
int guessp2 = 0;
int guessp3 = 0;
boolean p1isright = false; //variable to hold value based on players answer
boolean p2isright = false;
boolean p3isright = false;
int targetnumber = (int) (Math.random() * 10); //sets a target number for the players to guess
System.out.println("I am thinking of a number between 0 and 9");
while(true){
System.out.println("Number to guess is .." + targetnumber);
p1.guess(); //calls each players' guess() method.
p2.guess();
p3.guess();
guessp1 = p1.number;
System.out.println("I am guessing " + guessp1); //displays the value of the players guess
guessp2 = p2.number;
System.out.println("I am guessing " + guessp2);
guessp3 = p3.number;
System.out.println("I am guessing " + guessp3);
if(guessp1 == targetnumber){ //checks if the guess is the same as the targey number and if true set the player to true
p1isright = true;
}
if(guessp3 == 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 is over.");
break; // game over, so break out of loop
}
else
//Since no one got it right we must keep going
System.out.println("Players have to try again");
}
}
}
the symbol the compiler can't find is "Player".
Thanks for your anticipated help.