Posted By

trusktr on 11/18/10


Tagged


Versions (?)

CISP401 HourlyEmployee.java


 / Published in: Java
 

  1. import java.util.*;
  2.  
  3. public class HourlyEmployee extends Employee {
  4.  
  5. // Data Objects (
  6. private static final double OVERTIME_FACTOR = 1.5;
  7. public Number hours, payrate;
  8. // )
  9. // Constructors (
  10. public HourlyEmployee() { //default
  11. super();
  12. hours = new Number(0);
  13. payrate = new Number(0);
  14. }
  15. public HourlyEmployee(String f, String l, double hrs, double pr) { //param
  16. super(f, l);
  17. hours = new Number(hrs);
  18. payrate = new Number(pr);
  19. }
  20. public HourlyEmployee(MyString f, MyString l, Number hrs, Number pr) { //param
  21. super(f, l);
  22. hours = new Number(hrs);
  23. payrate = new Number(pr);
  24. }
  25. public HourlyEmployee(EmployeeData d) { // basic info set, no payrate or hours
  26. super(d);
  27. hours = new Number(0);
  28. payrate = new Number(0);
  29. }
  30. public HourlyEmployee(HourlyEmployee e) { // copy
  31. super(e.info());
  32. hours = new Number(e.hours());
  33. payrate = new Number(e.payRate());
  34. }
  35. // )
  36. // Accessors (
  37. public Number hours() {
  38. return new Number(hours);
  39. }
  40. public Number payRate() {
  41. return new Number(payrate);
  42. }
  43. // )
  44. // Mutators (
  45. public Number regHours() {
  46. Number regHrs = new Number();
  47. if(hours.value() <= 40){
  48. regHrs.set_value(hours);
  49. }
  50. else if(hours.value() > 40){
  51. regHrs.set_value(40);
  52. }
  53. return regHrs;
  54. }
  55. public Number ovrHours() {
  56. Number ovrHrs = new Number();
  57. if(hours.value() <= 40){
  58. ovrHrs.set_value(0);
  59. }
  60. else if(hours.value() > 40){
  61. ovrHrs = hours .minus (40);
  62. }
  63. return ovrHrs;
  64. }
  65. public Number grossPay() {
  66. return regHours() .times (payRate()) .plus ( ovrHours() .times (OVERTIME_FACTOR) .times (payRate()) );
  67. }
  68. // )
  69. }

Report this snippet  

You need to login to post a comment.