Advertisement
Skootiebae

Lab 4

Dec 11th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. public class Lab4 {
  2. public static void main (String[] args)
  3. {
  4.  
  5.  
  6. Staff personnel = new Staff();
  7.  
  8. personnel.payWeek();
  9.  
  10.  
  11. }//Main
  12. }
  13.  
  14. abstract class StaffMember {
  15. protected String name;
  16. protected String payClass;
  17.  
  18.  
  19. public StaffMember (String eName, String ePayClass)
  20. {
  21. name = eName;
  22. payClass = ePayClass;
  23. }
  24.  
  25. public String toString()
  26. {
  27. String result = "Name: " + name + "Class: " + payClass;
  28. return result;
  29. }
  30.  
  31.  
  32. public abstract double pay();
  33. }
  34.  
  35. public class Staff {
  36. private StaffMember[] staffList;
  37.  
  38.  
  39. //Create loop that feeds in user input data
  40.  
  41. public Staff ()
  42. {
  43. staffList = new StaffMember[5];
  44. staffList[0] = new Hourly("Anthony","Hourly","16.00");
  45. staffList[1] = new Employee("Juan","Salary","1600.00");
  46. staffList[2] = new Hourly("Mana","Hourly","32.00");
  47. staffList[3] = new Hourly("Felicia","Hourly","16.00");
  48. staffList[4] = new Hourly("Antonio","Salary","2800.00");
  49. }
  50.  
  51. public void payWeek()
  52. {
  53. double amount;
  54.  
  55.  
  56. for (int count=0; count < staffList.length; count++)
  57. {
  58. System.out.println (staffList[count]);
  59. amount = staffList[count].pay();
  60.  
  61. if (amount == 0.00)
  62. System.out.println("Thanks!");
  63. else
  64. System.out.println("Paid: " + amount);
  65. System.out.println("-----------------------------------------------------------");
  66.  
  67. }
  68. }//payWeek
  69. }
  70.  
  71.  
  72. public class Employee extends StaffMember {
  73. protected double payRate;
  74.  
  75. public Employee (String eName, String ePayClass, double rate)
  76. {
  77. super (eName, ePayClass);
  78. payRate= rate;
  79. }
  80.  
  81. public String toString()
  82. {
  83. String result = super.toString();
  84.  
  85. result += "Rate: " + payRate;
  86. return result;
  87. }
  88.  
  89. public double pay()
  90. {
  91. return payRate;
  92. }
  93. }
  94.  
  95. public class Hourly extends Employee {
  96.  
  97. private int hoursWorked;
  98.  
  99.  
  100. public Hourly(String eName, String ePayClass, double rate)
  101. {
  102. super (eName, ePayClass, rate);
  103. hoursWorked = 0;
  104. }
  105.  
  106.  
  107. public void addHours(int moreHours)
  108. {
  109. hoursWorked += moreHours;
  110. }
  111.  
  112.  
  113.  
  114. public double pay()
  115. {
  116. double weeksPaycheck = payRate * hoursWorked;
  117. hoursWorked = 0;
  118.  
  119. return weeksPaycheck;
  120. }
  121.  
  122.  
  123.  
  124.  
  125. public String toString()
  126. {
  127. String result = super.toString();
  128.  
  129. result += "Hours: "+ hoursWorked + "\t Rate: " +payRate;
  130. return result;
  131. }
  132. }
  133.  
  134.  
  135. //Commissoned employee STILL IN PROGRESS
  136. public class Commission extends Employee
  137. {
  138.  
  139.  
  140. Private double percentage;
  141.  
  142. public Employee (String eName, String ePayClass, double rate)
  143. {
  144. super (eName, ePayClass, payRate);
  145. percentage = 0;
  146. }
  147.  
  148.  
  149. //Commissioned Employees get 20% of their sales
  150. public double getCommission()
  151. {
  152. double commission = payRate * 0.20;
  153.  
  154.  
  155. return commission;
  156. }
  157.  
  158.  
  159.  
  160.  
  161. public String toString()
  162. {
  163. String result = super.toString();
  164.  
  165. result += "\sHours: "+ hours +"\sRate: " + rate;
  166. return result;
  167. }
  168.  
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement