Question
Employee Payment (repost because I asked the question 3 time and got spam answers) Your program is going to display employees' hours and pay. To
Employee Payment (repost because I asked the question 3 time and got spam answers)
Your program is going to display employees' hours and pay.
To Do in the Pay.java file:
Complete the Pay class as follows:
Import Statements:
- In line 1 of Pay.java, type import java.text.NumberFormat; This will give you the ability to write in currency format. You will utilize this ability in your toString() method.
Fields:
- hoursWorked double
- payRate double
- grossPay double
Constructors:
-
A default constructor to initialize the fields. The payRate field should be set to $7.50 and the hoursWorked field to zero.
-
Another constructor with one argument, the number of hours worked. It should assign this value to the appropriate field and set the payRate field to the default value of $7.50.
Methods:
- getHours() this method returns the hoursWorked field value.
- getPayRate() this method returns the payRate field value.
- getGrossPay() this method returns the grossPay field value.
- calcGrossPay() this method calculates the grossPay field (hour * payRate)
- setHours() this method has one argument representing the number of hours worked
- setPayRate() this method has one argument representing the current payRate to be assigned
- toString() - this method returns a String that will print out the hours worked, pay rate, and gross pay for a Pay object. The money should be properly formatted to show change correctly.
- As stated above, you are going to use the NumberFormat class to format your currency. More specifically, you should use the getCurrencyInstance() and format() methods.
- For example, if you wanted to output $25.00, your code would be:
NumberFormat money = NumberFormat.getCurrencyInstance();
System.out.println(money.format(25));
To Do in Main.java file:
- Create two instances of the Pay class: emp1 that uses the default constructor, emp2 that creates an instance with hours worked equal to 36
- Change the hours worked for emp1 to 48.
- Change the pay rate for emp2 to $15.60.
- Calculate the gross pay for emp1 and emp2.
- Display the hours worked, pay rate, and gross pay for both instances with appropriate labels. Put a blank line in between the two outputs.
Then
Run the Main class. Be sure that you hand calculate the results to make sure that your program is giving the correct results. Be sure to use appropriate comments/documentation
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