yuhsing

Untitled

Dec 5th, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1.  
  2.  
  3.  
  4. private void btnCalculateActionPerformed(java.awt.event.ActionEvent evt) {
  5. SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMMM-yyyy, hh:mm:ss");
  6. Date date = new Date();
  7. String basicSalary = fmtBasic.getText();
  8. double basic = 0.00;
  9. double hours = (Double)spnHours.getValue();
  10. String department = (String)cboDept.getSelectedItem();
  11. String id = fmtId.getText();
  12. String name = txtName.getText();
  13. double total = 0.00;
  14. double rate = 0.00;
  15.  
  16. if( fmtId.getText().trim().length() != 4 ){
  17. // tarMessage.setText("Invalid input(s)\n\n");
  18. tarMessage.append("-[Staff ID must not empty]\n");
  19. }else if( txtName.getText().trim().length() < 4 || txtName.getText().trim().length() > 20 ){
  20. tarMessage.append("-[Name] must not more than 20 chars\n");
  21. }else if( cboDept.getSelectedIndex() == 0 ){
  22. tarMessage.append("-[Department] must be selected\n");
  23. }else if( fmtBasic.getText().trim().length() < 1 ){
  24. tarMessage.append("-[Basic Salary] must not empty\n");
  25. }else{
  26. basic = Double.parseDouble( fmtBasic.getText() );
  27. if( basic < 1000 || basic > 5000 ){
  28. tarMessage.append("[Basic Salary] must be between RM1000 - RM5000\n");
  29. }else{
  30. // calculate salary
  31. if( hours <= 20 ){
  32. rate = 20.00 * hours;
  33. }else{
  34. rate = (20.00 * 20) + 30.00 * (hours - 20);
  35. }
  36. total = basic + rate;
  37.  
  38. tarMessage.setText("Salary for Mr. " + name + " (" + id + ")\n"
  39. + "from " + department + ":\n\n"
  40. + "Basic Salary = RM " + basic + "\n"
  41. + "OT Claims = RM " + hours + "\n"
  42. + "Total Salary = RM " + total + "\n\n"
  43. + "As on " + dateFormat.format( date) );
  44.  
  45. error = false;
  46.  
  47. }
  48. }
  49. error = true;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment