title: How to pass salary data to each salesperson in Java
body: <p>I am having trouble understanding how to get the information in my array to print for a comparison.  I need to compare salesperson[0]'s and salesperson[1]'s total annual compensation and cannot figure out how to pass each salesperson's compensation.  Please help me figure out what I am doing wrong. </p>
  
  <pre><code>import java.util.Scanner;//import tools for scanner useage
  import java.util.InputMismatchException;//import tools for try-catch
  import java.text.DecimalFormat;//format percentages
  
  public class AnnualCompensationCalculator 
  {
  
      //main method begins    
      public static void main(String[] args) 
      {
  
          //create object to assign greeting
          AnnCompGreet myGreeting = new AnnCompGreet();
  
          // call greeting
          myGreeting.displayMessage();
  
          //object to call table
          AnnCompTable myTable = new AnnCompTable();
  
          //object to call formatting for percentages
          DecimalFormat percent = new DecimalFormat("#0%");
  
          //variable for boolean answer to display table
          boolean bool = true;
  
          /**
           * next few lines determine whether or not 
           * to display the compensation table
          */ 
          do 
          {
              try 
              {
                  //ask user if they want to display compensation table
                  System.out.print("Would you like to see compensation table?"
                          + "  Enter: True/False  ");
  
                  //create scanner to obtain bool
                  Scanner answer = new Scanner(System.in);
                  boolean boolAnswer = answer.nextBoolean();
  
                  //this will display the table
                  if (boolAnswer == true) 
                  {
                      myTable.displayTable();
  
                  } //this will display message when table is not displayed
                  else if (boolAnswer == false) 
                  {
                      System.out.println("Then let us continue!");
                  }
  
              } catch (InputMismatchException e) {
                  System.out.println("Invalid input, the table"
                                      + " will not be displayed.");
              }
  
          } while (!bool);
  
          final double salary = 100000.00;//fixed variable
          double numberSales;//hold place of sales variable
          double annualSalary;//hold place of total annual salary
          int people;//used for array to gather salesperson info
  
  
          //create Commission object
          Commission number = new Commission();
  
          //create scanner for sales info
          Scanner keyboard = new Scanner(System.in);
  
          //used to determine how many salespeople will be entered for array
          System.out.print("How many Sales people are you entering? ");
          people = keyboard.nextInt();
  
          //array for sales people information
          String[]SalespersonName = new String[people];
  
          //loops array
          for(int i = 0; i &lt; people; i++)
          {
  
              //requests salesperson's name
              System.out.print("Enter name of salesperson "
                      + "number " + (i+1) + ": ");
              SalespersonName[i] = keyboard.next();
  
              do
              {                    
                  //next two lines used to obtain annual sales
                  System.out.print("Enter " + SalespersonName[i]
                          + "'s annual sales: "
                                      + "$");
                  numberSales = keyboard.nextDouble();
  
                  //set annual sales and commission rate
                  number.set(numberSales, 0.0);
  
  
                  //conditional statements to determin annual sales
                  if (numberSales &lt;= 96000) 
                  {
                      //displays base commission rate
                      System.out.println("Base Commission rate is: 5%.");
  
                      //displays current commission rate
                      System.out.println(SalespersonName[i] + "'s "
                                          + "commission rate is:  "
                                          + percent.format(number.getRate()));
  
                      //displays message for not reaching target sales
                      System.out.println("Sorry you have not reached your "
                                          + "target of $96,000.");
                      //equation to calculate total annual compensation
                      annualSalary = salary + number.getSalesCommission();
  
                      //displays salary with no commissions
                      System.out.printf(SalespersonName[i] 
                                         + "'s annual compensation "
                                          + "is:  $%,.2f \n", annualSalary);
                  }
                  else 
                  {
                      //displays base commission rate
                      System.out.println("Base commission rate is: 5%.");
  
                      //displays current commission rate for salesperson
                      System.out.println(SalespersonName[i] 
                                          + "'s commission rate is "
                                          + percent.format(number.getRate()));
  
                      //displays commissions earned
                      System.out.printf(SalespersonName[i] 
                                         + "'s total commission is: "
                                      + "$%,.2f \n", number.getSalesCommission());
  
                      //equation to calculate total annual compensation
                      annualSalary = salary + number.getSalesCommission();
  
                      //displays total annual compensation
                      System.out.print(SalespersonName[i] 
                              + "'s annual compensation is ");
                      System.out.printf("$%,.2f \n", annualSalary);
                  }
              }while (i == people);
          }     
          for(int i = 0; i &lt; people; i++)
          {
              System.out.println(SalespersonName[i]);          
          }
      }
  }
  </code></pre>