Question: 1) Make the following updates to Firm.java You MAY NOT use any of the collection classes (such ArrayList) for this assignment. You must 'roll your

1) Make the following updates to Firm.java

You MAY NOT use any of the collection classes (such ArrayList) for this assignment. You must 'roll your own' arrays.

1) Modify the Firm program such that it expands its use of polymorphism by using an interface calledPayable. You will move pay method from StaffMember into Payable.

2) Modify Firm such that all employees can be given different vacation options depending on their classification. Provide an abstract method in StaffMember called vacation that returns the number of vacation days a person has. Give all Employees a standard number of vacation days (14) using a constant STANDARD_VACATION.

a) Then override the vacation method in the various Employee classes as follows: - Employee: STANDARD_VACATION - Hourly: STANDARD_VACATION - 7 - Executive: STANDARD_VACATION + extraVacation NOTE: You will need to add extraVacation as instance variable to Executive and pass it in as an argument to the constructor. - Volunteer (who are not Employees): 0 b) Call vacation method inside the loop already used by payday method so we see each StaffMembers vacation days.

3) Rewrite the Sorting class so that both sorting algorithms put the values in descending order.

4) Sort the array of StaffMembers based on name using the updated selection OR insertion sort from Sorting.java. Put the sort method in the class that has direct access to the array. Then call the sort in main before calling payday

Hints on Implementation

Constructor for Executive needs to be passed the number of vacation days. No other StaffMember needs to have its constructor updated.

All StaffMembers need to override the vacation method

Use a constant for VACATION_DAYS. This way if the Firm becomes more generous in future, we only need to update one line of code.

StaffMember needs to OVERRIDE compareTo method (we will use names for comparing). This means you need to implement the Comparable interface so the Sorting.java methods work.

THIS IS THE PROGRAM CODE TO MODIFY:

FIRM PROGRAM CODE:

// Demonstrates polymorphism via inheritance.

public class Firm

{ //----------------------------------------------------------------- // Creates a staff of employees for a firm and pays them. //----------------------------------------------------------------- public static void main(String[] args) { Staff personnel = new Staff();

personnel.payday(); } }

SORTING PROGRAM CODE:

// Demonstrates the selection sort and insertion sort algorithms.

public class Sorting { //----------------------------------------------------------------- // Sorts the specified array of objects using the selection // sort algorithm. //----------------------------------------------------------------- public void selectionSort(Comparable[] list) { int min; Comparable temp;

for (int index = 0; index < list.length-1; index++) { min = index; for (int scan = index+1; scan < list.length; scan++) if (list[scan].compareTo((T)list[min]) < 0) min = scan;

// Swap the values temp = list[min]; list[min] = list[index]; list[index] = temp; } }

//----------------------------------------------------------------- // Sorts the specified array of objects using the insertion // sort algorithm. //----------------------------------------------------------------- public void insertionSort (Comparable[] list) { for (int index = 1; index < list.length; index++) { Comparable key = list[index]; int position = index;

// Shift larger values to the right while (position > 0 && key.compareTo((T)list[position-1]) < 0) { list[position] = list[position-1]; position--; }

list[position] = key; } } }

STAFFMEMBER PROGRAM CODE:

// Represents a generic staff member.

abstract public class StaffMember { protected String name; protected String address; protected String phone;

//----------------------------------------------------------------- // Constructor: Sets up this staff member using the specified // information. //----------------------------------------------------------------- public StaffMember(String eName, String eAddress, String ePhone) { name = eName; address = eAddress; phone = ePhone; }

//----------------------------------------------------------------- // Returns a string including the basic employee information. //----------------------------------------------------------------- public String toString() { String result = "Name: " + name + " ";

result += "Address: " + address + " "; result += "Phone: " + phone;

return result; }

//----------------------------------------------------------------- // Derived classes must define the pay method for each type of // employee. //----------------------------------------------------------------- public abstract double pay(); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!