Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a.Create a class named Pay that includes five double variables that hold hours w

ID: 3633490 • Letter: A

Question

a.Create a class named Pay that includes five double variables that hold hours worked, rate of pay per hour, withholding rate, gross pay, and net pay. Create three overloaded computeNetPay () methods. When computeNetPay () receives values for hours, pay rate, and withholding rate, it computes the gross pay and reduces it by the appropriate withholding amount to produce the net pay. (Gross pay is computed as hours worked multiplied by pay per hour.)


b.When computeNetPay () receives two parameters, they represent the hours and pay rate, and the withholding rate is assumed to be 15%. When computeNetPay () receives one parameter, it represents the number of hours worked, the withholding rate is assumed to be 15%, and the hourly rate is assumed to be 5.85. Write a main() method that tests all three overloaded methods. Save the application as Pay.java

--------------------------------------------------------------------------------

Explanation / Answer


public class Pay
{
   public double hours_worked, rate_of_pay_per_hour, withholding_rate, gross_pay, net_pay;  
   public void computeNetPay(double hours, double payrate, double withholdingrate)
   {
       hours_worked = hours;
       rate_of_pay_per_hour = payrate;
       withholding_rate = withholdingrate;
       gross_pay = hours_worked * rate_of_pay_per_hour;
       net_pay = gross_pay - withholding_rate;
   }
  
   public void computeNetPay(double hours, double payrate)
   {
       hours_worked = hours;
       rate_of_pay_per_hour = payrate;
       gross_pay = hours_worked * rate_of_pay_per_hour;
       withholding_rate = (15/100) * gross_pay;
       net_pay = gross_pay - withholding_rate;
   }
  
   public void computeNetPay(double hours)
   {
       hours_worked = hours;
       rate_of_pay_per_hour = 5.85;
       gross_pay = hours_worked * rate_of_pay_per_hour;
       withholding_rate = (15/100) * gross_pay;
       net_pay = gross_pay - withholding_rate;
   }
  
   public static void main(String[] args)
   {
       Pay p = new Pay();
      
       p.computeNetPay(138,7.2, 150);//1st type
       System.out.println(" Constructor overload with 3 parameters");
       System.out.println("Gross Pay = "+p.gross_pay+", Net Pay = "+p.net_pay);
      
       p.computeNetPay(138,7.2);//2nd type
       System.out.println(" Constructor overload with 2 parameters");
       System.out.println("Gross Pay = "+p.gross_pay+", Net Pay = "+p.net_pay);
      
       p.computeNetPay(138);//3rd type
       System.out.println(" Constructor overload with 1 parameter");
       System.out.println("Gross Pay = "+p.gross_pay+", Net Pay = "+p.net_pay);
   }

}