wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Help with code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with code" Watch "Help with code" New topic
Author

Help with code

Scott Pike
Greenhorn

Joined: Jan 17, 2007
Posts: 12
i'm a dtudent studying java in my off term. I don't know if this is the right place for this, but I wasn't sure where to post this question. if wrong, please tell me where to put it. I try to compile SimpleDotComGame class from my "Head First" book, but I get this error message. SimpleDotComGame.java:1: 'class' or 'interface' expected
public static void main(String [] args) { with a litle arrow under the void word. I don't know what is wrong. Please tell me. Here is my whole code.


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.equal("kill")) {
isAlive = false;
System.out.println("You took " + numbofGuesses + "guesses");
} //close if
} //close while
}// close main
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Originally posted by Scott Pike:
i'm a dtudent studying java in my off term. I don't know if this is the right place for this, but I wasn't sure where to post this question. if wrong, please tell me where to put it. I try to compile SimpleDotComGame class from my "Head First" book, but I get this error message. SimpleDotComGame.java:1: 'class' or 'interface' expected
public static void main(String [] args) { with a litle arrow under the void word. I don't know what is wrong. Please tell me. Here is my whole code.





Welcome to JavaRanch, Scott.

Unlike some other languages, in Java all methods must be inside a class. You need to surround your main method (the code you have posted) with
class SimpleDotComGame {
(Your main() code goes here)
}

However, this is not the correct forum to post this question because this forum is for students studying the CattleDrive Assignments, so I am moving it to the Java in General (beginner) forum.
[ March 10, 2007: Message edited by: Marilyn de Queiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Help with code
 
Similar Threads
.equal problem question
Help With With HeadFirst Java Chap.6
First question in Beginners forum ...
HeadFirst DotComBust... Help?
HFJ 2nd - Problem with SimpleDotCom