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

Please assist. Create a payroll JApplet named JCalculatePay that allows the user

ID: 3534842 • Letter: P

Question

Please assist.

Create a payroll JApplet named JCalculatePay that allows the user to enter two double values: hours worked and an hourly rate. When the user clicks a JButton, gross pay is calculated. Display the result in a JTextField that appears on the screen only : clicks the JButton. Save the file as JCalculatePay.java. Modify the payroll applet created in Exercise 8a so that federal withholding tax is subtracted from gross pay based on the values in Table 17-1. Display the gross pay, tax amount, and net pay. Save the file as JCalculatePay2.java.

Explanation / Answer

Please rate with 5 stars :)


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JCalculatePay extends JApplet implements ActionListener
{
JLabel companyName = new
JLabel("Accounting Inc");
JButton calcButton = new JButton("Calculate");
JLabel perPersonResult = new JLabel("Payroll.");
JLabel totalResult = new JLabel("Calculate hours worked and hourly rate");

Font bigFont = new Font("Helvetica", Font.ITALIC, 24);

public void init()
{
Container con = getContentPane();
con.setLayout(new FlowLayout());
companyName.setFont(bigFont);
con.add(companyName);
con.add(calcButton);
con.add(okButton);
calcButton.addActionListener(this);
con.add(perPersonResult);
con.add(totalResult);
}

public void start()
{
perPersonResult.setText("Payroll.");
totalResult.setText("Calculate hours worked and hourly rate");
repaint();
}

public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source == calcButton)
{
String response = JOptionPane.showInputDialog(null, "Enter the number of hours worked");
}
else if(source == okButton)
{
String response = JOptionPane.showInputDialog(null, "Enter the hourly rate");


int totalPay;
int hoursWorked = Integer.parseInt(response);
int hourlyRate = 0;
int x = 0, a = 0;

{
totalPay = hoursWorked * hourlyRate;
x = 0;
}
totalResult.setText("$" + totalPay);
}
}
}