Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.70 KB | None | 0 0
  1. package workforce;
  2.  
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class WorkForce {
  7.  
  8. static class Person
  9. {
  10. String name;
  11. String email;
  12. int age;
  13.  
  14. public Person(){}
  15.  
  16. public Person(String name, String email, int age)
  17. {
  18. this.name = name;
  19. this.email = email;
  20. this.age = age;
  21. }
  22.  
  23. public void Identify()
  24. {
  25. System.out.println("Name " + name);
  26. System.out.println("Email: " + email);
  27. System.out.println("Age: " + age);
  28. }
  29.  
  30. public String getName()
  31. {
  32. return name;
  33. }
  34.  
  35. public String getEmail()
  36. {
  37. return email;
  38. }
  39.  
  40. public int getAge()
  41. {
  42. return age;
  43. }
  44.  
  45.  
  46. }
  47.  
  48. interface Worker
  49. {
  50. int getSalary();
  51. }
  52.  
  53. interface AcademicInterest
  54. {
  55. String getInterest();
  56. }
  57.  
  58. static class Student extends Person implements AcademicInterest
  59. {
  60. int avgrade;
  61. String interest;
  62. public Student(String name, String email, int age, int avgrade, String interest)
  63. {
  64. super(name, email, age);
  65.  
  66. this.avgrade = avgrade;
  67. this.interest = interest;
  68. }
  69.  
  70. @Override
  71. public String getInterest() {
  72. return interest;
  73. }
  74.  
  75. public int getAvgrade()
  76. {
  77. return avgrade;
  78. }
  79. }
  80.  
  81. static class Teacher extends Person implements Worker, AcademicInterest
  82. {
  83.  
  84. int rating;
  85. int salary;
  86. String interest;
  87.  
  88. public Teacher(String name, String email, int age, int rating, int salary, String interest)
  89. {
  90. super(name, email, age);
  91.  
  92. this.interest = interest;
  93. this.rating = rating;
  94. this.salary = salary;
  95. }
  96.  
  97. int getRating()
  98. {
  99. return rating;
  100. }
  101.  
  102. @Override
  103. public int getSalary() {
  104. return salary;
  105. }
  106.  
  107.  
  108. @Override
  109. public String getInterest() {
  110. return interest;
  111. }
  112.  
  113. @Override
  114. public void Identify()
  115. {
  116. System.out.println("Name " + name);
  117. System.out.println("Email: " + email);
  118. System.out.println("Age: " + age);
  119. System.out.println("S/He is a teacher.");
  120. }
  121.  
  122. }
  123.  
  124. static class Plummer extends Person implements Worker
  125. {
  126.  
  127. int salary;
  128.  
  129. public Plummer(String name, String email, int age, int salary)
  130. {
  131. super(name, email, age);
  132. this.salary =salary;
  133. }
  134.  
  135. @Override
  136. public int getSalary() {
  137. return salary;
  138. }
  139.  
  140. @Override
  141. public void Identify()
  142. {
  143. System.out.println("Name " + name);
  144. System.out.println("Email: " + email);
  145. System.out.println("Age: " + age);
  146. System.out.println("S/He is a plummer.");
  147. }
  148.  
  149. }
  150.  
  151. static void Menu()
  152. {
  153. System.out.println("Choose an option <enter its index>");
  154. System.out.println("1: Identify all workers with salary under 50k");
  155. System.out.println("2: Identify all Teachers with rating lesser than 8");
  156. System.out.println("3: Count people with the same academic interest");
  157. System.out.println("4: Group students and teachers that share the same academic interest and have average grade and rating lesser then 8");
  158.  
  159. }
  160.  
  161.  
  162. public static void main(String[] args) {
  163. Scanner s = new Scanner(System.in);
  164.  
  165. Person ppl[] = new Person[10];
  166.  
  167. ppl[0] = new Person("Dan", "mit@gmail.com", 38);
  168. ppl[1] = new Plummer("John", "john@gmail.com", 48, 15000);
  169. ppl[2] = new Student("Jacob", "jacob@gmail.com", 24, 6, "Java");
  170. ppl[3] = new Student("Ian", "ian@gmail.com", 22, 8, "Java");
  171. ppl[4] = new Student("Coolio", "coolio@gmail.com", 25, 9, "Managment");
  172. ppl[5] = new Student("Mark", "Mark@gmail.com", 23, 8, "Java");
  173. ppl[6] = new Teacher("Fran", "fran@gmail.com", 48, 9, 80000, "Java");
  174. ppl[7] = new Teacher("Richie", "richie@gmail.com", 52, 8, 49900, "Java");
  175. ppl[8] = new Teacher("Roger", "roger@gmail.com", 39, 8, 70000, "Managment");
  176. ppl[9] = new Teacher("Homer", "homer@gmail.com", 42, 6, 40000, "Managment");
  177.  
  178. int exit= 0;
  179. int choice = 0;
  180. for(;;)
  181. {
  182. if(exit != 0)
  183. {
  184. System.out.println("Do you like to list more? <1 - yes 2 - no");
  185. choice = s.nextInt();
  186. if (choice == 2)
  187. break;
  188. }
  189.  
  190. Menu();
  191.  
  192. choice = s.nextInt();
  193. if(choice == 1)
  194. {
  195. for(int i = 0; i < 10; i++)
  196. {
  197. if(ppl[i].isInstance(Plummer) || ppl[i].isInstance(Teacher))
  198. {
  199. if(ppl[i].getSalary < 50000)
  200. ppl[i].Identify();
  201. }
  202. }
  203. }
  204.  
  205. if( choice == 2)
  206. {
  207. for(int i = 0; i < 10; i++)
  208. {
  209. if(ppl[i].isInstance(Teacher))
  210. {
  211. if(ppl[i].getRating < 😎
  212. ppl[i].Identify();
  213. }
  214. }
  215. }
  216.  
  217. if(choice == 3)
  218. {
  219. int countJ = 0, countM = 0, countF = 0;
  220. for(int i = 0; i < 10; i++)
  221. {
  222. if(ppl[i].getInterest() == 'Java')
  223. {
  224. countJ++;
  225. }
  226.  
  227. if(ppl[i].getInterest() == 'Managment')
  228. {
  229. countM++;
  230. }
  231.  
  232. if(ppl[i].getInterest() == 'Finance')
  233. {
  234. countF++;
  235. }
  236.  
  237. }
  238.  
  239. System.out.println("Java: " + countJ);
  240. System.out.println("Managment: " + countM);
  241. System.out.println("Finance: " + countF);
  242. }
  243.  
  244. if(choice == 4)
  245. {
  246. System.out.println("Teachers and Student with interest java and below 8");
  247. for(int i = 0; i < 9; i++)
  248. {
  249. if(ppl[i].isInstanceof(Teacher) && ppl[i].getRating < 8 && ppl[i].getInterest() == 'Java')
  250. {
  251. ppl[i].Identify();
  252. }
  253.  
  254. if(ppl[i].isInstance(Student) && ppl[i].getAvgrade < 8 && ppl[i].getInterest() == 'Java')
  255. {
  256. ppl[i].Identify();
  257. }
  258. }
  259.  
  260. System.out.println("Teachers and Student with interest managment and below 8");
  261. for(int i = 0; i < 9; i++)
  262. {
  263. if(ppl[i].isInstance(Teacher) && ppl[i].getRating < 8 && ppl[i].getInterest() == 'Managment')
  264. {
  265. ppl[i].Identify();
  266. }
  267.  
  268. if(ppl[i].isInstance(Student) && ppl[i].getAvgrade < 8 && ppl[i].getInterest() == 'Managment')
  269. {
  270. ppl[i].Identify();
  271. }
  272. }
  273.  
  274. System.out.println("Teachers and Student with interest finance and below 8");
  275. for(int i = 0; i < 9; i++)
  276. {
  277. if(ppl[i].isInstance(Teacher) && ppl[i].getRating < 8 && ppl[i].getInterest() == 'Finance')
  278. {
  279. ppl[i].Identify();
  280. }
  281.  
  282. if(ppl[i].isInstance(Student) && ppl[i].getAvgrade < 8 && ppl[i].getInterest() == 'Finance')
  283. {
  284. ppl[i].Identify();
  285. }
  286. }
  287.  
  288. }
  289.  
  290. exit = 1;
  291. }
  292.  
  293. }
  294. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement