aspose file tools*
The moose likes Beginning Java and the fly likes The Code is not compiling,and also tell me what will be the filename for this code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "The Code is not compiling,and also tell me what will be the filename for this code" Watch "The Code is not compiling,and also tell me what will be the filename for this code" New topic
Author

The Code is not compiling,and also tell me what will be the filename for this code

Zakir Hossain
Ranch Hand

Joined: Feb 14, 2006
Posts: 38
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 is 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();
}
}


"The Choices We Make, Dictates Our Life To Lead".
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
If it doesn't compile, there must have been an error message, right? What was it? (What the file name will be you'll see as soon as it does compile :-)

In the future, if you post code of any length, surround it with CODE tags, which you can do by clicking the "CODE" button underneath the text entry area. That way, the code will be displayed formatted.


Ping & DNS - updated with new look and Ping home screen widget
satishkumar janakiraman
Ranch Hand

Joined: May 03, 2004
Posts: 334
Hi,

Change the following in your code
and your class name is


compile and run

bye for now
sat
Sumi Festus
Greenhorn

Joined: Feb 04, 2005
Posts: 14
Hi!!

There can be only one public class so just make the class GameLaucher as public and remove the public keyword from the other 2 classes. Also remember that naming convention is to capitalise the class names. It is a good and the right way of coding.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
... Another thing that you should get used to is putting each (top-level) class in its own file. Making all but one of your classes non-public is a hack. In the long run, whether or not a class is public is a design decision but the reason should not be because one was too lazy to create separate files.


There is no emoticon for what I am feeling!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The Code is not compiling,and also tell me what will be the filename for this code
 
Similar Threads
Very new to java
GuessGame errors
GuessGame Errors From Head First Java
Head First Java Book, Chapter 2
Please Help with Guessing Game (Head First Java)