Question: JAVA In a company, a permanent staff is entitled for 20 days of annual leave. The staff may carry-forward the annual leave maximum of 5

JAVA

In a company, a permanent staff is entitled for 20 days of annual leave. The staff may carry-forward

the annual leave maximum of 5 days for next year.

Another type of staff is contract staff. A contract staff is entitled 10 days of annual leave. No carry

forward leave for contract staff. However, he/she is granted for additional leave (for next year)

based on the total hours of overtime he/she has worked.

Write Java programs based on the following instructions:

A. Write a class named Staff that represents a record of a staff. The class consists of the

following fields and methods:

Private instance data fields that store:

Staff name

Staff ID

A constant field of annual leave with a default value 20.

The number of leave taken by the staff for this year.

Public constructor:

A constructor with the parameters of staff name and staff ID,

o Set the data to the class accordingly.

Public method:

A mutator method to set the number of leave taken by this staff.

An accessor method to retrieve the number of leave taken by this staff.

An accessor method to retrieve the annual leave assigned for the staff.

A toString method to return the string (text) that contains the staff name

and staff ID.

B. Next, write a class named PermanentStaff that inherits the Staff class. The class

consists of the following fields and methods.

Private instance data field that stores:

The total days of carry-forward leave granted to the staff for next year.

Public constructor:

A constructor with the parameters staff name, staff ID and number of leave

taken.

o Call the superclasss constructor with the parameters: staff name, and

staff ID.

o Call the superclasss respective method to set the leave taken (and pass

the argument).

Public method:

An accessor method to retrieve the carry-forward leave that granted for the

staff.

o The formula is subtracting the annual leave with the number of leave

taken. However, the number of carry-forward leave should not be more

than 5 days.

An overridden toString method to return the string(text) that contains the

staffs info.

o Call the superclasss toString method along with the text of annual

leave, leave taken and carry-forward leave (be ensure to call the

appropriate methods). You may refer to the sample output (Figure B1

and B2).

C. Next, write a class named ContractStaff that inherits the Staff class. The class

consists of the following fields and methods.

Private instance data fields:

An array of overtime hours for this staff.

The extra leave granted to the staff for next year.

Public constructor:

A constructor with the parameters staff name, staff ID and number of leave

taken.

o Call the superclasss constructor with the parameters: staff name, and

staff ID.

o Call the superclasss respective method to set the leave taken (and pass

the argument).

Public method:

A mutator method to set the overtime hours for the staff.

An accessor method to calculate and return the total hours of overtime that

the contract staff has worked.

An accessor method to determine and return the extra leave granted for this

staff based on the total hours of overtime. Refer to the following table (Table

1).

Total hours of

overtime

Extra leave

(day)

70 and above

6

50 - 69

5

40 - 49

4

30 - 39

3

20 - 29

2

Less than 20

No leave

Table 1: Extra leave for overtime

An overridden method to return the annual leave for the contract staff.

o Call the superclasss method of annual leave and subtract by 10.

An overridden toString method to return the string (text) that contains

the staffs info.

o Call the superclasss method of toString along with the text of

annual leave, leave taken, total overtime and extra leave (be ensure to

call the appropriate methods). You may refer to the sample output

(Figure B3).

D. Then, write an application program to test the classes above.

Prompt the user to enter staff name, staff ID, days of leave taken and type of staff

(refer to sample output).

If permanent staff:

Create an object of PermanentStaff and pass the parameters of staff

name, staff ID and days of leave taken which entered by the user earlier.

Print the object / call the toString method.

If contract staff:

Create an object of ContractStaff and pass the parameters of staff

name, staff ID and days of leave taken which entered by the user earlier.

Prompt the user to enter the overtime hours for each month of the year (store

the data in an array).

Next, call the respective method to set the overtime hours.

Print the object / call the toString method.

Display the total leave awarded for this staff for next year (add annual leave

and the extra leave). Call the respective methods.

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!