My BattleShip game will not compile correctly.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: My BattleShip game will not compile correctly.

  1. #1
    Join Date
    Mar 2006
    Posts
    37

    My BattleShip game will not compile correctly.

    I have two classes. The application Starter is Called StartBattleShip. My Second Class is BattleShip. When I try to complie StartBattleShip I get two errors. The They both say they cannot find symbol , symbol : class BattleShip.

    I have tried just about everything I could think of. I have typed in the command prompt set classpath = . That didn't even help. Here is the Code.


    Code:
    public class StartBattleShip
    {
    	public static void main(String[] Args)
    	{
    		BattleShip play = new BattleShip();
    		int[] locations = {2,3,4};
    		play.setLocationCells(locations);
    		String userGuess = "2";
    		String result = play.checkGuess(userGuess);
    	}
    }
    Code:
    class BattleShip
    {
    	int[] locationCells;
    	int numberOfHits = 0;
    	
    	public void setLocationCells(int[] locs)
    	{
    		locationCells = locs;
    	}
    	
    	public String checkGuess(String stringGuess)
    	{
    		int guess = Integer.parseInt(stringGuess);
    		String result = "miss";
    		for(int cells : locationCells)
    		{
    			if(guess == cells)
    			{
    				result = "hit";
    				numberOfHits++;
    				break;
    			}
    		}
    		
    		if(numberOfHits == locationCells.length)
    		{
    			result = "Kill" ;
    		}
    		
    		System.out.println(result);
    		return result;
    	}
    }
    Any help would be appreciated. I am just too frustrated. I am sure it is something very simple. This is just the begining. I plan to expand it but for now I am trying to just get the basic to work.
    Last edited by javatier; 04-10-2006 at 07:10 PM.

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Look at your declaration (the first line) of your Battleship class. Is something missing?

    Do you have your CLASSPATH defined properly? (is this a problem you've had, before?)

  3. #3
    Join Date
    Mar 2006
    Posts
    37
    No I have not had this problem before. I did place a public infront of the
    class BattleShip decelaration. I happened to notice that also after I posted but it still comes up with the same errors.

  4. #4
    Join Date
    Mar 2006
    Posts
    37

    Got it.

    I got it to compile finally. I went to my enviornment variables and added a new variable classpath and set the value to H:\Apps; which is where all my java applications are stored. Thanks for the help nspils.

Similar Threads

  1. Replies: 3
    Last Post: 11-17-2005, 02:48 PM
  2. Replies: 3
    Last Post: 03-08-2005, 11:24 PM
  3. BattleShip the game
    By brian molokov in forum .NET
    Replies: 1
    Last Post: 09-18-2001, 10:25 PM
  4. Framework of a complex game...
    By AGuy in forum Java
    Replies: 0
    Last Post: 07-31-2000, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center