Andrew Bayliss

Greenhorn
+ Follow
since Jan 15, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Andrew Bayliss

Thanks to Ernest, Kathy & Joel for your answers. I was able to fix the issue with your help. Such a stupid syntax mistake caused my error.
20 years ago
Ok Tried to compile all 3 files and received following errors
F:\java\scripts\guessgame>javac *.java
Player.java:1: 'class' or 'interface' expected
Public class Player {
^
Player.java:5: 'class' or 'interface' expected
public void guess() {
^
Player.java:9: 'class' or 'interface' expected
}
^
Player.java:11: 'class' or 'interface' expected
^
GuessGame.java:24: cannot resolve symbol
symbol : method guess ()
location: class Player
p1.guess();
^
GuessGame.java:25: cannot resolve symbol
symbol : method method ()
location: class Player
p2.method();
^
GuessGame.java:26: cannot resolve symbol
symbol : method guess ()
location: class Player
p3.guess();
^
7 errors

Any ideas why. I copied your code for the files called Player.java and GameLauncher.java to ensure that no mistyping crept in.
Thanks again for your help.
20 years ago
Thanks to the both of you for your help. I am just in the process of building the other 2 files. When building the class files should I run the GameLauncher.java file first and then Player.java and finally GuessGame.java file to ensure that this file compiles without throwing errors? I am new to java, been building web apps with Perl and ASP for the last few years.
20 years ago
Keep getting the following error 'unable to resolve symbol' error, when I compile code?? Code obtained from HeadFirst Java GuessGame. Can anybody help. Great book .
GuessGame.java:2: cannot resolve symbol
symbol : class Player
location: class GuessGame
Player p1;
^
GuessGame.java:3: cannot resolve symbol
symbol : class Player
location: class GuessGame
Player p2;
^
GuessGame.java:4: cannot resolve symbol
symbol : class Player
location: class GuessGame
Player p3;
^
GuessGame.java:7: cannot resolve symbol
symbol : class Player
location: class GuessGame
p1 = new Player();
^
GuessGame.java:8: cannot resolve symbol
symbol : class Player
location: class GuessGame
p2 = new Player();
^
GuessGame.java:9: cannot resolve symbol
symbol : class Player
location: class GuessGame
p3 = new Player();
Here is the code. Thanks.
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.method();
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("try again");
}
}
}
}
^
20 years ago