Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. public interface SalaryBusiness {
  2.  
  3. double getSalary();
  4. }
  5.  
  6. public class SalaryCalculator implements SalaryBusiness {
  7.  
  8. // Some shared fileds, useful for the calculation....
  9.  
  10. // A public constructor
  11. public SalaryCalculator()
  12. {
  13. }
  14.  
  15. protected SalaryCalculator(Object anObject)
  16. {
  17.  
  18. // the anObject is useful to init the shared fileds
  19. initFields(anObject)
  20. }
  21. //Method that creat a Regime
  22. public final SalaryCalculator getRegimeCalculator(Object anObject)
  23. {
  24. if (newRegimeCalculator.equals(anObject.getRegime))
  25. {
  26. return new newRegimeCalculator(anObject);
  27. }else {
  28.  
  29. NewRegimeCalculator newRegimeCalcultor = new NewRegimeCalculator(anObject);
  30. OldRegimeCalculator oldRegimeCalculator = new OldRegimeCalculator(anObject);
  31. oldRegimeCalculator.setTauxNr = newRegime.getSalary();
  32. return oldRegimeCalculator
  33. }
  34.  
  35. @override
  36. public double getSalary()
  37. {
  38. return 0.0d;
  39. }
  40.  
  41. }
  42.  
  43. public class NewRegimeCalculator extends SalaryCalculator {
  44.  
  45. // Special fileds...
  46.  
  47. // Procted constructor
  48. proctected NewRegimeCalculator(Object anObject) {
  49. super(anObject);
  50. }
  51.  
  52. @override
  53. public double getSalary()
  54. {
  55. double salary = 0.0d;
  56. //Traitements....
  57. return salary;
  58. }
  59. }
  60.  
  61.  
  62.  
  63. public class OldRegimeCalculator extends SalaryCalculator {
  64.  
  65. // Field holding the newRegime salary
  66. double tauxNr = 0.0d;
  67. // Special fileds...
  68.  
  69. // Procted constructor
  70. proctected OldRegimeCalculator(Object anObject) {
  71. super(anObject);
  72. }
  73.  
  74. @override
  75. public double getSalary()
  76. {
  77. double salary = 0.0d;
  78. //Traitements....
  79. if (tauxNr>salary)
  80. {
  81. return tauxNr;
  82. }
  83. else {
  84. return salary;
  85. }
  86. }
  87.  
  88. public classWantToGetTheSalary {
  89.  
  90. Object anObject;
  91. double salary;
  92. SalaryCalculator regimeCalculator = new SalaryCalculator().getRegimeCalculator(anObject);
  93.  
  94. //Here is our salary
  95. salary = regimeCalculator.getSalary();
  96.  
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement