fork(1) download
  1. import java.util.Scanner;
  2. import java.util.Objects;
  3. import java.io.BufferedReader;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6.  
  7. class EmployeeDriverSystem
  8. {
  9. public static void main(String args[]) throws IOException
  10. {
  11. //System.out.println("Hello Java");
  12. Employee[] a = new Employee[10];
  13. int count;
  14. // If file handling not needed, uncomment the codes from Line 15-24.
  15. a[0] = new PermanentEmployee("Maninder", "Singh", "30312306"); // to be replaced by the university's student
  16. a[1] = new PermanentEmployee("Peter", "VAMPLEW", "VAM12345678");
  17. a[2] = new PermanentEmployee("Rudi", "SKACEL", "SKA51515151", 56.7);
  18. a[3] = new CasualEmployee("Katie","BLACKBURN","BLA41925612");
  19. a[4] = new CasualEmployee("Neal","STEPHENSON","STE97527467",12.5);
  20. a[5] = new CasualEmployee("Neneh","CHERRY","CHE98765432",9.4);
  21. a[6] = new CasualEmployee("Chris","BROOKMYRE","BRO97635198");
  22. a[7] = new CasualEmployee("Grace","HOPPER","HOP26554432",3.4);
  23. a[8] = new CasualEmployee("Randall","MUNROE","XKCD1234567");
  24. a[9] = new CasualEmployee("Kaylee","FRYE","FRY90224718");
  25.  
  26. //Needs a file named file.txt in the same folder as the code. If file handling not needed, comment
  27. // code from Line 28-41.
  28. /*BufferedReader reader = new BufferedReader(new FileReader("employeedata.txt"));
  29.   for(int i = 0; i < 3; i++)
  30.   {
  31.   String line = reader.readLine();
  32.   String[] parts = line.split(" ");
  33.   a[i] = new PermanentEmployee(parts[0], parts[1], parts[2]);
  34.   }
  35.   for(int i = 3; i < 10; i++)
  36.   {
  37.   String line = reader.readLine();
  38.   String[] parts = line.split(" ");
  39.   a[i] = new CasualEmployee(parts[0], parts[1], parts[2]);
  40.   }
  41.   reader.close();*/
  42. Employee[][] b = new Employee [5][4];
  43. int flag = 0;
  44. int n,n2,n3,n4;
  45. while (true)
  46. {
  47. if (flag == 0)
  48. {
  49. System.out.println("1. Display all staff");
  50. System.out.println("2. Clear schedule");
  51. System.out.println("3. Display schedule");
  52. System.out.println("4. Assign shift to casual employee");
  53. System.out.println("5. Assign shifts to permanent employee");
  54. System.out.println("6. Calculate total weekly wages");
  55. System.out.println("7. Exit Program");
  56. while (true)
  57. {
  58. System.out.println("Enter your selection");
  59. //n = Integer.parseInt(System.console().readLine());
  60. Scanner in = new Scanner(System.in);
  61. n = in.nextInt();
  62.  
  63. // n = in.nextInt();
  64.  
  65.  
  66. // n = in.nextInt();
  67. if (n <= 0 || n > 7)
  68. {
  69. System.out.println("Invalid Selection - must be between 1 and 7.");
  70. break;
  71. }
  72. if (n == 1)
  73. {
  74. int i = 0;
  75. for (i = 0; i < 10; i++)
  76. {
  77. String x = a[i].toString();
  78. System.out.println(x);
  79. }
  80. break;
  81. }
  82. else if (n == 2)
  83. {
  84. int i = 0;
  85. int j = 0;
  86. for (i = 0; i < 10; i++)
  87. {
  88. a[i].shiftsWorkedThisWeek = 0;
  89. }
  90. for (i = 0; i < 5; i++ )
  91. {
  92. for (j = 0; j < 4; j++ )
  93. {
  94. b[i][j] = null;
  95. }
  96. }
  97. break;
  98. }
  99. else if (n == 3)
  100. {
  101. int i,j;
  102. for (i = 0; i < 5; i++)
  103. {
  104. if (i == 0)
  105. System.out.print("MON\t");
  106. else if (i == 1)
  107. System.out.print("TUE\t");
  108. else if (i == 2)
  109. System.out.print("WED\t");
  110. else if (i == 3)
  111. System.out.print("THU\t");
  112. else if (i == 4)
  113. System.out.print("FRI\t");
  114. for (j = 0; j < 4; j++)
  115. {
  116. if (b[i][j] == null)
  117. {
  118. System.out.print("------------------------\t");
  119. }
  120. else
  121. {
  122. System.out.print(b[i][j].toString());
  123. System.out.print("\t");
  124. }
  125. }
  126. System.out.print("\n");
  127. }
  128. break;
  129. }
  130. else if (n == 4)
  131. {
  132. while (true)
  133. {
  134. System.out.println("Which shift do you wish to allocate to a casual employee? (1..4):");
  135. n2 = Integer.parseInt(System.console().readLine());
  136. if (n2 < 1 || n2 > 4)
  137. {
  138. System.out.println("Invalid selection - must be between 1 and 4.");
  139. }
  140. else
  141. break;
  142. }
  143. while (true)
  144. {
  145. System.out.println("On which day? (1..5):");
  146. n3 = Integer.parseInt(System.console().readLine());
  147. if (n3 < 1 || n3 > 5)
  148. {
  149. System.out.println("Invalid selection - must be between 1 and 5.");
  150. }
  151. else
  152. break;
  153. }
  154. if (b[n3-1][n2-1] != null)
  155. {
  156. System.out.println("This shift has already been allocated");
  157. break;
  158. }
  159. else
  160. {
  161. int i;
  162. for (i = 0; i < 10; i++)
  163. {
  164. if (a[i] instanceof CasualEmployee == true)
  165. {
  166. String v = a[i].toString();
  167. System.out.println(v);
  168. }
  169. }
  170. int flag2 = 0;
  171. while (true)
  172. {
  173. System.out.println("Enter ID");
  174. Scanner input = new Scanner(System.in);
  175. String y = input.nextLine();
  176. for (i = 0; i < 10; i++)
  177. {
  178. if (Objects.equals(y, a[i].ID) == true)
  179. {
  180. flag2 = 1;
  181. }
  182. if (flag2 == 1)
  183. break;
  184. }
  185. if (flag2 == 1)
  186. break;
  187. else
  188. {
  189. System.out.println("Invalid selection - try again.");
  190. }
  191. }
  192. b[n3-1][n2-1] = a[i];
  193. a[i].incrementShiftsWorkedThisWeek();
  194. }
  195. break;
  196. }
  197. else if (n == 5)
  198. {
  199. while (true)
  200. {
  201. System.out.println("Which shift do you wish to allocate to a permanent employee? (1..4):");
  202. n4 = Integer.parseInt(System.console().readLine());
  203. if (n4 < 1 || n4 > 4)
  204. {
  205. System.out.println("Invalid selection - must be between 1 and 4.");
  206. }
  207. else
  208. break;
  209. }
  210. int flag3 = 0;
  211. int i;
  212. for (i = 0; i < 5; i++)
  213. {
  214. if (b[i][n4] != null)
  215. {
  216. System.out.println("This shift is already allocated\n");
  217. flag3 = 1;
  218. break;
  219. }
  220. }
  221. if (flag3 == 0)
  222. {
  223.  
  224. for (i = 0; i < 10; i++)
  225. {
  226. if (a[i] instanceof PermanentEmployee == true)
  227. {
  228. String v = a[i].toString();
  229. System.out.println(v);
  230. }
  231. }
  232. int flag4 = 0;
  233. while (true)
  234. {
  235. System.out.println("Enter ID");
  236. Scanner input = new Scanner(System.in);
  237. String y = input.nextLine();
  238. for (i = 0; i < 10; i++)
  239. {
  240. if (Objects.equals(y, a[i].ID) == true)
  241. {
  242. flag4 = 1;
  243. }
  244. if (flag4 == 1)
  245. break;
  246. }
  247. if (flag4 == 1)
  248. break;
  249. else
  250. {
  251. System.out.println("Invalid selection - try again.");
  252. }
  253. }
  254. int j;
  255. for (j = 0; j < 5; j++)
  256. {
  257. b[j][n4-1] = a[i];
  258. }
  259. a[i].shiftsWorkedThisWeek = a[i].shiftsWorkedThisWeek + 5;
  260. }
  261. break;
  262. }
  263. else if ( n == 6 )
  264. {
  265. int i;
  266. double total = 0;
  267. for ( i = 0; i < 10; i++ )
  268. {
  269. System.out.print(a[i].toString());
  270. System.out.print(" ");
  271. double var = a[i].calculateWeeklyPay();
  272. System.out.print(var);
  273. total = total + var;
  274. System.out.print("\n");
  275. }
  276. System.out.println("-----------------------------------------");
  277. System.out.print("TOTAL WAGES FOR THIS WEEK: ");
  278. System.out.println(total);
  279. break;
  280. }
  281. else if (n == 7)
  282. {
  283. flag = 1;
  284. break;
  285. }
  286. }
  287. }
  288. else
  289. break;
  290. }
  291. }
  292. public abstract static class Employee
  293. {
  294. String firstName;
  295. String lastName;
  296. String ID;
  297. int shiftsWorkedThisWeek;
  298. Employee(String a, String b, String c)
  299. {
  300. firstName = a;
  301. lastName = b;
  302. ID = c;
  303. }
  304. public String getFirstName()
  305. {
  306. return firstName;
  307. }
  308. public String getLastName()
  309. {
  310. return lastName;
  311. }
  312. public String getID()
  313. {
  314. return ID;
  315. }
  316. public int getShiftsWorkedThisWeek()
  317. {
  318. return shiftsWorkedThisWeek;
  319. }
  320. public void resetShiftsWorkedThisWeek()
  321. {
  322. shiftsWorkedThisWeek = 0;
  323. }
  324. public void incrementShiftsWorkedThisWeek()
  325. {
  326. shiftsWorkedThisWeek = shiftsWorkedThisWeek + 1;
  327. }
  328. public abstract double calculateWeeklyPay();
  329. public String toString()
  330. {
  331. String a1 = "[" + ID + "]";
  332. String a2 = a1 + " ";
  333. String a3 = lastName + ",";
  334. String a4 = a3 + " ";
  335. String a5 = firstName;
  336. String a6 = a2 + a4 + a5;
  337. return a6;
  338. }
  339. }
  340.  
  341. public static class PermanentEmployee extends Employee
  342. {
  343. double weeklyWage;
  344. PermanentEmployee(String a1, String a2, String a3)
  345. {
  346. super(a1,a2,a3);
  347. weeklyWage = 812.47;
  348. }
  349. PermanentEmployee(String a1, String a2, String a3, double a4)
  350. {
  351. super(a1,a2,a3);
  352. weeklyWage = a4;
  353. }
  354. public void setWeeklyWage(double a1)
  355. {
  356. weeklyWage = a1;
  357. }
  358. public double getWeeklyWage()
  359. {
  360. return weeklyWage;
  361. }
  362. public double calculateWeeklyPay()
  363. {
  364. return weeklyWage;
  365. }
  366. }
  367.  
  368. public static class CasualEmployee extends Employee
  369. {
  370. double shiftRate;
  371. CasualEmployee(String a1, String a2, String a3)
  372. {
  373. super(a1,a2,a3);
  374. shiftRate = 47.5;
  375. }
  376. CasualEmployee(String a1, String a2, String a3, double a4)
  377. {
  378. super(a1,a2,a3);
  379. shiftRate = a4;
  380. }
  381. public void setShiftRate(double a1)
  382. {
  383. shiftRate = a1;
  384. }
  385. public double getShiftRate (double a2)
  386. {
  387. return shiftRate;
  388. }
  389. public double calculateWeeklyPay()
  390. {
  391. double a1 = shiftRate*shiftsWorkedThisWeek;
  392. return a1;
  393. }
  394. }
  395. }
  396.  
  397.  
  398.  
Runtime error #stdin #stdout #stderr 0.14s 321344KB
stdin
1
stdout
1. Display all staff
2. Clear schedule
3. Display schedule
4. Assign shift to casual employee
5. Assign shifts to permanent employee
6. Calculate total weekly wages
7. Exit Program
Enter your selection
[30312306] Singh, Maninder
[VAM12345678] VAMPLEW, Peter
[SKA51515151] SKACEL, Rudi
[BLA41925612] BLACKBURN, Katie
[STE97527467] STEPHENSON, Neal
[CHE98765432] CHERRY, Neneh
[BRO97635198] BROOKMYRE, Chris
[HOP26554432] HOPPER, Grace
[XKCD1234567] MUNROE, Randall
[FRY90224718] FRYE, Kaylee
1. Display all staff
2. Clear schedule
3. Display schedule
4. Assign shift to casual employee
5. Assign shifts to permanent employee
6. Calculate total weekly wages
7. Exit Program
Enter your selection
stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:862)
	at java.util.Scanner.next(Scanner.java:1485)
	at java.util.Scanner.nextInt(Scanner.java:2117)
	at java.util.Scanner.nextInt(Scanner.java:2076)
	at EmployeeDriverSystem.main(Main.java:61)