File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Cannot able to get the Output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cannot able to get the Output" Watch "Cannot able to get the Output" New topic

Cannot able to get the Output

Zakir Hosain

Joined: Apr 28, 2007
Posts: 16
I have done this problem from "Head First Java" Chapter 2 - Page 39.
I am not getting the out put.
I am getting the Error Below:

C:\Program Files\Xinox Software\JCreatorV3LE\MyProjects\ClassesandObjects2007\ class GuessGame is public, should be declared in a file named
public class GuessGame
C:\Program Files\Xinox Software\JCreatorV3LE\MyProjects\ClassesandObjects2007\ class Player is public, should be declared in a file named
public class Player
C:\Program Files\Xinox Software\JCreatorV3LE\MyProjects\ClassesandObjects2007\ cannot find symbol
symbol : method prinln(java.lang.String)
location: class
System.out.prinln("Player one guessed" + guessp1);
3 errors


// The coding is below:

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 number between 0 and 9....");

while(true) {
System.out.println("Number to guess is" + targetNumber);


guessp1 = p1.number;
System.out.prinln("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 theee got it right" + p3isright);
System.out.println("Game is over.");

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();



"The Choices We Make, Dictates Our Life To Lead".
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
In java you can have only one public class in a source code file. So remove public class from GuessGame and Player.

Error 3 is a typo. It should have been

I hope this helps

Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11314

Believe it or not, those error messages tell you a lot. You should learn to read them and understand what they mean.

the first two tell you EXACTLY what you need to do: "class GuessGame is public, should be declared in a file named"

in other words: Since the class GuessGame has the 'public' modifier in front of it, you must create a second, separate file called '', and put all the code for THAT class there.

The third error messages says "i have no idea what you are talking about. the specific thing i don't understand is this symbol: prinln(java.lang.String) - oh, and it's some kind of method."

you can then search your code for that symbol (although it also tells you it's line 32). often it's either a typo or you don't have an import correct. in this case, it's pretty obvious you meant println.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: Cannot able to get the Output