#I keep getting "substring out of bounds" when using main methods and my "playerAge" method

1 messages ยท Page 1 of 1 (latest)

swift field
#

public class Player {

 private int ID;

private String playerName;
private String playerTeam;
private int playerRating;
private int playerDOB;
private String playerBestPosition;
private boolean achievedPlayerOfTheSeasonAward;

//constructor method

public Player (int i, String n, String t, int r, int d, String p, boolean psa )
{
//asigning values to to feilds
i = ID;
n = playerName;
t = playerTeam;
r = playerRating;
d = playerDOB;
p = playerBestPosition;
psa = achievedPlayerOfTheSeasonAward;
}
// accessor methods
public int getPlayerID ()
{
return ID;
}
public String getPlayerName ()
{
return playerName;
}
public String getPlayerTeam ()
{
return playerTeam;
}
public int getPlayerRating ()
{
return playerRating;
}
public int getPlayerDOB ()
{
return playerDOB;
}
public String getPlayerBestPositon ()
{
return playerBestPosition;
}
public boolean getachievedPlayerOfTheSeasonAward ()
{
return achievedPlayerOfTheSeasonAward;
}

      //calculate a players age
      
      public int playerAge()
      {
         
      String str = String.valueOf(playerDOB);
      str = str.substring(4,7);
      int dob = Integer.parseInt(str);
     LocalDateTime date1 = LocalDateTime.now();
     int year = date1.getYear();
     return year - dob;
     
      }
azure scrollBOT
#

โŒ› This post has been reserved for your question.

Hey @swift field! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

azure scrollBOT
#
public class Player {

    
     private int ID;
   private String playerName;
   private String playerTeam;
   private int playerRating;
   private int playerDOB;
   private String playerBestPosition;
   private boolean achievedPlayerOfTheSeasonAward;
  
    //constructor method
 
   public Player (int i, String n, String t, int r, int d, String p, boolean psa )
   {
       //asigning values to to feilds
       i = ID;
       n = playerName;
       t = playerTeam;
       r = playerRating;
       d = playerDOB;
       p = playerBestPosition;
       psa = achievedPlayerOfTheSeasonAward;
   }
   // accessor methods
        public int getPlayerID ()
        {
            return ID;
        }
         public String getPlayerName ()
        {
            return playerName;
        }
          public String getPlayerTeam ()
        {
            return playerTeam;
        }
        public int getPlayerRating ()
        {
            return playerRating;
        }
        public int getPlayerDOB ()
        {
            return playerDOB;
        }
         public String getPlayerBestPositon ()
        {
            return playerBestPosition;
        }
          public boolean getachievedPlayerOfTheSeasonAward ()
        {
            return achievedPlayerOfTheSeasonAward;
        }
          
 
          //calculate a players age
          
          public int playerAge()
          {
             
          String str = String.valueOf(playerDOB);
          str = str.substring(4,7);
          int dob = Integer.parseInt(str);
         LocalDateTime date1 = LocalDateTime.now();
         int year = date1.getYear();
         return year - dob;
         
          }
short eagle
#

Your constructor is incorrect

#

you are assigning the object variables to the incoming fields, instead of the other way around

azure scrollBOT
#

๐Ÿ’ค Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

swift field
azure scrollBOT
# swift field ahh thanks man๐Ÿ‘Š๐Ÿผ

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.