Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 131,627 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,100 people online right now. Registration is fast and FREE... Join Now!




I don't think the player class is right?

 
Reply to this topicStart new topic

I don't think the player class is right?, this will not compile please help

learningjava
post 13 Oct, 2008 - 09:26 AM
Post #1


New D.I.C Head

*
Joined: 6 Sep, 2008
Posts: 25

CODE
a game similiar to monopoly. squares
represent continents and oceans.  Each player
spins a spinner that returns a value range 1 to 3.
The player moves that many places around the
board.  If player lands on North America, the
player wins the game and game is over. If
not play passes to next player
public class Player
{
    private String name;
    private int location;
    //sets and gets
    public void setName(String newName){name = newName;}
    public void setLocation(int newLoc){location = newLoc;}
    public String getName(){return name;}
    public int getLocation(){return location;}
}
     public Player(String aName)
     {
         name = aName
      }
//-------------------------------------------------------------------
import javax.swing.JOptionPane;
import java.util.*;
import java.io.*;
public class GlobeTrotter
{
    private Player[] player;
    public static void main(String[] args) throws IOException, ClassNotFoundException{
    // get the destinations
    String[] destinations = new String[12];
    Scanner in = new Scanner(new File("Destinations.txt"));
    int i = 0;
    try{
        while(in.hasNext()){
            destinations[i++] = in.nextLine();
          }//end while in.hasNext
        }
        finally{
        }
        // create the players
        Player player[] = new Player[4];
        player[0].setName("Jerry");
        player[1].setName("Gary");
        player[2].setName("Mary");
        player[3].setName("Larry");
        int id = 0;
        int winner = -1;
        // Loop to play the game
        while(winner<0){
           move();
        //Find out if there was a winner
           if(winner<0){
               id = (++id) % 4;
            }else{
                JOptionPane.showMessageDialog(null, "Congratulations, " + player[id].getName()
                + "you have landed on North America and have won the game!");
            }//end if winner<0
          }//end while
        }
        //----
        private static int move(player[]){
            //spin the spinner
          int steps = ((int)(Math.random() * 100) %3 +1);
          //move the player
          int newLoc=player.move(steps);
          //tell the player where they are
          JOptionPane.showMessageDialog(null, player.getName() + "has rolled a " + steps
            + "and has landed on " + destinations[player.getLocations()]);
            if(newLoc == 0){
                return i;
            }else {
                return -1;
            }//end if newLoc == 0
        }//end Method move
    }//end class


This post has been edited by learningjava: 13 Oct, 2008 - 09:30 AM
User is offlineProfile CardPM

Go to the top of the page


William_Wilson
post 13 Oct, 2008 - 09:46 AM
Post #2


lost in compilation

Group Icon
Joined: 23 Dec, 2005
Posts: 3,951



Thanked 13 times

Dream Kudos: 3275

Expert In: Java, C, Javascript

My Contributions


Looks like a {} error, comments in code.
java

public class Player
{
private String name;
private int location;
//sets and gets
public void setName(String newName){name = newName;}
public void setLocation(int newLoc){location = newLoc;}
public String getName(){return name;}
public int getLocation(){return location;}
//you had a } here
public Player(String aName)
{
name = aName
}
} // and it goes here
User is offlineProfile CardPM

Go to the top of the page

learningjava
post 13 Oct, 2008 - 07:10 PM
Post #3


New D.I.C Head

*
Joined: 6 Sep, 2008
Posts: 25

QUOTE(William_Wilson @ 13 Oct, 2008 - 10:46 AM) *
that still doesn't fix it dude
Looks like a {} error, comments in code.
java

public class Player
{
private String name;
private int location;
//sets and gets
public void setName(String newName){name = newName;}
public void setLocation(int newLoc){location = newLoc;}
public String getName(){return name;}
public int getLocation(){return location;}
//you had a } here
public Player(String aName)
{
name = aName
}
} // and it goes here


User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 05:22AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month