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

in Java, Create an applet payroll program named CalcPay that allows the user to

ID: 3858175 • Letter: I

Question

in Java, Create an applet payroll program named CalcPay that allows the user to enter two double valuesand a string namely hours worked, hourly rate and name. After the user enters the rate, hours,and name the program should calculate the gross pay by pressing CALCULATE button. Compute federal withholding tax which is subtracted from gross based on the following table: Hints: (100pts) Use methods as deemed appropriate. 0 to 99.99 6% 100.00 to 299.99 12% 300.00 to 599.99 18% 600.00 and up 21%. Display the output which should include: Name, hours, rate, deduct, gross and net.

Explanation / Answer

import java.awt.*;

import java.applet.*;

import java.awt.event.*;

import java.awt.Label;

import java.text.DecimalFormat;

public class CalcPay extends Applet implements ActionListener{

TextField txtname,txtdays,txtrate, txtsalary,txtfedtax;

Label lblname,lblposition,lblrate,lblsalary,title,lblfedtax;

Button button,clear;

DecimalFormat dFormat = new DecimalFormat("0.00");

public void init(){

setLayout(null);

title = new Label("Payroll");

title.setBounds(0,0,80,20);

add(title);

lblname = new Label("Employee Name ");

lblname.setBounds(20,50,100,20);

add(lblname);

txtname = new TextField(51);

txtname.setBounds(150,50,180,20);

add(txtname);

lblhour = new Label("hours worked");

lblhour.setBounds(20,90,100,20);

add(lblhour);

txthour = new TextField(5);

txthour.setBounds(150,90,100,20);

add(txthour);

lblrate = new Label("hourly rate");

lblrate.setBounds(20,130,130,20);

add(lblrate);

txtrate = new TextField(5);

txtrate.setBounds(150,130,100,20);

add(txtrate);

lblsalary = new Label("Employee Salary");

lblsalary.setBounds(20,170,130,20);

add(lblsalary);

txtsalary = new TextField(5);

txtsalary.setBounds(150,170,100,20);

add(txtsalary);

lblfedtax = new Label("Enter federal tax withholding rate:");

lblfedtax.setBounds(20,170,130,20);

add(lblfedtax);

txtfedtax = new TextField(5);

txtfedtax.setBounds(150,170,100,20);

add(txtfedtax);

button = new Button(" Calculate ");

button.setBounds(70,230,100,20);

add(button);

clear = new Button(" Clear ");

clear.setBounds(230,230,100,20);

add(clear);

button.addActionListener(this);

clear.addActionListener(this);

}

public void actionPerformed(ActionEvent ae){

int hour =Integer.parseInt(txthour.getText());

double rate=Double.parseDouble(txtrate.getText());

double fedtax=Double.parseDouble(txtfedtax.getText());

double gross_pay = (hour * rate);

if(gross_pay>0 && gross_pay<=99.99)

{

double fedtaxr = fedtax * 0.06;

}

if(gross_pay>=100 && gross_pay<=299.99)

{

double fedtaxr = fedtax * 0.12;

}

if(gross_pay>300 && gross_pay<=599.99)

{

double fedtaxr = fedtax * 0.18;

}

if(gross_pay>599.99)

{

double fedtaxr = fedtax * 0.21;

}

double deductions = fedtaxr ;

double total_pay= gross_pay - deductions;

txtsalary.setText("Name "+txtname.getText()+" Hours "+txthour.getText()+"rate "+txtrate.getText()+"Deduction "+deductions+"gross "+gross_pay+" "+Net pay"+dFormat.format(total_pay));

txtsalary.setEditable(false);

if(ae.getSource() == clear)

{

txtname.setText("");

txtdays.setText("");

txtrate.setText("");

txtsalary.setText("");

txtname.requestFocus();

}

}

}

Net pay is the take-home pay an employee receives after payroll deductions are taken out. You can find net pay by subtracting deductions from the gross pay.

Gross S = Basic + Da + Hra + Ma.

Deduction = Gross S - Pf - Pt - It.

Net Salary = Gross S - Deduction.