A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
File wouldnt compile
Jose Kampilan
Greenhorn
Joined: Aug 04, 2012
Posts: 11
posted
Aug 22, 2012 19:41:52
0
Hi.
I'm currently having a problem with compiling an exercise from Head First: Java. I think all needed classes for the game to run have been compiled except for the main method.
Here's the main method (just copied it directly from the book):
public static void main(String[] args) { int numOfGuesses = 0; GameHelper helper = new GameHelper(); SimpleDotCom theDotCom = new SimpleDotCom(); int randomNum = (int) (Math.random() * 5); int[] locations = {randomNum, randomNum+1, randomNum+2}; theDotCom.setLocationCells(locations); boolean isAlive = true; while(isAlive == true) { String guess = helper.getUserInput("enter a number"); String result = theDotCom.checkYourself(guess); numOfGuesses++; if (result.equals("kill")) { isAlive = false; System.out.println("You took " + numOfGuesses + " guesses"); } } }
And here's the error message from the compiler:
Not sure what i did wrong here.
Carey Brown
Ranch Hand
Joined: Nov 19, 2001
Posts: 159
I like...
posted
Aug 22, 2012 19:45:39
0
Is main() enclosed in a class ?
Jose Kampilan
Greenhorn
Joined: Aug 04, 2012
Posts: 11
posted
Aug 22, 2012 19:49:10
0
Carey Brown wrote:
Is main() enclosed in a class ?
(Sorry. still new with Java.)
oh. i have to put it inside a class first? will try that.
Jose Kampilan
Greenhorn
Joined: Aug 04, 2012
Posts: 11
posted
Aug 22, 2012 19:53:27
0
Huzzah. It worked.
Thanks Carey Brown.
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: File wouldnt compile
Similar Threads
HFJ 2nd - Problem with SimpleDotCom
Help with code
Help With With HeadFirst Java Chap.6
HeadFirst DotComBust... Help?
.equal problem question
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter