Question
1. Use the attached Java code to complete this assignment. 2. Create three private instance fields to hold the following information: a. The number of
1. Use the attached Java code to complete this assignment.
2. Create three private instance fields to hold the following information:
a. The number of hours an employee has worked during the last week (type double)
b. The hourly wageRate (type double)
c. The number of dependents that the employee has (type int)
3. Write a no-argument constructor that sets all the instance fields to zero.
4. Write a Java instance method named prompt4data to prompt the user for hours worked, wage rate, and number of dependents. Use these inputs to assign the private instance fields.
5. Write an instance method named grossPay, to compute and return the gross pay. Gross pay is calculated as follows:
wageRate * number of hours worked for the first 40 hours,
plus time and a half for all hours worked over 40 hours up to 60 hours,
plus double time for all hours worked over 60 hours.
Negative hours worked should result in zero pay.
6. Write an instance method named fedTax, to compute and return the federal tax withheld. The tax withheld is 10% of the gross pay minus $25 for each dependent. Note the tax withheld cannot be less than 0.
7. Write an instance method named toString, to return a string with the following information in a neat and readable form as shown here:
The Hours worked is: xx.xx
The Hourly Rate is: xx.xx
The Number of Dependents is: x
The Gross income is: xxxx.xx
The Federal Tax withheld is: xxx.xx
The Take home pay is: xxxx.xx
The take home pay is the gross-pay less the federal taxes withheld.
8. Run your program three different times using the following data:
Hours Wage Rate Dependents
36.0 8.25 3
49.5 16.50 1
72.0 25.75 4
import java.util.Scanner;
public class WorkerPay
{
public static void main( String args [] )
{
// 1. Instantiate the object worker here using the
// no-argument constructor:
// 2. Reference the method to prompt for inputs here:
// 3. Reference the method to display the results here:
} // end main
/*
Students must fill in the code for the private instance fields and the two instance methods: grossPay, fedTax, and display. Declare the three private instance fields here: */
private double hours;
/* Write the no-argument constructor here: */ public WorkerPay ()
{ // initialize the instance fields to zero.
hours = 0.0;
}
public void prompt4data() /* this is an instance method */
{
// This method should prompt for the input data
Scanner console = new Scanner( System.in );
// Fill in the remaining code here by prompting for the // three inputs and assigning the three instance fields.
System.out.print( "Enter the number of hours worked: " );
}
/* Complete the grossPay instance method */
public double grossPay()
{ return 0.0 ; // return the gross pay, not zero.
}
/* Write the fedTax() instance method here: */
/* Write the toString() instance method here: */
} // end class
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