Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Finish this java exercise Question 2 In a factory, a factory worker is a salaried employee who is eligible to work overtime for every month
Finish this java exercise
Question 2 In a factory, a factory worker is a salaried employee who is eligible to work overtime for every month in a year. A factory worker whose post is as a supervisor could earn a yearly bonus when his or her overtime reaches certain hours. The following application is designed based on this situation. Refer to the UML class diagrams as shown in Figure 2 (a) for the following instructions: a Write a class named Employee that consists the following fields and methods: Class fields: employee ID field represents the ID of the employee. employee Name field represents the name of the employee. Constructor: Employee () constructs an object with two parameters: employee ID and employee Name, and set the data with the class fields. Methods: getID(): returns the ID of the employee. getName(): returns the name of the employee. V b Write a class named Factoryworker that inherits Employee class Class field: monthsOTHours is an array field that represents the number of overtime hours in a year for the employee. 6 Constructor: Factoryworker constructs an object with parameters: ID, name and overtime hours. This constructor calls the superclass's constructor to set the ID and name for this employee. This constructor also should assign the overtime hours to the class field monthsorHours, Method: getMonthsOTHours return the array field of number of overtime (monthsOTHours) for the employee. Write a class named Supervisor that inherits FactoryWorker class Class fields: avgor field represents the average of overtime hours that the supervisor achieves bonus field represents the annual bonus that the supervisor gets based on the average of overtime hours for the supervisor. Constructor: Supervisor constructs an object with parameters: ID, name and supervisor overtime hours (an array). This constructor calls the superclass's constructor to set these parameters for the supervisor. Methods: V getAverage or calculates and returns the average overtime for this supervisor. You should call the superclass's method (getMonthsotHours) to retrieve the overtime hours. To calculate the average, sum up the overtime hours and calculate the average. V getAnnualBonus returns the bonus for the supervisor based on the average overtime. Refer to the following table: Average Overtime Bonus (RM) (hours) 30 and more 800.00 20 and more 500.00 10 and more 200.00 others Table 1: Bonus Reward 14 d Then write an application program to test Supervisor class. Prompt the user to enter the supervisor ID and name. Create an array of overtime for 12 months and prompt the user to enter the number of hours for each month to be stored in the array Create an object of Supervisor with the parameters of supervisor ID, name and overtime (that user entered earlier) as the arguments. Then display the record of the supervisor with these data by calling the appropriate methods: Supervisor ID Supervisor name Average overtime of the supervisor in that year. Annual bonus for the supervisor for that year. You may refer to the sample output as shown in Figure 2(b). 15 Employee employeeID: String employeeame: String 1/other related fields + Employee employeeID: String, employeeName: String) + getID(): String + getName(): String //other related methods A FactoryWorker monthsOI Hours: int [] //other related fields + FactoryWorker (ID: String, name: String, OTHours: int 01) + getMonths0THours (): int[] //ather related methods Supervisor avgor: double bonus: double //other related fields + Supervisor (ID: String, name: String, svOTHours: int in + getAverageOT(): double + getAnnualBonu: (): double //other related methods Figure 2(a): UML class diagram for Employee, Factory Worker and Supervisor 16 D run: Supervisor Information Enter employee ID: MU123456 Enter employee name: Frank c. Enter overtime (hours) for the year: Month 1 = 20 Month 2 = 1 Month 3 = 14 Month 4 = 10 Month 5 = 8 Month 6 = 12 Month 7 = 4 Month 8 = 5 Month 9 = 11 Month 10 = 12 Month 11 = 10 Month 12 = 8 Annual Report Supervisor ID :M0123456 Supervisor Name : Frank c. Average OT: 10.50 Annual bonus : $200.00 Figure 2(b) - Sample outputStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started