Advertisement
coffeebeforecode

rujulCatJava

Feb 24th, 2022
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. package temp;
  2.  
  3. import java.util.*;
  4.  
  5. public class RujulCAT {
  6.  
  7. public static void main(String[] args) {
  8. Scanner sc = new Scanner(System.in);
  9. // 3 chefs and 3 waiter
  10. ArrayList<Chef> chefs = new ArrayList<Chef>();
  11. ArrayList<Waiter> waiters = new ArrayList<Waiter>();
  12.  
  13. System.out.println("Creating chefs:");
  14. for(int i = 0; i < 3; i++) {
  15. chefs.add(new Chef());
  16. }
  17.  
  18. System.out.println("Creating waiters:");
  19. for(int i = 0; i < 3; i++) {
  20. waiters.add(new Waiter());
  21. }
  22.  
  23. // printing name and salary for chefs
  24. System.out.println("Chefs:");
  25.  
  26. for(Chef c : chefs) {
  27. System.out.println("\nName: " + c.getName() + "\nSalary: " + c.getSalary());
  28. }
  29.  
  30. // printing name and salary for waiters
  31. System.out.println("Waiters:");
  32.  
  33. for(Waiter w : waiters) {
  34. System.out.println("\nName: " + w.getName() + "\nSalary: " + w.getSalary());
  35. }
  36. sc.close();
  37. }
  38.  
  39. }
  40.  
  41. abstract class Worker{
  42. private String name;
  43. private String number;
  44. protected double salary;
  45. abstract void computeSalary();
  46.  
  47. public void setName(String name) {
  48. this.name = name;
  49. }
  50.  
  51. public void setNumber(String number) {
  52. this.number = number;
  53. }
  54.  
  55. public String getName() {
  56. return name;
  57. }
  58.  
  59. public String getNumber() {
  60. return number;
  61. }
  62.  
  63. public double getSalary() {
  64. return salary;
  65. }
  66.  
  67. }
  68.  
  69. class Chef extends Worker{
  70. private String certificate;
  71. private double basicPay;
  72. private double houseRent;
  73. private double dearness;
  74.  
  75. @Override
  76. void computeSalary() {
  77. this.houseRent = this.basicPay*0.20;
  78. this.dearness = this.basicPay*0.28;
  79. this.salary = this.basicPay + this.houseRent + this.dearness;
  80. }
  81.  
  82. public void setCertificate(String certificate) {
  83. this.certificate = certificate;
  84. }
  85.  
  86. public void setBasicPay(double basicPay) {
  87. this.basicPay = basicPay;
  88. }
  89.  
  90. public Chef() {
  91. Scanner chef_sc = new Scanner(System.in);
  92. System.out.println("Input Name:");
  93. setName(chef_sc.nextLine());
  94. System.out.println("Input mobile number:");
  95. setNumber(chef_sc.nextLine());
  96. System.out.println("Input Certificate number:");
  97. setCertificate(chef_sc.nextLine());
  98. System.out.println("Input base pay:");
  99. setBasicPay(chef_sc.nextDouble());
  100. chef_sc.nextLine();
  101. computeSalary();
  102. }
  103. }
  104.  
  105. class Waiter extends Worker{
  106. private String id;
  107. private int numDaysWorked;
  108.  
  109. @Override
  110. void computeSalary() {
  111. this.salary = 40000 + this.numDaysWorked*200;
  112. }
  113.  
  114. public void setId(String id) {
  115. this.id = id;
  116. }
  117.  
  118. public void setNumDaysWorked(int numDaysWorked) {
  119. this.numDaysWorked = numDaysWorked;
  120. }
  121.  
  122. public Waiter() {
  123. Scanner waiter_sc = new Scanner(System.in);
  124. System.out.println("Input Name:");
  125. setName(waiter_sc.nextLine());
  126. System.out.println("Input mobile number:");
  127. setNumber(waiter_sc.nextLine());
  128. System.out.println("Input id:");
  129. setId(waiter_sc.nextLine());
  130. System.out.println("Input number of days worked:");
  131. setNumDaysWorked(waiter_sc.nextInt());
  132. waiter_sc.nextLine();
  133. computeSalary();
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement