// This program calculates an employee\'s take home pay. public class Payroll {
ID: 3791712 • Letter: #
Question
// 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);
}
}
1. write the java code needed to perform the following:
calculate state withholding tax at 6.5 percent, and calculate federal withholding tax at 28.0 percent
calculate dependent deductions at 2.5 percent of the employee's salary for each dependent.
calculate total withholding
calcuate take-home pay as salary minus total withholding plus deductions
2. compile
3. execute
4. Output should be:
state tax: $81.25
federal tax: $350.00000000000006
dependents: $62.5
salary: $1250.0
take home pay: $881.25
5. the variables named salary and numDependents are initialized with the values 1250.0 and 2. To make this program more flexible, modify it to accept interactive input for salary and numDependents. Name the modified version payroll2.java
Explanation / Answer
Payroll2.java
import java.util.Scanner;
public class Payroll2 {
public static void main(String[] args) {
double salary;
double stateTax, stax;
double federalTax, fTax;
double numDependents;
double dependentDeduction, dd;
double totalWithholding;
double takeHomePay;
// Scanner object is used to get the inputs entered by the user
Scanner sc = new Scanner(System.in);
System.out.print("Enter the Salary :");
salary = sc.nextDouble();
System.out.print("Enter the State tax(%) :");
stax = sc.nextDouble();
System.out.print("Enter the Federal tax(%) :");
fTax = sc.nextDouble();
System.out.print("Enter the Dependent Deduction(%) :");
dd = sc.nextDouble();
System.out.print("Enter the number of Dependents :");
numDependents = sc.nextInt();
// Calculate state tax here.
stateTax = salary * (stax / 100);
// Calculate federal tax here.
federalTax = salary * (fTax / 100);
// Calculate dependent deduction here.
dependentDeduction = numDependents * salary * (dd / 100);
// Calculate total withholding here.
totalWithholding = (stateTax + federalTax) - dependentDeduction;
// Calculate take home pay here.
takeHomePay = salary - totalWithholding;
//Displaying the results
System.out.printf(" State Tax: $%.2f", stateTax);
System.out.printf(" Federal Tax: $%.2f", federalTax);
System.out.printf(" Dependents: $%.2f", dependentDeduction);
System.out.printf(" Total withholding amount : $%.2f",
totalWithholding);
System.out.printf(" Take Home Pay: $%.2f", takeHomePay);
}
}
__________________
Output:
Enter the Salary :1250
Enter the State tax(%) :6.5
Enter the Federal tax(%) :28.0
Enter the Dependent Deduction(%) :2.5
Enter the number of Dependents :2
State Tax: $81.25
Federal Tax: $350.00
Dependents: $62.50
Total withholding amount : $368.75
Take Home Pay: $881.25
_______________Thank You
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.