title: How to give a value to a setter using another setter in the same class in Java
body: <p>Im new to programming and I was making a text based game; more specifically, the player creation. It will ask you to declare the persons name, gender, and type(teen, young adult, adult, or elder) and it will give the person's age based on the players type, e.g. teen could be 13-17 years old. To do this, I asked the user what the type was and that would be the value for setPlayerType. Then, setAge is suppose to use the information from setPersonType to decide what the age should be using an if statement. To test the program to see if the player creation system works I am having it print out the name, how old the player is, and its gender. However, it always prints that the age is 0, and I have been trying to fix it for almost an hour. Sorry if I'm not using the correct naming conventions, I am still trying to get the hang of setters and getters. I hope I explained this well enough for you guys to understand what I am trying to do. Thank you so much in advance!</p>
  
  <p>This is my tester class:</p>
  
  <pre><code>import javax.swing.JOptionPane;
  
      public class PopulationGameTestDrive {
  
          static Person one = new Person();
  
  
  
          public static void main(String[] args){
  
              one.setName(JOptionPane.showInputDialog("Name your player"));
              one.setGender(JOptionPane.showInputDialog("What is their gender?"));
              one.setPersonType(JOptionPane.showInputDialog("Are they a teen, young adult, adult, or elder?"));
  
              String testName = one.getName();
              String testGender = one.getGender();
              int testAge = one.getAge();
  
              System.out.println(testName + " is " + testAge + " and is a " + testGender);
  
          }
  
      }
  </code></pre>
  
  <p>And this is the Player class:</p>
  
  <pre><code>import java.util.Random;
  
  public class Person {
  
      private String name; //they choose a name
      private String gender; //male or female
      private String personsType; //teen, young adult, adult, or elder
      int numOfKids = 0;
      private int age;
  
      public String getName(){
          return name;
      }
  
      public void setName(String personsName){
          name = personsName;
      }
  
      public String getPersonType(){
          return personsType;
      }
  
      /*
       * setPersonType gives age a value based on whether
       * the player chose teen, young adult, adult, or elder
       */
      public void setPersonType(String personType){
          personsType = personType;
      }
  
  
  
      public String getGender(){
          return gender;
      }
  
      public void setGender(String personsGender){
          gender = personsGender;
      }
  
      public int getAge(){
          return age;
      }
  
      public void setAge(int personsAge){
          if(personsType.equals("teen")){
              Random num = new Random();
              int number = num.nextInt(20);
              if(number &gt; 12 &amp; number &lt; 18){
                  age = number;
              } else if(personsType.equals("young adult")){
                  Random num2 = new Random();
                  int number2 = num2.nextInt(30);
                  if(number2 &gt; 17 &amp; number2 &lt; 31){
                      age = number2;
                  } else if(personsType.equals("adult")){
                      Random num3 = new Random();
                      int number3 = num3.nextInt(50);
                      if(number3 &gt; 30 &amp; number3 &lt; 50){
                          age = number3;
                      }else if(personsType.equals("elder")){
                          Random num4 = new Random();
                          int number4 = num4.nextInt(100);
                          if(number4 &gt; 49 &amp; number4 &lt; 101){
                              age = number4;
                          }
                      }
                  }
              }
          }
          age = personsAge;
      }
  
  }
  </code></pre>