import java.io.*;    // to use InputStreamReader and BufferedReader
import java.util.*;  // to use the StringTokenizer class

/** A program that uses BufferedReader and StringTokenizer to read
  input from the keyboard, tokenize input strings into Employee
  records, then save them into an array of Employee objects; there
  are two types of Employees, Boss and HourluWOrker, which are extended
  from the Employee base class 
  (Oct. 13, 2001)
*/
public class TestEmployee {
  public static void main(String[] args) {

    String line;  // the next input line
    int size;  // max # of Employee objects
    int count; // actual # of Employees input
    StringTokenizer tokens;  // to tokenize next line
    String token;  // the next token of line being processed
    String first, last;  // an Employee's first and last names, respectively
    double wage, hours; // an Employee's wage, and hours (if HourlyWorker)

    // open a character-based input stream to read keyboard input
    BufferedReader in = new BufferedReader (
                 new InputStreamReader(System.in));

    // catch IOException when doing read, then ignore it
    try {
        // prompt the user for # of Employee records to be processed
        System.out.print("Enter an integer for the # of Employee records: ");
        line = in.readLine();
        size = Integer.parseInt(line);

        // create an array to hold Employee objects
        Employee[] arrOfEmployees = new Employee[size];

        // input Employee records from the keyboard
        for (count = 0; count < size; count++) {
          if ((line = in.readLine()) == null) 
            break;  // terminate for loop if no more input

          // create a new StringTokenizer object
          tokens = new StringTokenizer(line);  

          // extract tokens from the current line
          token = tokens.nextToken();  
          if (token.equals("Boss")) {  
            // a Boss Employee record
            first = tokens.nextToken();  
            last = tokens.nextToken();  
            wage = Double.parseDouble(tokens.nextToken());  
            arrOfEmployees[count] = new Boss(first, last, wage);
          }
          else {  
            // assume an HourlyWorker Employee record
            first = tokens.nextToken();  
            last = tokens.nextToken();  
            wage = Double.parseDouble(tokens.nextToken());  
            hours = Double.parseDouble(tokens.nextToken());
            arrOfEmployees[count] = new HourlyWorker(first, last, wage, hours);
          }
        }  // end of the input for loop

        // output all Employee objects saved in array arrOfEmployees
        for (int j = 0; j < count; j++)
          System.out.println(arrOfEmployees[j]);

    } catch (IOException e) {}
  }  // end of main()
}
