title: Linking two classes
body: <p>sorry to be annoying, I am new to programming and am a bit confused.</p>
  
  <p>How do I link variables of two classes? ie get a variable of one class into another? I'm trying to make an OOP scenario for a game platform where a player can join a game(max of 2 players per game, and pay an associated fee. I;'m trying to get a method which totals these in the Game class but I'm unsure how to add up all the players "amountOwed" into this. I also have to make sure both players are not the same player? any advice GREATLY appreciated! here is what i have so far</p>
  
  <pre><code>import java.time.LocalDate;
  import java.time.Period;
  import java.util.Date;
  
  public class Player {
      private static int instanceCounter = 0;
      private int playerId;
      private String playerName;
      public int birthDay;
      public int birthMonth;
      public int birthYear;
      public int playerAge;
      public double amountOwed;
  
      public Player(int playerId, String playerName, int birthDay, int birthMonth, int birthYear, double amountOwed) {
          this.playerId = playerId;
          this.playerName = playerName;
          this.birthDay = birthDay;
          this.birthMonth = birthMonth;
          this.birthYear = birthYear;
          this.amountOwed = amountOwed;
          instanceCounter++;
      }
  
      public double getAmountOwed() {
          return (amountOwed);
      }
  
      public int calculateAge() {
          LocalDate birthDate = LocalDate.of(birthYear, birthMonth, birthDay);
          LocalDate currentDate = LocalDate.now();
          return playerAge = Period.between(birthDate, currentDate).getYears();
      }
  
      public String printDetails() {
          return (playerName + ", with ID " + playerId + ", is " + playerAge + " and owes the game platform£" + amountOwed);
  
      }
  
      public String payFees() {
          amountOwed = 0;
          return ("Thank you" + playerName + ",you have paid for your game, your balance now stands at £0.00");
      }
  
      public String joinGameChess() {
          if (instanceCounter &lt; 3) {
              return (playerName + " has joined the game.");
          } else {
              return ("Sorry, maximum of 2 players per game");
          }
      }
  
      public String leaveGame() {
          return (playerName + "has left the game.");
      }
  }
  
  public class Game {
      private String gameName;
      private int gameId;
      private int minAge;
      private double fee;
      public double amountOwed;
      public double totalFeesOwed;
  
      public Game(String gameName, int gameId, int minAge, double fee) {
          this.gameId = gameId;
          this.gameName = gameName;
          this.minAge = minAge;
          this.fee = fee;
  
      }
  
      public String printGameDetails() {
          return (gameName + "of ID " + gameId + "has a minimum age of " + minAge + " and costs " + fee + " to play");
      }
  }
  
  public class W07Practical {
      public static void main(String[] args) {
  
          Player marina = new Player(123, "Marina", 15, 4, 1999, 0);
          marina.calculateAge();
          System.out.println(marina.printDetails());
  
          Game chess = new Game("chess", 1234, 19, 2);
  
          marina.getAmountOwed();
          System.out.println(marina.joinGameChess());
  
          Player elise = new Player(153, "elise", 16, 3, 2000, 0);
          System.out.println(elise.joinGameChess());
  
          Player john = new Player(322, "john", 23, 5, 2002, 0);
  
          System.out.println(john.joinGameChess());
  
          System.out.println(john.printDetails());
          System.out.println(elise.printDetails());
      }
  }
  </code></pre>