Results 1 to 3 of 3
Thread: newbie Game question
- 12-03-2010, 04:26 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 12
- Rep Power
- 0
newbie Game question
Im trying to run this code and all seems fine to me I think it may have an error somewhere that I don't see thats causing a string of errors...or it ...idk. Bless me with your knowledge oh mighty java gurus of the interweb. Any help is greatly appreciated :)
This is the error(s) that command prompt gives me.Java Code:public class BattleShipsTestDrive { public static void main (String[] args) { BattleShip megaship = new BattleShip(); int[] locations = {2,3,4}; megaship.setLocationCells(locations); String userGuess = "2"; String result = megaship.checkYourself(userguess); } } public class BattleShip { int[] locationCells; int numOfHits = 0; public void setLocationCells(int[] locs) { locationCells = locs; } public String checkYourself(String stringGuess); int guess = Integer.parseInt(stringGuess); String result = "miss"; for (int cell : locationCells) { if (guess == cell) { result = "hit"; numOfHits++; break; } } if (numOfHits == locationCells.length) { result = "kill"; } System.out.println(result); return result; } }
I've tinkered with it and I'm stumped thanks in advance! :)Java Code:BattleShip.java:37: illegal start of type for(int cell : locationCells) { ^ BattleShip.java:37: ')' expected for(int cell : locationCells) { ^ BattleShip.java:37: <identifier> expected for(int cell : locationCells) { ^ BattleShip.java:50: illegal start of type if (numOfHits == locationCells.length) { ^ BattleShip.java:50: <identifier> expected if (numOfHits == locationCells.length) { ^ BattleShip.java:50: ';' expected if (numOfHits == locationCells.length) { ^ BattleShip.java:50: illegal start of type if (numOfHits == locationCells.length) { ^ BattleShip.java:50: ';' expected if (numOfHits == locationCells.length) { ^ BattleShip.java:55: <identifier> expected System.out.println(result); ^ BattleShip.java:55: <identifier> expected System.out.println(result); ^ BattleShip.java:57: illegal start of type return result; ^ BattleShip.java:57: ';' expected return result; ^ BattleShip.java:60: class, interface, or enum expected } ^ 13 errors
-
You seem to have method calls dangling in the middle of your class, not in a constructor or method block. You can fix that by putting the method calls in a method where they belong.
- 12-03-2010, 04:48 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
Newbie Loop Question
By MrNiceGuy in forum New To JavaReplies: 4Last Post: 11-14-2010, 02:27 PM -
Newbie question
By MrNiceGuy in forum New To JavaReplies: 8Last Post: 11-12-2010, 05:29 AM -
Newbie Game Experiment - looking for feedback/advice
By papium in forum New To JavaReplies: 8Last Post: 09-23-2010, 12:48 AM -
newbie question
By ronguilmet in forum New To JavaReplies: 2Last Post: 11-16-2009, 02:37 AM -
Newbie question; Vectors
By Kern in forum New To JavaReplies: 7Last Post: 08-03-2008, 06:59 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks