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

would you pls help me with this it is urgent!!! Problem Description Wombat Corpo

ID: 3772090 • Letter: W

Question

would you pls help me with this it is urgent!!!

Problem Description

Wombat Corporation needs a GUI program to calculate how much to pay their hourly employees each week. The US Department of Labor requires that employees get paid time and a half for any hours over 40 they work in a single week. For example, if an employee works 45 hours, they get 5 hours of overtime, at 1.5 times their base pay.

Specifications

Write a program that will allow users to enter an Employee’s ID Number, Base Pay amount, and the Hours Worked for a particular week. This information will be added to a list of employees showing the entered information and the paycheck amount.

Use a Border Pane for your program.

The Center Region is where the table of information will be displayed. Use a GridPane to make it easier to line up the columns.

The Top Region contains fields for the user to enter employee data and an Add button. Pressing Add to insert the information into the table in the Center Region.

The Bottom Region should have a field containing the total Pay Amt for all entries. For the example above, an amount of $1,275.81 would be displayed.

The Right Region should have 4 vertical Radio Buttons labeled Raises. The 4 buttons should be labeled, from top to bottom, 1%, 2%, 5%, and Reset. If the user selects any of the first 3 buttons, you will need to increase each Pay Amount by that percentage.

So the screen would look something like this after a couple of entries:

(Note: This is an example. You are not required to make your output look like this.)

If the user pressed the 5% Radio Button, the example above would look like:

If the user clicks Reset, the amounts go back to their original values.

Hint: Store the values entered in an Array or ArrayList and rebuild the GridPane accordingly.

Error Checking

Inputs

Make sure all fields are numbers.

Hours Worked should not be less than 4.

All fields need to be correct when the Add button is pressed.

Use a Try-Catch blocks where you deem appropriate.

Explanation / Answer

Due to lack of time I could not implement the raises functionality. Rest works

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.text.NumberFormat;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;

public class EmployeeWages implements PropertyChangeListener, ActionListener {
   private JFrame frame;
  
   private int id = 0;
   private double amount;
   private double hours;
  
   private JRadioButton raise5;
   private JRadioButton raise2;
   private JRadioButton raise1;
   private JRadioButton reset;
  
   private ButtonGroup group;
  
  
   private DefaultTableModel model;
  
   //Fields for data entry
   private JFormattedTextField idField;
   private JFormattedTextField payField;
   private JFormattedTextField hoursField;
  
   private String[] columnNames;
  
   private JButton add;
  
   //Formats to format and parse numbers
   private NumberFormat amountFormat;
  
   public EmployeeWages() {
       frame = new JFrame("Employee Wages");
       makeFrame();
   }

   private void makeFrame() {
       // main container
       Container mainContainer = frame.getContentPane();
       mainContainer.setLayout(new BorderLayout());
      
       mainContainer.add(createTopPanel(), BorderLayout.NORTH);
       mainContainer.add(createCentralPanel(), BorderLayout.CENTER);
       mainContainer.add(createRightPanel(), BorderLayout.EAST);
      
       frame.setSize(450, 425);
       frame.setVisible(true);
      
      
   }
  
   private JPanel createTopPanel() {
       JPanel topPane = new JPanel();
       topPane.setLayout(new GridLayout(4, 1));
      
       // make four panels with FlowLayout
       JPanel idPane = new JPanel();
       idPane.setLayout(new FlowLayout(FlowLayout.LEFT));
       JPanel payPane = new JPanel();
       payPane.setLayout(new FlowLayout(FlowLayout.LEFT));
       JPanel hoursPane = new JPanel();
       hoursPane.setLayout(new FlowLayout(FlowLayout.LEFT));
       JPanel addPane = new JPanel();
       addPane.setLayout(new FlowLayout(FlowLayout.LEFT));
      
       add = new JButton("Add");
       add.addActionListener(this);
      
       idField = new JFormattedTextField();
       idField.setValue(new Integer(id));
idField.setColumns(10);
idField.addPropertyChangeListener("value", this);
  
amountFormat = NumberFormat.getNumberInstance();
payField = new JFormattedTextField(amountFormat);
payField.setValue(new Double(amount));
payField.setColumns(10);
payField.addPropertyChangeListener("value", this);
  
hoursField = new JFormattedTextField(amountFormat);
hoursField.setValue(new Double(hours));
hoursField.setColumns(10);
hoursField.addPropertyChangeListener("value", this);
  
       // put the label "Employee #:" and textField into the id panel
       idPane.add(new JLabel("Employee #:"));
       idPane.add(idField);  

       // put the label "Base Pay:" and textField into the pay panel
       payPane.add(new JLabel("Base Pay:"));
       payPane.add(payField);

       // put the label "Hours Worked:" and textField into the hours panel
       hoursPane.add(new JLabel("Hours Worked:"));
       hoursPane.add(hoursField);

       // put the button "Add" into add panel
       addPane.add(add);
      
       // put the three panels into top panel
       topPane.add(idPane);
       topPane.add(payPane);
       topPane.add(hoursPane);
       topPane.add(addPane);
       return topPane;
   }

   @Override
   public void propertyChange(PropertyChangeEvent evt) {
       Object source = evt.getSource();
       if (source == idField) {
           id = ((Number)idField.getValue()).intValue();
       }
      
       else if (source == payField) {
           amount = ((Number)payField.getValue()).doubleValue();
       }
      
       else if (source == hoursField) {
           hours = ((Number)hoursField.getValue()).doubleValue();
       }
      
   }
  
   private JPanel createCentralPanel() {
       JPanel centralPane = new JPanel();
       centralPane.setLayout(new GridLayout(1, 0));
       columnNames = new String[]{"Employee #", "Base Pay", "Hours Worked", "Pay Amount"};
       model = new DefaultTableModel(null, columnNames);
       JTable table = new JTable(model);
       centralPane.add(table);
       return centralPane;
   }

   @Override
   public void actionPerformed(ActionEvent e) {
       Object source = e.getSource();
       if (source == add) {
           String empId = idField.getValue().toString();
           double basePay = (Double) payField.getValue();
           double hours = (Double) hoursField.getValue();
           double payAmount;
           if (hours > 40) {
               payAmount = 40*basePay + 1.5*basePay*(hours - 40);
           }
           else {
               payAmount = hours*basePay;
           }
           model.addRow(new Object[]{empId, basePay, hours, payAmount});
       }
      
   }
  
   private JPanel createRightPanel() {
       JPanel rightPanel = new JPanel();
       rightPanel.setLayout(new FlowLayout());
       raise5 = new JRadioButton("5%");
       raise2 = new JRadioButton("2%");
       raise1 = new JRadioButton("1%");
       reset = new JRadioButton("Reset");
      
       group = new ButtonGroup();
       group.add(raise5);
       group.add(raise2);
       group.add(raise1);
       group.add(reset);
       rightPanel.add(raise5);
       rightPanel.add(raise2);
       rightPanel.add(raise1);
       rightPanel.add(reset);
       rightPanel.setBorder(new TitledBorder(new EtchedBorder(), "Raises"));
       return rightPanel;
   }

}