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\GameLauncher.java:1: class GuessGame is public, should be declared in a file named GuessGame.java public class GuessGame ^ C:\Program Files\Xinox Software\JCreatorV3LE\MyProjects\ClassesandObjects2007\GameLauncher.java:74: class Player is public, should be declared in a file named Player.java public class Player ^ C:\Program Files\Xinox Software\JCreatorV3LE\MyProjects\ClassesandObjects2007\GameLauncher.java:32: cannot find symbol symbol : method prinln(java.lang.String) location: class java.io.PrintStream System.out.prinln("Player one guessed" + guessp1); ^ 3 errors
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);
p1.guess(); p2.guess(); p3.guess();
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."); 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(); } }
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 GuessGame.java"
in other words: Since the class GuessGame has the 'public' modifier in front of it, you must create a second, separate file called 'GuessGame.java', 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.
Never ascribe to malice that which can be adequately explained by stupidity.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.