title: Import data in file and use to compute salary
body: <p>Working on a java program that computes salaries for a collection of employees of different types, which is imported from a TXT file.</p>
  
  <p>The program builds and runs successfully if I comment out:</p>
  
  <pre><code>System.out.println("\nAverage Salary for 2014: " + (totalSalary / indexYear2014));
  
  System.out.println("\nAverage Salary for 2015: " + (totalSalary / indexYear2015));
  </code></pre>
  
  <p>However, it does not seem that the data is imported/used at all.</p>
  
  <p>Here is the full code:</p>
  
  <pre><code>package computeemployeesalary;
  
  /**
   *
   * @author Jason Snook
   * Course name: Intermediate Programming (CMIS 242)
   * Assignment: Project 1 - Compute Employee Salary
   */
  
  /**
   * This program computes the salaries of a collection of employees of
   * different types: Employee, Salesman, Executive
   * 
   * Salary for employee is calculated by multiplying monthly salary by 12
   * 
   * Salary for salesman takes the base of employee, and then adds commission,
   * which has a cap of 20000
   * 
   * Salary for executive takes the base of employee, and then adds a bonus
   * in the event that the current stock is more than 100
  */
  
  // Imports
  import java.util.Scanner;
  import java.io.*;
  
  /**
   * This class contains the employee name and monthly salary
   */
  // Employee class
  class Employee {
      // Variable declaration
      String employeeName;
      int monthlySalary = 0;
  
      // Employee constructor
      public Employee(String employeeName, int monthlySalary) {
          this.employeeName = employeeName;
          this.monthlySalary = monthlySalary;
      } // end Employee constructor method
  
      // Calculate employee annual salary
      public int annualSalary() {
          return monthlySalary * 12;
      } // end annualSalary method
  
      // Return employee name and annual salary as String
      @Override // takes advantage from compiler checking
      public String toString() {
          return "Employee Name: " + employeeName +
                  " Salary: $" + monthlySalary;
      } // end toString method
  } // end employee class
  
  /**
   * This class contains the salesman annual sales and extends employee class
   */
  // Salesman subclass, extends Employee class
  class Salesman extends Employee {
      // Variable declaration
      int annualSales = 0;
  
      // Salesman constructor
      public Salesman(String employeeName, int monthlySalary, int annualSales) {
          super(employeeName, monthlySalary);
          this.annualSales = annualSales;
      } // end Salesman constructor method
  
      @Override // takes advantage from compiler checking
      // Computes commission and annual salary
      public int annualSalary() {
          int commission = annualSales * 3 / 100;
  
          // if commission is greater than 25000, then set commission to 25000
          if (commission &gt; 25000) {
              commission = 25000;
          } // emd comission if
  
          return (monthlySalary * 12 + commission);
      } // end annualSalary method
  
      @Override // takes advantage from compiler checking
      // Displays output details as String
      public String toString(){
          return "Employee Name: " + employeeName +
                  " Salary: $" + monthlySalary;
      } // end toString method
  } // end Salesman class
  
  /**
   * This class contains the current stock price and extends employee class
   */
  // Executive subclass, extends Employee class
  class Executive extends Employee {
      // Variable declaration
      int currentStockPrice = 0;
  
      // Executive constructor
      public Executive(String employeeName, 
              int monthlySalary, int currentStockPrice) {
          super(employeeName, monthlySalary);
          this.currentStockPrice = currentStockPrice;
      } // end Executive constructor method
  
      @Override // takes advantage from compiler checking
      // Computes commission and annual salary
      public int annualSalary() {
          int executiveBonus = 0;
  
          // Adds executive bonus if stock is greater than 100
          if(currentStockPrice &gt; 100) {
              executiveBonus = 20000;
          } // end executiveBonus if
  
          return (monthlySalary * 12 + executiveBonus);
      } // end annualSalary method
  
      @Override // takes advantage from compiler checking
      // Displays output details as String
      public String toString() {
          return "Employee Name: " + employeeName +
                  " Salary: $" + monthlySalary;
      } // end toString method
  } // end Executive class
  
  /**
   * This class computes salary based on input file and reports results
   */
  public class ComputeEmployeeSalary {
      // Main method
      public static void main(String[] args) throws IOException {
      // Import text file and compute salary increase
  
          try {
              // Create a File instance
              java.io.File file = new java.io.File("employees.txt");
  
              // Create Scanner object
              Scanner input = new Scanner(file);
  
              // Create arrays for 2014 and 2015
              Employee year2014[] = new Employee[20];
              Employee year2015[] = new Employee[20];
  
              // Create indexes for 2014 and 2015 arrays
              int indexYear2014 = 0, indexYear2015 = 0;
  
              // Read data from a file
              while (input.hasNext()) {
                  String year = input.next();
                  String employeeTitle = input.next();
                  String employeeName = input.next();
                  int monthlySalary = input.nextInt();
  
                  // Action if employee is a regular employee.
                  if (employeeTitle.equalsIgnoreCase("Employee")) {
                      Employee regularEmployee = new Employee(employeeName, 
                              monthlySalary);
  
                      if (year == "2014") {
                          year2014[indexYear2014++] = regularEmployee;
                      } // end 2014 if
  
                      if (year == "2015") {
                          year2015[indexYear2015++] = regularEmployee;
                      } // end 2015 if
                  } // end Employee if
  
                  // Action if employee is a salesman.
                  if (employeeTitle.equalsIgnoreCase("Salesman")){
                      int annualSales = input.nextInt();
  
                      Salesman salesEmployee = new Salesman(employeeName, 
                              monthlySalary, annualSales);
  
                      if (year == "2014") {
                          year2014[indexYear2014++] = salesEmployee;
                      } // end 2014 if
  
                      if (year == "2015") {
                          year2015[indexYear2015++] = salesEmployee;
                      } // end 2015 if
                  } // end Salesman if
  
                  // Action if employee is an executive.
                  if (employeeTitle.equalsIgnoreCase("Executive")) {
                      int currentStockPrice = input.nextInt();
  
                      Executive executiveEmployee = new Executive(employeeName,
                      monthlySalary, currentStockPrice);
  
                      if (year == "2014") {
                          year2014[indexYear2014++] = executiveEmployee;
                      } // end 2014 if
  
                      if (year == "2015") {
                          year2015[indexYear2015++] = executiveEmployee;
                      } // end 2015 if
                  } // end Executive if
  
              }  // end While
  
              // Generate Report for 2014
              int totalSalary = 0;
  
              System.out.println("===== Salary Report for 2014 =====");
  
              for (int i = 0; i &lt; indexYear2014; i++) {
                  System.out.print(year2014[i]);
                  System.out.println(" Annual Salary: " +
                          year2014[i].annualSalary());
              } // end annualSalary 2014 for
  
              for (int i = 0; i &lt; indexYear2014; i++) {
                  totalSalary+= year2014[i].annualSalary();
              } // end totalSalary 2014 for
  
              System.out.println("\nAverage Salary for 2014: " +
                      (totalSalary / indexYear2014));
  
              // Generate Report for 2015
              System.out.println("\n===== Salary Report for 2015 =====");
  
              for (int i = 0; i &lt; indexYear2015; i++) {
                  System.out.print(year2015[i]);
                  System.out.println(" Annual Salary: " +
                          year2015[i].annualSalary());
              } // end annualSalary 2015 for
  
              for (int i = 0; i &lt; indexYear2015; i++) {
                  totalSalary+= year2015[i].annualSalary();
              }  // end totalSalary 2015 for
  
              System.out.println("\nAverage Salary for 2015: " +
                      (totalSalary / indexYear2015));
  
              // Close input file
              input.close();
          } // end try
          catch (IOException i) {
              System.out.println("Error: File Not Found, error code: " + i);
          } // end catch
      } // end main method  
  } // end ComputeEmployeeSalary class
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>