-Problem Description Wombat Corporation needs a GUI program to calculate how muc
ID: 3807322 • Letter: #
Question
-Problem Description
Wombat Corporation needs a GUI program to calculate how much to pay their hourly employees. 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. The Commonwealth of Virginia requires that hourly employees be paid at least $8.25 an hour. Wombat Corporation policy states that they will pay a maximum of 60 hours and a minimum of 4 hours per week.
-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. So the list would look something like this after a couple of entries:
(Note: This is an example. You are not required to make your output look exactly like this.)
Base Pay and Pay Amt must be formatted like currency. Hours Worked must show 2 decimal places.
Use a Border Pane for your program.
The Center Region is where the table of information will be displayed.
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 Amt by that percentage.
If the user pressed the 5% Radio Button, the example above would look like:
and the Total would be $1,339.61.
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 a GridPane accordingly to show the information.
-Error Checking
Inputs
Make sure all fields are numbers.
Employee Number should be an Integer.
Base Pay should not be below the minimum wage allowed.
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
Bcoz of stipulated time i couldn't implement Raises functionality.rest of the things is working fine.
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;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.