import java.io.*;

/** A program that demonstrates the use of array, character-based stream 
 input, conversion of string to int and to double, and how to catch and 
 ingore IO exception. We assume there is a public java class Employee 
 and subclasses Boss and HourlyWorker */
public class SampleEmployee {
  public static void main(String[] args) {
    // declare an array to hold 3 Employee objects
    Employee[] arrayOfEmployee = new Employee[3];
    double wage;
    int hours;
    String first, last;

    String line;  // to hold the next input line
    // open a character-based input stream (i.e., read from keyboard)
    BufferedReader in = new BufferedReader (
                 new InputStreamReader(System.in));
    // catch IOException when doing read, then ignore it
    try {
      for (int i = 0; i < 2; i++) {
        System.out.print("Enter the first name: "); // prompt
        line = in.readLine(); 
        first = new String(line);

        System.out.print("Enter the last name: "); // prompt
        line = in.readLine(); 
        last = new String(line);
      
        // echo print the input
        System.out.println("name = " + first + " " + last);

        System.out.print("Enter double for wage: "); // prompt
        line = in.readLine(); 
        wage = Double.parseDouble(line); // convert String to double
        System.out.println("double = " + wage); // print input

        System.out.print("Enter an integer: "); // prompt
        line = in.readLine(); 
        hours = Integer.parseInt(line); // convert String to int
        System.out.println("integer = " + hours); // print input
        // create a HourlyWorker object and store it into an array
        arrayOfEmployee[i] = (HourlyWorker) 
                             new HourlyWorker(first, last, wage, hours);
      }
    } catch (IOException e) {}

    // create a Boss object
    Boss boss = new Boss("john", "smith", 800.0); 
    arrayOfEmployee[2] = boss;  // add it to array
    // print objects in the array
    for (int i = 0; i < 3; i++) 
      System.out.println(arrayOfEmployee[i].toString() + ", wage = " +
                         arrayOfEmployee[i].earnings());
  }
}

