Lab 9:  Inheritance



You will implement three classes: Person, Employee, and Manager. Both Manager and Employee will inherit from Person. The Person class will contain the following instance variables: a name (String), an age (int), and an id (String). The Employee class will provide the additional instance variables: salary (int) and a reference to the manager (Manager) of the employee. The Manager class will have an additional instance variable that is of type ListArray and contains a list of all the Employees that this manager manages.

You will also create a class EmployeeSystem, which will contain the main method of the program. Inside this class you will maintain a list of Person objects in the system. Inside the main method you should firstly ask the user to login to the system by giving his/her id. Then, depending on whether the user is a Manager or a simple Employee, s/he will get a different menu of choices. In particular, an employee will have the choices of:

On the other hand, a manager will have the following options:

The classes Person, Employee and Manager will have to provide a toString() method along with appropriate get methods to access their internal state. The Manager class will also have to provide methods in order to manipulate the internal list of Employees. The classes must provide the appropriate constructors to initialize all of their fields to correct initial values, and call the constructors of their superclasses, as appropriate.

To help you get started, we provide you with a skeleton for EmployeeSystem.java. In it, you will find an instance variable of type ArrayList which holds all the people that exist in the system, and a constructor which populates the list with some people. Some the method calls should give you insight on which methods to provide for some of your classes.   

A sample output of a typical execution of the program is provided here.

Hint: An ArrayList is one of the classes that are provided by the Java standard library. It has functionality similar to that of  a normal array of Objects, but in addition it can automatically grow or shrink as you add or remove objects from it. An ArrayList is polymorphic, i.e., it can operate on objects of different types, therefore, when it returns an object, you must cast the element to the correct object type, as shown in the System.out.println() calls below. Here is an example of using an ArrayList to hold objects of type String.

    ArrayList aList = new ArrayList();
    String msg1 = "hello";
    String msg2 = "world";
    aList.add(msg1);
    aList.add(msg2);
    for (int i=0; i<aList.size(); ++i) {
       System.out.println((String)aList.get(i));
    }
    aList.remove(msg1);
    for (int i=0; i<aList.size(); ++i) {
       System.out.println((String)aList.get(i));
    }

The above code first creates an ArrayList and adds two String objects into it. Then, in a for loop, it goes over the list and prints out each of its elements. By calling remove() we can delete the element that is in the head of the list. So, the final output of the above code is:

    hello
    world
    world

Extra Credit (20 points): Extend the above class hierarchy by adding a President class. President should inherit from Manager and should also have the ability to find the best employee, we will assume that it is the employee with the highest salary, and promote him to a manager. You should make sure that the newly promoted manager is removed from the list of his previous manager. Initially, the new manager should not have any employees under his supervision, but you can add some while the program is running. For simplicity, you may have the president store in his list of immediate employees only the managers.


 
Submission and Grading:

Include your names, slip days, and a comment at the top of your Transformations.java file. Answer the questions below in your header too.

/**
* @author name 1: discussion section time:
* CS account user name:
* Section Unique Number: 
* slip days used on this assignment: ??/4
* total slip days used: ??/6
*
* @author name 2: discussion section time:
* CS account user name:
* Section Unique Number: 
* slip days used on this assignment: ??/4
* total slip days used: ??/6
*
* On our honor, we followed the pair programming rules of splitting
* keyboard time evenly and 80% or more joint development, and we have
* neither read nor copied code, nor have we shown or given our code to
* others.
*
* @version Date
*
*
* Extra Credit attempted (Yes/No):
*
*/

 For this lab, you will turn in a zipped folder containing all the source files. Please make sure that all the files you need to turn in are in this folder BEFORE you zip it.

 You then turnin this .zip file using the turnin program. If you need help goto turnin program help.

 Your program should be internally correct (sound logic) and externally correct (following Java style guideline).