Player object – Java

What it is: 

This is a Player object which I created to use with various programs I have created or will create at the minute its fairly basic as it only has a name, score and a toString method.

Code:

public class Player
{
   private String name;
   private int score;

   public Player()
   {

   }//Constructor

   public void setName(String pName)
   {
      name = pName;
   }//setName

   public String getName()
   {
      return name;
   }//getName

   public void setScore(int pScoreIncrease)
   {
      score += pScoreIncrease;
   }//setScore

   public int getScore()
   {
      return score;
   }//getScore

   public String toString()
   {
      return "Players Name: " + this.name  + "\nScore: " + this.score;
   }//toString
}//class

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s