Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1.  
  2. public class Solution
  3. {
  4. public static void main(String[] args)
  5. {
  6. Solution solution = new Solution();
  7. Programmer pupkin = solution.new Programmer();
  8. pupkin.setHoursWorked(150);
  9. pupkin.setSalaryPerMonth(2000);
  10.  
  11. Manager vasia = solution.new Manager();
  12. vasia.hoursWorked = 170;
  13. vasia.salaryPerMonth = 1500;
  14.  
  15. Programmer vova = solution.new Programmer();
  16. vova.hoursWorked = 195;
  17. vova.salaryPerMonth = 2200;
  18.  
  19. Manager ffuuu = solution.new Manager();
  20. vasia.hoursWorked = 80;
  21. vasia.salaryPerMonth = 1000;
  22.  
  23. Booker petrovna = new Booker();
  24. System.out.println("manager vasia: " + petrovna.payroll(vasia));
  25. System.out.println("manager ffuuu: " + petrovna.payroll(ffuuu));
  26. System.out.println("programmer vova: " + petrovna.payroll(vova));
  27. System.out.println("programmer pupkin: " + petrovna.payroll(pupkin));
  28. }
  29.  
  30. abstract class Worker
  31. {
  32. public int salaryPerMonth;
  33. public int hoursWorked;
  34. private int needHours = 168;
  35.  
  36. public void setSalaryPerMonth(int salaryPerMonth)
  37. {
  38. this.salaryPerMonth = salaryPerMonth;
  39. }
  40.  
  41. public void setHoursWorked(int hoursWorked)
  42. {
  43. this.hoursWorked = hoursWorked;
  44. }
  45.  
  46. public double percentage()
  47. {
  48. double percentage = (double) hoursWorked / (double) needHours;
  49. return percentage;
  50. }
  51.  
  52. public int salary()
  53. {
  54. int salary = (int) (percentage() * salaryPerMonth);
  55. return salary;
  56. }
  57. }
  58.  
  59. class Programmer extends Worker
  60. {
  61.  
  62. }
  63.  
  64. class Manager extends Worker
  65. {
  66. public int salary()
  67. {
  68. int salary = (int) (percentage() * salaryPerMonth);
  69. if (salary > salaryPerMonth) return salaryPerMonth;
  70. else return salary;
  71. }
  72. }
  73.  
  74. static class Booker
  75. {
  76.  
  77. public int payroll(Worker name)
  78. {
  79. return name.salary();
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement