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

Write a program that includes an empPay class that can be used to calculate and

ID: 3738531 • Letter: W

Question

Write a program that includes an empPay class that can be used to calculate and print the take-home pay for a restaurant employee, and an Employee class that will contain your main method and be used to test it. When you create this project, name it empPayXX, where XX = your initials. For example, mine would be empPayCW. An employee has 2 attributes (fields): name (String) grossPay (double) Take-home pay is calculated by taking the grossPay and subtracting the following taxes: Federal Tax rate: 18%, Retirement: 10%, Social Security Tax: 6%. (all values subtracted should use original grossPay as the base value and of course, they're all double data types). I'd like you to create the following in your class file: Private fields for the name and grossPay. Private FINAL (constant) fields for each of the federal, pension, and social security rates. So five fields in total. Create public accessors/mutators for your name and grossPay attributes. These could be called from anywhere in the program. Then create one showDeductions method to print all of the pay and deduction information (see the example). Create three PRIVATE HELPER METHODS to calculate the federal, retirement, and social security deductions. These will only be called from within your class file. So you should have 8 member methods total in your class file, five of them public and three of them private for calculating deductions. Investigate importing java.text.NumberFormat in your class file to properly format your output. This will require you to lookup NumberFormat and it's proper use for currency. In the working world, you will need to commonly do this. Or, you can format your currency output the best you know how. Create a second class called Employees to test this restaurant empPay class and it's members within a main() function. Test with three employees. In my sample, I used Bob, Raymond, and Dilbert. In this sample output, each of the three employee objects were created and the employee's name and grossPay attributes were set from within the main () method, and then the showDeductions method was called to produce the output that follows: ---------- Payroll data for: Bob Gross pay is: $34,000.00 Federal tax deduction is: $6,120.00 Pension deduction is: $3,400.00 Social Security deduction is: $2,040.00 Net pay is: $22,440.00 ---------- Payroll data for: Raymond Gross pay is: $41,595.00 Federal tax deduction is: $7,487.10 Pension deduction is: $4,159.50 Social Security deduction is: $2,495.70 Net pay is: $27,452.70 ---------- Payroll data for: Dilbert Gross pay is: $20,001.25 Federal tax deduction is: $3,600.22 Pension deduction is: $2,000.12 Social Security deduction is: $1,200.08 Net pay is: $13,200.83

Explanation / Answer

empPayKW.java

import java.text.NumberFormat;

public class empPayKW {

//Declaring instance variables

private String name;

private double grossPay;

//Declaring constants

private final double FEDERAL_TAX=0.18;

private final double PENSION=.10;

private final double SOCIAL_SECURITY_TAX=0.06;

//Parameterized constructor

public empPayKW(String name, double grossPay) {

this.name = name;

this.grossPay = grossPay;

}

// getters and setters

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public double getGrossPay() {

return grossPay;

}

public void setGrossPay(double grossPay) {

this.grossPay = grossPay;

}

//This method will display deductions

void showDeductions()

{

NumberFormat fmt = NumberFormat.getCurrencyInstance();

double net=0;

net=grossPay-(getFederalTax())-(getPensionTax())-(getSocialSecurityTax());

System.out.println("Payroll data for: "+name);

System.out.println("pay is: "+fmt.format(grossPay));

System.out.println("Federal tax deduction is: "+fmt.format(getFederalTax()));

System.out.println("Pension deduction is: "+fmt.format(getPensionTax()));

System.out.println("Social Security deduction is: "+fmt.format(getSocialSecurityTax()));

System.out.println("Net pay is: "+fmt.format(net));

System.out.println("----------");

}

private double getFederalTax()

{

return grossPay*FEDERAL_TAX;

}

private double getPensionTax()

{

return grossPay*PENSION;

}

private double getSocialSecurityTax()

{

return grossPay*SOCIAL_SECURITY_TAX;

}

}

___________________

Employees.java

public class Employees {

public static void main(String[] args) {

  

//Creating 3 Employees

empPayKW emp1=new empPayKW("Bob",34000);

empPayKW emp2=new empPayKW("Raymond",41595);

empPayKW emp3=new empPayKW("Dilbert",20001.25);

//Display deductions of each employee

emp1.showDeductions();

emp2.showDeductions();

emp3.showDeductions();

}

}

__________________

Output:

Payroll data for: Bob
pay is: $34,000.00
Federal tax deduction is: $6,120.00
Pension deduction is: $3,400.00
Social Security deduction is: $2,040.00
Net pay is: $22,440.00
----------
Payroll data for: Raymond
pay is: $41,595.00
Federal tax deduction is: $7,487.10
Pension deduction is: $4,159.50
Social Security deduction is: $2,495.70
Net pay is: $27,452.70
----------
Payroll data for: Dilbert
pay is: $20,001.25
Federal tax deduction is: $3,600.22
Pension deduction is: $2,000.12
Social Security deduction is: $1,200.08
Net pay is: $13,200.82
----------

_______________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote