aspose file tools*
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
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: 9053
    
  12
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with code