/**
   This program demonstrates parallel arrays.
*/

import java.text.DecimalFormat;
import java.io.*;

public class ParallelArrays
{
   public static void main(String[] args)
                      throws IOException
   {
      final int NUM_EMPLOYEES = 3;
      int[] hours = new int[NUM_EMPLOYEES];
      double[] payRates = new double[NUM_EMPLOYEES];

      // Get the hours worked by each employee.
      getPayData(hours, payRates);

      // Display each employee's gross pay.
      displayGrossPay(hours, payRates);
   }

   /**
      The getPayData method accepts as arguments arrays
      for employees' hours and pay rates. The user enters
      values for these arrays.
      @param hours The array of hours.
      @param payRates The array of pay rates.
   */

   private static void getPayData(int[] hours,
                                  double[] payRates)
                                  throws IOException
   {
      String input;  // To hold user input
      
      // Create the necessary objects for console input.
      InputStreamReader reader =
                 new InputStreamReader(System.in);
      BufferedReader keyboard =
                 new BufferedReader(reader);

      // Get the hours and pay rate for all employees.
      for (int i = 0; i < hours.length; i++)
      {
         // Get the hours worked for an this employee.
         System.out.print("Enter the hours worked by " +
                          "employee #" + (i + 1) + ": ");
         input = keyboard.readLine();
         hours[i] = Integer.parseInt(input);

         // Get the hourly pay rate for this employee.
         System.out.print("Enter the hourly pay rate for " +
                          "employee #" + (i + 1) +
                          ": ");
         input = keyboard.readLine();
         payRates[i] = Double.parseDouble(input);
      }
   }

   /**
      The displayGrossPay method accepts as arguments
      arrays for employees' hours and pay rates. The
      method uses these arrays to calculate and display
      each employee's gross pay.
      @param hours The array of hours.
      @param payRates The array of pay rates.
   */

   private static void displayGrossPay(int[] hours, 
                                       double[] payRates)
   {
      double grossPay;
      DecimalFormat dollar = new DecimalFormat("#,##0.00");

      for (int i = 0; i < hours.length; i++)
      {
         // Calculate the gross pay.
         grossPay = hours[i] * payRates[i];

         // Display the gross pay.
         System.out.println("The gross pay for " +
                            "employee #" + (i + 1) +
                            " is $" +
                            dollar.format(grossPay));
      }
   }
}
