Advertisement
rushdie

הורשות תרגילים 1 ו 2

Dec 11th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. package test;
  2.  
  3. public class Employee {
  4.  
  5. protected String _EmpName;
  6. protected int _EmpNum;
  7. protected double _Salary;
  8.  
  9. /** Employee Constructor
  10. * @param _EmpName //holds Employee Name
  11. * @param _EmpNum //hold Employee ID number
  12. * @param _Salary //hold Beginning Salary
  13. */
  14. public Employee(String _EmpName, int _EmpNum, double _Salary) {
  15. super();
  16. this._EmpName = _EmpName;
  17. this._Salary = _Salary;
  18. if (_EmpNum > 1000) { // If Employee number < 1000 set it to 1000
  19. this._EmpNum = _EmpNum;
  20. } else {
  21. this._EmpNum = 1000;
  22. }
  23.  
  24. }
  25. //Method that Calculate the Bonus for either Programmer or Secretary
  26. public double CalcBonus(double PBonusR) {
  27. if (PBonusR < 10) { // Rate is percent if its less than 100%
  28. _Salary = this._Salary * PBonusR; //Calculate using the Programmer function
  29. } else {
  30. _Salary = this._Salary + Secratry.getSBonusR();
  31. }
  32. return this._Salary; // Return calculated Salary with Bonus
  33. }
  34. //Method to update bonus for Either a Programmer or a Secretary
  35. public double UpdateSalary(double NewRate) {
  36.  
  37. if (Pragrammer.setPBonusR(NewRate) < 10) { // Set new rate to programmer
  38. CalcBonus(Pragrammer.setPBonusR(NewRate));
  39. } else { // its a Secretary bonus
  40. CalcBonus(Secratry.setSBonusR(NewRate));
  41. }
  42. return NewRate;
  43. }
  44.  
  45. //Getter and Setters for All Parameters of the Class
  46. public String get_EmpName() {
  47. return _EmpName;
  48. }
  49.  
  50. public void set_EmpName(String _EmpName) {
  51. this._EmpName = _EmpName;
  52. }
  53.  
  54. public int get_EmpNum() {
  55. return _EmpNum;
  56. }
  57.  
  58. public void setENum(int _EmpNum) {
  59. this._EmpNum = _EmpNum;
  60.  
  61. }
  62.  
  63. public double get_Salary() {
  64. return _Salary;
  65. }
  66.  
  67. public void set_Salary(double _Salary) {
  68. this._Salary = _Salary;
  69. }
  70. // Method to print Employee before applying any Bonus or Updated bonuses
  71. @Override
  72. public String toString() {
  73. return "Employee [_EmpName=" + _EmpName + ", _EmpNum=" + _EmpNum + ", _Salary=" + _Salary + "]";
  74. }
  75. package test;
  76.  
  77. public class employeeTester {
  78.  
  79. public static void main(String[] args) {
  80. Pragrammer P1 = new Pragrammer("BeeGee", 900, 6000, 0);
  81. Secratry S1 = new Secratry("Lola", 1005, 5000, 0, 0);
  82. System.out.println("============== No Bonus for any================");
  83.  
  84. System.out.println(P1.toString());
  85. System.out.println(S1.toString());
  86.  
  87. // after we assign employee bonuses
  88. P1.CalcBonus(Pragrammer.setPBonusR(2.0));
  89. System.out.println("==============Bonus 2.0%================");
  90. System.out.println(P1.toString());
  91.  
  92. S1.CalcBonus(Secratry.setSBonusR(1000));
  93. System.out.println("==============Bonus $1000================");
  94. System.out.println(S1.toString());
  95.  
  96. //after we assign Words per Minute typing speed
  97. S1.setWordPerMin(80);
  98. System.out.println("==============Set Typing Speed for Secratry================");
  99. System.out.println(S1.toString());
  100.  
  101. P1.UpdateSalary(3.0);
  102. System.out.println("==============Updated Rate to 3.0%================");
  103.  
  104. System.out.println(P1.toString());
  105.  
  106. S1.UpdateSalary(1500);
  107. System.out.println("==============Updated Bonus $1500.00================");
  108.  
  109. System.out.println(S1.toString());
  110.  
  111. }
  112. }
  113. package test;
  114.  
  115. public class Pragrammer extends Employee {
  116. private static double PBonusR;
  117. //private static double Programmer Bonus Rate;
  118.  
  119. // Getter for Programmer Bonus Rate
  120. public static double getPBonusR() {
  121. return PBonusR;
  122. }
  123.  
  124. // Setter for Programmer Bonus Rate
  125. public static double setPBonusR(double pBonusR) {
  126. return PBonusR = pBonusR;
  127. }
  128. /** Programmer Constructor
  129. * @param _EmpName //holds Employee Name
  130. * @param _EmpNum //hold Employee ID number
  131. * @param _Salary //hold Beginning Salary
  132. */
  133. public Pragrammer(String _EmpName, int _EmpNum, double _Salary, double PBonusR) {
  134. super(_EmpName, _EmpNum, _Salary);
  135. PBonusR = Pragrammer.PBonusR;
  136. // set programmer Bonus Parameter to Input%
  137. }
  138.  
  139. // Method to print Programmer with Bonuses if any applied
  140. @Override
  141. public String toString() {
  142. return "Pragrammer [_EmpName=" + _EmpName + ", _EmpNum=" + _EmpNum + ", _Salary=" + _Salary + " Bonus: "
  143. + PBonusR + "%" + "]";
  144. }
  145.  
  146. }
  147. package test;
  148.  
  149. public class Secratry extends Employee {
  150. private int WordPerMin; //Parameters that holds Number of typing speed Rate
  151. private static double SBonusR; //Parameter that hold Bonus Rate
  152.  
  153. /** Secretary Constructor
  154. * @param _EmpName //holds Employee Name
  155. * @param _EmpNum //hold Employee ID number
  156. * @param _Salary //hold Beginning Salary
  157. */
  158. public Secratry(String _EmpName, int _EmpNum, double _Salary, int WordPerMin, double SBonusR) {
  159. super(_EmpName, _EmpNum, _Salary);
  160. this.WordPerMin = WordPerMin;
  161. Secratry.SBonusR = SBonusR;
  162. //Secretary set Rate(SBonusR);
  163. }
  164. //Getter for Secretary Bonus Rate
  165. public static double getSBonusR() {
  166. return SBonusR;
  167. }
  168. //Setter for Secretary Bonus Rate
  169. public static double setSBonusR(double sBonusR) {
  170. return SBonusR = sBonusR;
  171. }
  172. //Getter for Secretary Words Per Minutes Rate
  173. public int getWordPerMin() {
  174. return WordPerMin;
  175. }
  176. //Setter for Secretary Words Per Minutes Rate
  177. public void setWordPerMin(int wordPerMin) {
  178. WordPerMin = wordPerMin;
  179. }
  180. // Method to print Secretary with Bonuses and WPM typing speed if any applied
  181. @Override
  182. public String toString() {
  183. return "Secratry [WordPerMin=" + WordPerMin + ", _EmpName=" + _EmpName + ", _EmpNum=" + _EmpNum + ", _Salary="
  184. + _Salary + " Typing W.P.M " + "Rate =" + getWordPerMin() + " Bonus of Set Amount of $" + SBonusR + "]";
  185. }
  186.  
  187. }
  188.  
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement