Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void btnCalculateActionPerformed(java.awt.event.ActionEvent evt) {
- SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMMM-yyyy, hh:mm:ss");
- Date date = new Date();
- String basicSalary = fmtBasic.getText();
- double basic = 0.00;
- double hours = (Double)spnHours.getValue();
- String department = (String)cboDept.getSelectedItem();
- String id = fmtId.getText();
- String name = txtName.getText();
- double total = 0.00;
- double rate = 0.00;
- if( fmtId.getText().trim().length() != 4 ){
- // tarMessage.setText("Invalid input(s)\n\n");
- tarMessage.append("-[Staff ID must not empty]\n");
- }else if( txtName.getText().trim().length() < 4 || txtName.getText().trim().length() > 20 ){
- tarMessage.append("-[Name] must not more than 20 chars\n");
- }else if( cboDept.getSelectedIndex() == 0 ){
- tarMessage.append("-[Department] must be selected\n");
- }else if( fmtBasic.getText().trim().length() < 1 ){
- tarMessage.append("-[Basic Salary] must not empty\n");
- }else{
- basic = Double.parseDouble( fmtBasic.getText() );
- if( basic < 1000 || basic > 5000 ){
- tarMessage.append("[Basic Salary] must be between RM1000 - RM5000\n");
- }else{
- // calculate salary
- if( hours <= 20 ){
- rate = 20.00 * hours;
- }else{
- rate = (20.00 * 20) + 30.00 * (hours - 20);
- }
- total = basic + rate;
- tarMessage.setText("Salary for Mr. " + name + " (" + id + ")\n"
- + "from " + department + ":\n\n"
- + "Basic Salary = RM " + basic + "\n"
- + "OT Claims = RM " + hours + "\n"
- + "Total Salary = RM " + total + "\n\n"
- + "As on " + dateFormat.format( date) );
- error = false;
- }
- }
- error = true;
- }
Advertisement
Add Comment
Please, Sign In to add comment