Question: Java programing Lab [Type here Write Java programs based on the following instructions: A. Write a class named Staff that represents a record of a
Java programing Lab 




[Type here 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, 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 1 B. Next, write a class named Permanent Staff 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. 1 [Type here) [Type here) . Public constructor: A constructor with the parameters staff name, staff ID and number of leave taken. Call the superclass's constructor with the parameters: staff name, and staff ID Call the superclass's 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. 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 o o An overridden toString method to return the string(text) that contains the staff's info. Call the superclass's 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 BI and B2). 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. Call the superclass's constructor with the parameters: staff name, and staff ID o Call the superclass's respective method to set the leave taken (and pass the argument). o . 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. [Type here) [Type here) 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 I). Total hours of Extra leave overtime (day) 70 and above 6 50 - 69 5 40-49 30-39 3 20-29 2 Less than 20 No leave Table I: Extra leave for overtime 4 An overridden method to return the annual leave for the contract staff. Call the superclass's method of annual leave and subtract by 10. An overridden toString method to return the string (text) that contains the staff's info. Call the superclass's method of toString along with the text of annual leave, leave taken, total overtime and extra Icave (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 Permanent Staff 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. . I If contract staff: Create an object of Contract Staff and pass the parameters of staff name, staff ID and days of leave taken which entered by the user carlier, 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. . [Type here) [Type here! . Display the total leave awarded for this staff for next year (add annual leave and the extra leave). Call the respective methods. Sample outputs of different record for your reference: Kindly key in the data of the staff: Staff Name = John Musk Staff ID = 344748 How many days of leave taken? = 17 Staff Type (P: Permanent C: Contract)? = P Permanent Staff Leave Data Staff name: John Musk Staff ID: 344748 Annual leave: 20 Total leave taken: 17 Carry forward leave: 3 Figure Bl: Sample 1 - Permanent staff with 17 days of leave taken. run: Kindly key-in the data of the staff: Staff Name - Sophia Jane Staff ID = 312907 How many days of leave taken? = 10 Staff Type (P: Permanent C: Contract)? = P Permanent Staff Leave Data Staff name: Sophia Jane Staff ID: 912907 Annual leave: 20 Total leave taken: 10 Carry forward leave: 5 Figure B2: Sample 2 - Permanent staff with 10 days of leave taken. [Type here) [Type here] run: Kindly key-in the data of the staff: Staff Name = Elle Billy Staff ID = c09256 How many days of leave taken? Staff Type (P: Permanent c: Contract)? = C Contract Staff Leave Data Key-in the overtime hours for each month: Month le 3 Month 2= 4 Month 3= 0 Month 4= 3 Month 5= 1 Month 6= 4 Month 7= 7 Month = 0 Month 9- 5 Month 105 4 Monch 11= 4 Monch 12= 4 Staff name: Elle Billy Staff ID: 009256 Annual leave: 10 Total leave taken: 6 Total hours of overtime: 39 Extra leave for next year: 3 Total leave for next year = 13 Figure B3: Sample 3 - A contract staff [Type here)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
