Advertisement
Guest User

Untitled

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