Problem Description Wombat Corporation needs a GUI program to calculate how much
ID: 3807915 • Letter: P
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.
Commenting
Use the generated flower box in BlueJ to provide a description of the Class and your name.
For @version – Enter the date you started writing the class in MM/DD/YYYY format.
A single line comment on each element needed for the assignment.
Significant variables descriptions.
No “loop” variables. a, b, c, x, y, z, etc.
Explanation / Answer
package chegg;
import java.util.ArrayList;
import java.util.List;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javax.swing.JOptionPane;
public class FxBorderPaneExample1 extends Application {
Label employIDLabel = null;
TextField employIDText = null;
Label basePayoutLabel = null;
TextField basePayoutText = null;
Label workedHourLabel = null;
TextField workeedHourText = null;
Button submit = null;
BorderPane root = null;
VBox vbox = null;
public static void main(String[] args) {
Application.launch(args);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void start(Stage stage) {
final List<EmployeeWorkHoursBean> employeeList = new ArrayList<EmployeeWorkHoursBean>();
GridPane pane = new GridPane();
pane.setStyle("-fx-background-color: white; -fx-grid-lines-visible: true");
pane.setAlignment(Pos.CENTER);
pane.setHgap(5);
pane.setVgap(5);
// pane.setPadding(new Insets(5, 5, 5, 5));
// Create the Text Nodes
Text centerText = new Text("Center");
Text topText = new Text("Top");
Text rightText = new Text("Right");
Text bottomText = new Text("Bottom");
Text leftText = new Text("Left");
// Text scenetitle = new Text("Welcome");
// scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
// pane.add(scenetitle, 0, 0, 2, 1);
employIDLabel = new Label("Employee ID:");
pane.add(employIDLabel, 0, 0);
employIDText = new TextField();
pane.add(employIDText, 1, 0);
basePayoutLabel = new Label("Base Payout:");
pane.add(basePayoutLabel, 0, 1);
basePayoutText = new TextField();
pane.add(basePayoutText, 1, 1);
workedHourLabel = new Label("Worked Hour:");
pane.add(workedHourLabel, 0, 2);
workeedHourText = new TextField();
pane.add(workeedHourText, 1, 2);
submit = new Button("Submit");
pane.add(submit, 1, 3);
TableView<EmployeeWorkHoursBean> table = new TableView<EmployeeWorkHoursBean>();
final ObservableList<EmployeeWorkHoursBean> data = FXCollections
.observableArrayList(new EmployeeWorkHoursBean(1, 12.0, 4.0,
0.0), new EmployeeWorkHoursBean(2, 22, 8, 0));
TableColumn firstNameCol = new TableColumn("Employee ID");
firstNameCol.setMinWidth(100);
firstNameCol
.setCellValueFactory(new PropertyValueFactory<Employee, String>(
"employeeId"));
TableColumn lastNameCol = new TableColumn("Base Payout");
lastNameCol.setMinWidth(100);
lastNameCol
.setCellValueFactory(new PropertyValueFactory<Employee, String>(
"basePayout"));
TableColumn emailCol = new TableColumn("Worked Hour");
emailCol.setMinWidth(200);
emailCol.setCellValueFactory(new PropertyValueFactory<Employee, String>(
"workedHour"));
table.setEditable(true);
table.setItems(data);
table.getColumns().addAll(firstNameCol, lastNameCol, emailCol);
vbox = new VBox();
vbox.setSpacing(5);
vbox.setPadding(new Insets(10, 0, 0, 10));
vbox.getChildren().addAll(table);
// Set the alignment of the Top Text to Center
BorderPane.setAlignment(pane, Pos.TOP_CENTER);
// Set the alignment of the Bottom Text to Center
BorderPane.setAlignment(bottomText, Pos.BOTTOM_CENTER);
// Set the alignment of the Left Text to Center
BorderPane.setAlignment(leftText, Pos.CENTER_LEFT);
// Set the alignment of the Right Text to Center
BorderPane.setAlignment(rightText, Pos.CENTER_RIGHT);
// Create a BorderPane with a Text node in each of the five regions
BorderPane root = new BorderPane(vbox, pane, rightText, bottomText,
leftText);
// Set the Size of the VBox
root.setPrefSize(600, 600);
// Set the Style-properties of the BorderPane
root.setStyle("-fx-padding: 10;" + "-fx-border-style: solid inside;"
+ "-fx-border-width: 2;" + "-fx-border-insets: 5;"
+ "-fx-border-radius: 5;" + "-fx-border-color: blue;");
// Create the Scene
Scene scene = new Scene(root);
// Add the scene to the Stage
stage.setScene(scene);
// Set the title of the Stage
stage.setTitle("A simple BorderPane Example");
// Display the Stage
stage.show();
submit.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
int employeId = -1;
double basePayout = -1.1;
double workedHours = -1.1;
double payAmount = -1.1;
try {
employeId = Integer.parseInt(employIDText.getText());
} catch (Exception e1) {
JOptionPane.showMessageDialog(null,
"Employee ID should be an Integer");
}
try {
basePayout = Double.parseDouble(basePayoutText.getText());
} catch (Exception e1) {
JOptionPane.showMessageDialog(null,
"Please enter valid basePayout as a double");
return;
}
try {
workedHours = Double.parseDouble(workeedHourText.getText());
if (workedHours < 4) {
JOptionPane.showMessageDialog(null,
"Hours Worked should not be less than 4.");
return;
} else if (workedHours > 4 && workedHours <= 40) {
if (basePayout < 8.25) {
JOptionPane
.showMessageDialog(null,
"Base Pay should not be below the minimum wage allowed i.e $8.25 .");
} else {
basePayout = 8.25;
payAmount = basePayout * workedHours;
}
} else if (workedHours > 40) {
if (workedHours > 60) {
workedHours = 60;
}
payAmount = basePayout * 40;
basePayout = basePayout + (basePayout * 1.50) / 100;
payAmount = payAmount + basePayout * (workedHours - 40);
JOptionPane
.showMessageDialog(
null,
"Payout will only be made for 60 hours as given worked hours are greater than 60 .");
}
} catch (Exception e1) {
JOptionPane.showMessageDialog(null,
"Please enter valid workedHours as a double");
}
EmployeeWorkHoursBean employee = new EmployeeWorkHoursBean(
employeId, basePayout, workedHours, payAmount);
employeeList.add(employee);
}
});
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.