title: how to increment an instance variable from a different class?
body: <p>I first set a class for the student's balance depending on how many courses they want to enroll in (more details will be added later). my issue is that I cannot find a way to increment the balance variable in the main class? </p>
  
  <pre><code>public class StudentBalance {
  
      private int balance;
  
  
      public StudentBalance() {
      }
  
      public int getBalance() {
          return balance;
      }
  
      public void setBalance(int balance) {
          this.balance = balance;
      }
  
   }
  public class newTest {
  
  static ArrayList&lt;String&gt; courses = new ArrayList&lt;&gt;();
  private static StudentBalance newBalance = new StudentBalance();
  private static Scanner scanner = new Scanner(System.in);
  
  public static void main(String[] args) {
      boolean start = true;
  
      while (start) {
  
          System.out.println("1 for subjects and 2 to print");
          int choice = scanner.nextInt();
          switch (choice) {
              case 1:
                  courseChoice();
                  break;
              case 2:
                  printStudentsSubject();
                  break;
              default:
                  start = false;
  
          }
  
  
      }
  }
  
  static void printStudentsSubject() {
      System.out.println("Enrolled students subject list: ");
      for (int i = 0; i &lt; courses.size(); i++) {
          System.out.println((i + 1) + ": " + courses.get(i) +
                  "\nBalance: " + newBalance.getBalance()
                  + "\n #################################");
  
  
      }
  }
  </code></pre>
  
  <p>I'm  trying to find a way to add 9000
  each time a course is added to the instance variable Balance.
  than i want to print it but I cant do the first part.</p>
  
  <pre><code>private static void courseChoice() {
  
      int price = 9000;
      System.out.println("ENTER SUBJECT: \n");
      String studentsCourses = scanner.next();
      courses.add(studentsCourses);
      if (courses.size() &gt; 0) {
          newBalance.setBalance(price);
      }
  
  
  }
  </code></pre>
  
  <p>}</p>