I need help with step 3 and knowing where and how to put the information in the
ID: 3684397 • Letter: I
Question
I need help with step 3 and knowing where and how to put the information in the code which is at the end. The program calculates the amount of tax withheld from an employee ’ s weekly salary, the tax deduction to which the employee is entitled for each dependent, and the employee ’ s take-home pay. The program output includes state tax withheld, federal tax withheld, dependent tax deductions, salary, and take-home pay. 1. Open the source code file named Payroll.cpp using Notepad or the text editor of your choice. 2. Variables have been declared and initialized for you as needed, and the input and output statements have been written. Read the code carefully before you proceed to the next step. 3. Write the JAVA code needed to perform the following: a. Calculate state withholding tax at 6.5 percent, and calculate federal with holding tax at 28.0. b. Calculate dependent deductions at 2.5 percent of the employee ’ s salary for each dependent. c. Calculate total withholding. (Total withholding is the total state withholding combined with the total federal withholding.) d. Calculate take-home pay as salary minus total withholding plus deductions. 4. Save this source code file in a directory of your choice, and then make that directory 5. Compile the program. 6. Execute the program. You should get the following output: State Tax: $81.25 Federal Tax: $350 Dependents: $62.5 Salary: $1250 Take-Home Pay: $881.25 // This program calculates an employee's take home pay. public class Payroll { public static void main(String args[]) { double salary = 1250.00; double stateTax ; double federalTax; double numDependents = 2; double dependentDeduction; double totalWithholding; double takeHomePay; // Calculate state tax here. System.out.println("State Tax: $" + stateTax); // Calculate federal tax here. System.out.println("Federal Tax: $" + federalTax); // Calculate dependant deduction here. System.out.println("Dependents: $" + dependentDeduction); // Calculate total withholding here. // Calculate take home pay here. System.out.println("Salary: $" + salary); System.out.println("Take Home Pay: $" + takeHomePay); System.exit(0); } }
Explanation / Answer
public class Payroll
{
private String name;
private double hours_Worked;
private double hourly_Pay;
private static final double FEDERAL_TAX = 0.28;
private static final double STATE_TAX = 0.065;
public Payroll()
{
}
public Payroll(String n, double hw, double hpr)
{
this.name = n;
this.hours_Worked = hw;
this.hourly_Pay = hpr;
}
public double grossPay(double hourlyRate, double hrsWorked)
{
double grossPay = (hourlyRate * hrsWorked);
return grossPay;
}
public double federalTax(double gross)
{
return FEDERAL_TAX * gross;
}
public double stateTax(double gross)
{
return STATE_TAX * gross;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double gethours_Worked() {
return hours_Worked;
}
public void sethours_Worked(double hours_Worked) {
this.hours_Worked = hours_Worked;
}
public double gethourly_Pay() {
return hourly_Pay;
}
public void sethourly_Pay(double hourly_Pay) {
this.hourly_Pay = hourly_Pay;
}
}
import java.util.*;
public class Payroll_employee
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
Payroll data = new Payroll();
System.out.println("Enter your name: ");
data.setName(input.next());
System.out.println("Number of Hours Worked: ");
data.sethours_Worked(Double.parseDouble(input.next()));
System.out.println("Hourly Pay Rate: ");
data.sethourly_Pay(Double.parseDouble(input.next()));
double grossAmount = data.grossPay(data.gethourly_Pay(), data.gethours_Worked());
System.out.println("Name: " + data.getName());
System.out.println("Hours Worked: " + data.gethours_Worked() + "hrs");
System.out.println("Pay Rate: $" + data.gethourly_Pay());
System.out.println("Gross Pay: $" + grossAmount + ' ');
System.out.println("DEDUCTIONS");
System.out.println("Federal Tax Withholding (28%): $" + data.federalTax(grossAmount));
System.out.println("State Tax Withholding (6.5%): $" + data.stateTax(grossAmount));
System.out.println("Total Deductions: $" + (data.federalTax(grossAmount) + data.stateTax(grossAmount)));
System.out.println("Net Pay: $" + (grossAmount - (data.federalTax(grossAmount) + data.stateTax(grossAmount))));
input.close();
}