• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with code

 
Scott Pike
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9066
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic