title: Text Based Java Game Pass Variables To Another Class
body: <p>I am coding a text based Java game, I have ran into a few issues I cannot get my head around.</p>
  
  <p>My code works along these lines:</p>
  
  <pre><code>        public class main() {
             run initial method for menu
             Player player = new Player(name,1,1,1);
             do{
             game code
             while(running = true)
            }
  
         public class Player() {
             string name
              int age
              int level
              int exp
  
             getName()
             setName() etc etc
            }
  
         public class Train() {
          kill monster
          totalExp = monsters killed
  
          }
  </code></pre>
  
  <p>Now, the problem is, how do I pass the exp gained to my player class which has my get and set methods? The exp is calculated/generated in the Train class, but I need to pass it through to Player so I can use .set/.get and display the updated information in my Main class.</p>
  
  <p>Would adding:</p>
  
  <p>Player player = new Player(name,1,1,1) into the Train class just create a NEW object of Player so I would have two, and assign the exp to the player in Train() but leave the one in Main() alone.</p>
  
  <p>Many thanks for your help.</p>