Advertisement
Naimul_X

JAVA ARRAY PROBLEM

Mar 14th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1.  
  2. package labtest;
  3.  
  4. class Employee
  5.  
  6.  
  7. public class Employee {
  8. protected String name;
  9. protected double salary;
  10.  
  11. Employee() {
  12. this.name = "Unknown";
  13. }
  14. Employee(String name) {
  15. this.name = name;
  16. }
  17. public int getHours() {
  18. return 40; // works 40 hours / week
  19. }
  20.  
  21. public double getSalary() {
  22. return 40000.0; // $40,000.00 / year
  23. }
  24.  
  25. public int getVacationDays() {
  26. return 10; // 2 weeks' paid vacation
  27. }
  28.  
  29. public String getVacationForm() {
  30. return "yellow"; // use the yellow form
  31. }
  32. }
  33. class HarvardLawyer
  34.  
  35.  
  36.  
  37. package labtest;
  38.  
  39.  
  40. public class HarvardLawyer extends Employee{
  41. @Override
  42. public int getVacationDays() {
  43. return super.getVacationDays() + 3; // 3 weeks vacation
  44. }
  45. @Override
  46. public String getVacationForm() {
  47. return super.getVacationForm() + super.getVacationForm();
  48. }
  49. @Override
  50. public double getSalary() {
  51. double x;
  52. x= (super.getSalary() * 20/100);
  53. return super.getSalary()+x; // 20% more make salary / year
  54. }
  55.  
  56. }
  57. class Lawyer
  58.  
  59.  
  60. package labtest;
  61.  
  62.  
  63. public class Lawyer extends Employee{
  64. @Override
  65. public int getVacationDays() {
  66. return super.getVacationDays() + 5; // 3 weeks vacation
  67. }
  68.  
  69. @Override
  70. public String getVacationForm() {
  71. return "pink";
  72. }
  73.  
  74. public void sue() {
  75. System.out.println("I'll see you in court!");
  76. }
  77. }
  78.  
  79. class LegalSecretary
  80.  
  81. package labtest;
  82.  
  83.  
  84. public class LegalSecretary extends Secretary {
  85. @Override
  86. public double getSalary() {
  87. return super.getSalary() + 5000.0; // $45,000.00 / year
  88. }
  89.  
  90. public void fileLegalBriefs() {
  91. System.out.println("I could file all day!");
  92. }
  93. }
  94. class Manager
  95.  
  96. package labtest;
  97.  
  98.  
  99. public class Manager extends Employee {
  100. Employee employees[];
  101.  
  102. Manager(String name) {
  103. super(name);
  104. this.employees = new Employee[4];
  105. }
  106. public void manage() {
  107. System.out.println("Follow my order");
  108. }
  109. @Override
  110. public double getSalary() {
  111. int i;
  112. double sum=0;
  113. for(i=0;i<employees.length;i++)
  114. {
  115. sum = sum+employees[i].salary;
  116. }
  117. return sum; // Write your code here
  118. }
  119. }
  120. class Secretary
  121.  
  122. package labtest;
  123.  
  124.  
  125. public class Secretary extends Employee{
  126. public void takeDictation(String text) {
  127. System.out.println("Taking dictation of text: " + text);
  128. }
  129. }
  130.  
  131. Main Class........
  132.  
  133. package labtest;
  134.  
  135. import java.util.Random;
  136.  
  137. public class Test {
  138. public static void main(String[] args) {
  139. Manager managers[] = new Manager[2];
  140. managers[0] = new Manager("Pele");
  141. managers[1] = new Manager("Zidane");
  142.  
  143. managers[0].employees[0] = new Employee("Mbappe");
  144. managers[0].employees[1] = new Employee("Ronaldo");
  145. managers[0].employees[2] = new Employee("Ballack");
  146. managers[0].employees[3] = new Employee("Messi");
  147. managers[1].employees[0] = new Employee("Kylian");
  148. managers[1].employees[1] = new Employee("Cristiano");
  149. managers[1].employees[2] = new Employee("Michael");
  150. managers[1].employees[3] = new Employee("Lionel");
  151.  
  152. Random random = new Random();
  153.  
  154. for(int i =0; i<2; i++){
  155. for (int j=0; j<4; j++) {
  156. int randomMark = random.nextInt(100000);
  157. managers[i].employees[j].salary = randomMark; // randomMark is an integer from 0 to 99999
  158. // assign mark to the jth Employee of ith Manager here
  159. System.out.print(randomMark + " ");
  160. }
  161. System.out.println();
  162. }
  163.  
  164. System.out.println(managers[0].getSalary());
  165. System.out.println(managers[1].getSalary());
  166. }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement