Create a class called Payroll. In it, write a constructor to accept values for the number of hours worked, hourly pay and the number of dependents. Write a method called getGrossPay to compute the gross pay, a method called getTaxableIncome to compute the taxable income, get a method called getTaxes to compute the amount of taxes and a method called getNetPay to compute the net pay. Also, create a second file to pass the three values described above to the Payroll class and print gross pay, taxable income, taxes and net pay.

Following is the complete code from lecture notes several weeks ago.

import java.text.DecimalFormat;
import java.util.Scanner;
public class application1 {
public static void main(String[] args) {
double hourly_pay, hours_worked,gross_pay;
double num_dependents, reduction_rate, taxable_income, taxes,net_pay;
Scanner k = new Scanner(System.in);
System.out.println("Enter the number of hours worked = ");
hours_worked = k.nextDouble();
System.out.println("Enter the hourly pay = ");
hourly_pay= k.nextDouble();
System.out.println("Enter the number of number of dependents = ");
num_dependents = k.nextDouble();
if (hours_worked <= 40)
gross_pay = hourly_pay * hours_worked;
else if (hours_worked <= 60)
gross_pay = hourly_pay * 40 + hourly_pay * 1.5 * (hours_worked - 40);
//Gross pay = 10(40) + 15(12) = 580
//gross_pay = hourly_pay * 40 + hourly_pay * 1.5 * (hours_worked%40);
else
gross_pay = hourly_pay * 40 + hourly_pay * 1.5 * (60 - 40) + hourly_pay * 2 * (hours_worked - 60);
//Gross pay = 10(40) + 15(20) + 20(15) = 1000
//gross_pay = hourly_pay * 40 + hourly_pay * 1.5 * (60 - 40) + hourly_pay * 2 * (hours_worked%60);

if (num_dependents == 0)
reduction_rate = 0;
else if (num_dependents == 1)
reduction_rate = 0.04;
else if (num_dependents == 2)
reduction_rate = 0.0775;
else if (num_dependents == 3)
reduction_rate = 0.1125;
else if (num_dependents == 4)
reduction_rate = 0.145;
else if (num_dependents == 5)
reduction_rate = 0.175;
else
reduction_rate = 0.2025;

taxable_income = gross_pay * (1 - reduction_rate);
//taxable income = 2000(1 - 11.25/100) = 1775
if(taxable_income <=500)
taxes = taxable_income *0.1;
else if(taxable_income <=1000)
taxes = (500*.1)+((taxable_income-500)*0.15);
else if(taxable_income <=1500)
taxes = (500*.1)+(500*.15)+((taxable_income-1000)*0.25);
else if(taxable_income <=2000)
taxes = (500*.1)+(500*.15)+(500*.25)+((taxable_income-1500)*0.40);
else
taxes = (500*.1)+(500*.15)+(500*.25)+(500*.4)+((taxable_income-2000)*0.50);
net_pay=gross_pay-taxes;
DecimalFormat f = new DecimalFormat("#0.00");
System.out.println("Gross pay = $" + f.format(gross_pay));
System.out.println("Taxable income = $" + f.format(taxable_income));
System.out.println("Taxes = $" + f.format(taxes));
System.out.println("Net pay = $"+ f.format(net_pay));
}
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.