Bookmark Topic Watch Topic
  • New Topic

Problem with writing Program  RSS feed

Craig E. Lewis
Posts: 29
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hey Guys I was writing a program here it is:

view plaincopy to clipboardprint?
public class GuessGame {
Player p1;
Player p2;
Player p3;

public void startGame() {
p1 = new Player();
p2 = new Player();
p2 = 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" + guessp1);


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("We Have a winner.");

} else {
System.out.println ("Players will have to try again.");

I have just started so I am not too good the compiler javac reported that I had 6 errors saying that my Player (p1) (p2) (p3) had no symbol could anyone help
Bear Bibeault
Author and ninkuma
Posts: 66307
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not post the same question more than once.
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!