# Assignment 7: Inheritance, Vectors, Recursion

Due date: Thursday March 4th, 11:59pm by e-mail

For this assignment you will need to write three programs.

1. Paying Staff Members Example

Write the code for a hierarchy of classes that classifies staff members.

There should be a class `Staff_Member` that serves as the root of the hierarchy.

The rest of the hierarchy should be designed based on the following:

• Because `Volunteer`s do not get paid, they are not considered to be `Employee`s. However, they share many common characteristics with employees, such as `name`, `username`, and tele`phone` number.

• Unlike `Volunteer`s, `Employee`s get paid and they have a `pay_rate` which is the amount that they get on pay day (their salary).

Among `Employee`s two categories have additional features as far as pay is concerned:

• For `Executive`s the pay is the regular salary plus a one time bonus.

• For `Hourly` employees the pay is computed by multiplying the number of hours worked with the pay rate.

Here's the code for a sample tester program and its output. Additional help with problem 1.

2. Write Your Own Vector Class

Define your own `Vector` class then use the `Stack` class defined in class, that relies on `Vector`, to test your code. (No longer import `java.util` in your test program, instead use the `Vector` class you define.)

Your `Vector` objects should be able to respond to the following messages:

`void addElement (Object obj) `
Adds the object to the end of the vector, increasing its size by one.

`boolean contains (Object obj) `
Returns `true` if the object is among the values stored in the vector, or `false` otherwise.

`Object elementAt (int index) `
Returns the object at the specified index position.

`int indexOf (Object obj) `
Returns the index position of the first instance of the object in the vector (if the object is in the vector) or `-1` otherwise.

`int indexOf (Object obj, int index) `
Same as above, but starts the search from the specified index.

`void insertElementAt(Object obj, int index)`
Inserts the object at the specified index position, after shifting down objects at and below the insertion point.

`boolean isEmpty () `
Returns `true` if the vector contains no objects, or `false` otherwise.

`void removeElement (Object obj) `
Removes the first occurrence of the specified object, and then shifts up objects at and below the deletion point.

`void removeElementAt(int index) `
Deletes the object at the specified index position, and then shifts up objects at and below the deletion point.

`void setElementAt (Object obj, int index) `
Replaces the existing object at the specified index position with the specified object.

`int size () `
Returns the number of objects currently stored in the vector. HELP in getting started writing your own `Vector` class.

3. Recursive Calculator

Define a class `Calculator` whose instances will be able to compute (recursively) the nth element of each of the following three recurrences:

1. T(0) = 0
T(n) = 2 * T(n-1) + 1, for n > 0

2. C(1) = 1
C(n) = 1 + C(n / 2), for n even and
C(n) = 1 + C(3 * n + 1), for n odd

3. J(1) = 1
J(n) = 2*J(n/2) - 1, if n > 1 is even, and
J(n) = 2*J((n-1)/2) + 1, if n > 1 is odd
The instance methods should be called `t`, `c`, `j`.

If we ever need to specify more details on this problem we will add a link to the document that provides them here.

If you have any questions please let us know.