Posted By


trusktr on 10/15/10

Tagged


Statistics


Viewed 681 times
Favorited by 0 user(s)

cisp401 PayrollApp.java


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. import java.io.*;
  2.  
  3. public class PayrollApp {
  4.  
  5. // Data Objects (
  6. private Employees empTable;
  7. private static final MyString REPORT_HEADER_A = new MyString("Employee Pay Hours Gross Tax Net");
  8. private static final MyString REPORT_HEADER_B = new MyString("Name Rate Worked Pay Amount Pay");
  9. private static final MyString REPORT_HEADER_C = new MyString("====================== ======== ========== ========== ========== ==========");
  10. private static final MyString WORD_TOTALS = new MyString("Totals:");
  11. private static final MyString WORD_AVERAGES = new MyString("Averages:");
  12. // )
  13. // Constructors (
  14. public PayrollApp() {
  15. empTable = new Employees();
  16. }
  17. public PayrollApp(HourlyEmployee e) {
  18. empTable = new Employees(e);
  19. }
  20. public PayrollApp(PiecedEmployee e) {
  21. empTable = new Employees(e);
  22. }
  23. public PayrollApp(SalariedEmployee e) {
  24. empTable = new Employees(e);
  25. }
  26. public PayrollApp(Employees e) {
  27. empTable = e;
  28. }
  29. public PayrollApp(File file) {
  30. empTable = new Employees(file);
  31. }
  32. // )
  33. // Accessors (
  34. public Employees getEmps() {
  35. return new Employees(empTable);
  36. }
  37. // )
  38. // Mutators (
  39. public MyString tableHeader() {
  40. return new MyString(" " + REPORT_HEADER_A + "\n " + REPORT_HEADER_B + "\n " + REPORT_HEADER_C);
  41. }
  42. public MyString[] tableRows() {
  43. MyString[] rows = new MyString[empTable.size()];
  44. for (int i=0; i<empTable.size(); i++) {
  45. HourlyEmployee e = (HourlyEmployee)empTable.employee(i);
  46. rows[i] = new MyString(" " + e.formattedName().left(22) + " " + e.payRate().myString(2).right(8) + " " + e.hours().myString(2).right(10) + " " + e.grossPay().myString(2).right(10) + " " + e.taxAmount().myString(2).right(10) + " " + e.netPay().myString(2).right(10));
  47. }
  48. return rows;
  49. }
  50. public Number totalPayRate() {
  51. Number total = new Number();
  52. for (int i=0; i<empTable.size(); i++) {
  53. total = total .plus (((HourlyEmployee)empTable.employee(i)).payRate());
  54. }
  55. return total;
  56. }
  57. public Number totalHours() {
  58. Number total = new Number();
  59. for (int i=0; i<empTable.size(); i++) {
  60. total = total .plus (((HourlyEmployee)empTable.employee(i)).hours());
  61. }
  62. return total;
  63. }
  64. public Number totalGross() {
  65. Number total = new Number();
  66. for (int i=0; i<empTable.size(); i++) {
  67. total = total .plus (empTable.employee(i).grossPay());
  68. }
  69. return total;
  70. }
  71. public Number totalTax() {
  72. Number total = new Number();
  73. for (int i=0; i<empTable.size(); i++) {
  74. total = total .plus (empTable.employee(i).taxAmount());
  75. }
  76. return total;
  77. }
  78. public Number totalNet() {
  79. Number total = new Number();
  80. for (int i=0; i<empTable.size(); i++) {
  81. total = total .plus (empTable.employee(i).netPay());
  82. }
  83. return total;
  84. }
  85. public Number avgPayRate() {
  86. return totalPayRate() .over (empTable.size());
  87. }
  88. public Number avgHours() {
  89. return totalHours() .over (empTable.size());
  90. }
  91. public Number avgGross() {
  92. return totalGross() .over (empTable.size());
  93. }
  94. public Number avgTax() {
  95. return totalTax() .over (empTable.size());
  96. }
  97. public Number avgNet() {
  98. return totalNet() .over (empTable.size());
  99. }
  100. public MyString totalsRow() {
  101. return new MyString(" " + WORD_TOTALS.left(22) + " " + totalPayRate().myString(2).right(8) + " " + totalHours().myString(2).right(10) + " " + totalGross().myString(2).right(10) + " " + totalTax().myString(2).right(10) + " " + totalNet().myString(2).right(10));
  102. }
  103. public MyString averagesRow() {
  104. return new MyString(" " + WORD_AVERAGES.left(22) + " " + avgPayRate().myString(2).right(8) + " " + avgHours().myString(2).right(10) + " " + avgGross().myString(2).right(10) + " " + avgTax().myString(2).right(10) + " " + avgNet().myString(2).right(10));
  105. }
  106. // )
  107. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.