Question
Define a class named Employee and save the class in a file named Employee.java This class has four data fields: name: String hoursWorked: double hourlyPayrate:
Define a class named Employee and save the class in a file named Employee.java This class has four data fields:
name: String
hoursWorked: double
hourlyPayrate: double
bonusRate: double
The class has two constructors: 1. constructor without arguments: initialize name to empty string, and all other data fields to 0.0 2. constructor with a String type arguments and three double type arguments. Use them to initialize the data fields properly The class also has:
1. getter method for each data field to return the value of the data field
2. setter method for each data field to set a new value of that data field
3. a method called calcRegularPay to calculate and return the regular salary using the following formula:
regular salary of an employee = hoursWorked * hourlyPayRate
4. a method called calcBonus to calculate and return the amount of bonus using the following formula:
bonus amount of an employee = regular salary of an employee * bonus rate
where the regular salary of an employee is the return value of the method in 3
5. a method called calcGrossPay to calculate and return the gross pay using the following formula:
gross pay of an employee = regular salary of an employee + bonus amount of the employee
where the regular salary of an employee is the return value of the method in 3 and the bonus amount is the return value of the method in 4
Then write a separate demo program to test the class. The demo program should be saved in a file named EmployeeDemo.java. In the demo program:
create an empty employee. Use setters methods to set values for all data fields. Use the three methods to calculate regular pay, bonus amount, and gross pay for the employee. Display results.
Notes:
1. the two java files should be saved in the same folder
Step 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