Advertisement
Guest User

Untitled

a guest
Nov 25th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.79 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 oop_ca2;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.Arrays;
  10. import java.util.Scanner;
  11.  
  12. /**
  13. *
  14. * @author Emil
  15. */
  16. public class MainApp
  17. {
  18.  
  19. /**
  20. * @param args the command line arguments
  21. */
  22. public static void main(String[] args)
  23. {
  24. MessageStore messageStore = new MessageStore();
  25. EmployeeStore employeeStore = new EmployeeStore();
  26. messageStore.MessageBox("Messages.txt");
  27. employeeStore.createList("Employee.txt");
  28. boolean accessGranted = false;
  29. boolean passAccess = false;
  30. boolean idAccess = false;
  31.  
  32. Scanner keyboard = new Scanner(System.in);
  33.  
  34. if (accessGranted != true)
  35. {
  36. System.out.println("Please Enter Login Password");
  37. String loginPass = keyboard.nextLine();
  38. int login = loginPass.hashCode();
  39.  
  40. System.out.println("Please Enter the ID");
  41. long loginID = keyboard.nextInt();
  42.  
  43. String LoginIdString = ""+loginID;
  44. while (!LoginIdString.matches("[0-9]+"))
  45. {
  46. System.out.println("Invalid number");
  47. }
  48. passAccess = employeeStore.checkEmployeePass(login, loginID);
  49.  
  50. while (passAccess == false)
  51. {
  52. System.out.println("Wrong login Details, Please try again!");
  53. loginPass = keyboard.nextLine();
  54.  
  55. System.out.println("Please Enter Login Password");
  56. loginPass = keyboard.nextLine();
  57. login = loginPass.hashCode();
  58.  
  59. System.out.println("Please Enter the ID");
  60. loginID = keyboard.nextInt();
  61.  
  62. passAccess = employeeStore.checkEmployeePass(login, loginID);
  63. if (passAccess == true)
  64. {
  65. accessGranted = true;
  66. }
  67. }
  68.  
  69. }
  70. if (passAccess == true)
  71. {
  72. multiPurposeMethods.displaySections();
  73.  
  74. System.out.println("Please Enter the Desired Option");
  75. int section = keyboard.nextInt();
  76. while (section != 3)
  77. {
  78. if (section == 1)
  79. {
  80. // multiPurposeMethods.displayListOfOptions();
  81. multiPurposeMethods.displayMessageMenu();
  82. System.out.println("Please Enter the Desired Message Option");
  83. int option = keyboard.nextInt();
  84. while (option != 13)
  85. {
  86.  
  87. keyboard.nextLine();
  88. //------------------- MESSAGE QUESTIONS 1-12 -------------------//
  89. //PART1 Create and add A new message to the messageStore.
  90. if (option == 1)
  91. {
  92.  
  93. messageStore.newMessageDetails();
  94.  
  95. }
  96.  
  97. //PART2 Print all message details from a list of messages
  98. else if (option == 2)
  99. {
  100. messageStore.displayMessageList();
  101. }
  102. //PART3 Return the details of a message selected by message ID.
  103. else if (option == 3)
  104. {
  105. ArrayList<Message> listById = new ArrayList<>();
  106. System.out.println("Plese Input the index of the message you would like: ");
  107.  
  108. int Id = keyboard.nextInt();
  109. listById = messageStore.getMessageByID(Id);
  110. messageStore.display(listById);
  111. }
  112. //PART4 Return a list of all messages sent from a user-defined email address.
  113. else if (option == 4)
  114. {
  115. ArrayList<Message> listOfSentEmailsByUser = new ArrayList<>();
  116. System.out.println("");
  117. System.out.println("Input The Email Address!(Sender)");
  118.  
  119. String SenderEmail = keyboard.nextLine();
  120. listOfSentEmailsByUser = messageStore.getMessageBySender(SenderEmail);
  121. messageStore.display(listOfSentEmailsByUser);
  122. }
  123. //PART5 Return a list of all messages that contain a user-defined substring in the message subject or message body.
  124. else if (option == 5)
  125. {
  126. System.out.println("");
  127. ArrayList<Message> listOfSubstringEmails = new ArrayList<>();
  128. System.out.println("Input The SubString to look for:");
  129.  
  130. String subString = keyboard.nextLine();
  131. listOfSubstringEmails = messageStore.getSubStringOfEmail(subString);
  132. messageStore.display(listOfSubstringEmails);
  133. }
  134. //PART6 Return a list of all messages sent to a user-defined email address.
  135. else if (option == 6)
  136. {
  137. System.out.println("");
  138. ArrayList<Message> listOfRecievedEmailsByUser = new ArrayList<>();
  139. System.out.println("Input The Email Address!(Reciever)");
  140.  
  141. String RecieverEmail = keyboard.nextLine();
  142. listOfRecievedEmailsByUser = messageStore.getMessageByReciever(RecieverEmail);
  143. messageStore.display(listOfRecievedEmailsByUser);
  144. }
  145. //PART7 Return a list of all messages with a user-defined priority.
  146. else if (option == 7)
  147. {
  148. System.out.println("");
  149. ArrayList<Message> listOfPriority = new ArrayList<>();
  150. System.out.println("Input The Priority Level Wanted (Low/Medium/High)");
  151.  
  152. String priorety = keyboard.nextLine();
  153. listOfPriority = messageStore.getMessageByPriority(priorety);
  154. messageStore.display(listOfPriority);
  155. }
  156. //PART8 Return a list of all messages with a user defined date.
  157. else if (option == 8)
  158. {
  159. System.out.println("");
  160. ArrayList<Message> listOfDate = new ArrayList<>();
  161. System.out.println("Input The Date you are searching for (d/m/yyyy)");
  162.  
  163. String date = keyboard.nextLine();
  164. listOfDate = messageStore.getMessageByDate(date);
  165. messageStore.display(listOfDate);
  166. }
  167. //PART9 Sort messages by date
  168. else if (option == 9)
  169. {
  170. ArrayList<Message> sortByDate = messageStore.sortMessageByDate();
  171. messageStore.display(sortByDate);
  172. }
  173. //PART10 Sort messages by message ID
  174. else if (option == 10)
  175. {
  176. ArrayList<Message> messagesSortedByID = new ArrayList<>();
  177. messagesSortedByID = messageStore.sortMessageById(messagesSortedByID);
  178. messageStore.display(messagesSortedByID);
  179. }
  180. //PART11 get message by user-defined two emails
  181. else if (option == 11)
  182. {
  183. System.out.println("Please enter the Two Emails to display that Message: ");
  184. System.out.println("First Date: ");
  185. String date1 = keyboard.nextLine();
  186. System.out.println("Second Date: ");
  187. String date2 = keyboard.nextLine();
  188. }
  189.  
  190. System.out.println("Please Enter The desired option: ");
  191. option = keyboard.nextInt();
  192. }
  193. if (option == 13)
  194. {
  195. multiPurposeMethods.displaySections();
  196.  
  197. System.out.println("Please Enter the Desired Option");
  198. section = keyboard.nextInt();
  199. }
  200. }
  201.  
  202. if (section == 2)
  203. {
  204. //------------------- EMPLOYEE QUESTIONS 13-16 -------------------//
  205. //PART13 Create and add new Employee to the system.
  206. multiPurposeMethods.displayEmployeeMenu();
  207. System.out.println("Please Enter the Desired Employee Option");
  208. int option2 = keyboard.nextInt();
  209. while (option2 != 9)
  210. {
  211. if (option2 == 1)
  212. {
  213. employeeStore.newEmployeeDetails();
  214. }
  215.  
  216. else if (option2 == 2)
  217. {
  218. //PART14 Return a list of all Employees
  219. ArrayList<String> empOnly = employeeStore.generateListEmployee();
  220.  
  221. //PART15 Pint a lisyt of all Employees in a system.
  222. employeeStore.display(empOnly);
  223. System.out.println("");
  224. }
  225. //PART16 Return a list of employees selected on a user defined name.
  226. else if (option2 == 3)
  227. {
  228. System.out.println("Name of employee you are searching: ");
  229. String name = keyboard.nextLine();
  230. employeeStore.getEmployeeByName(name);
  231. }
  232. //PART17 Edit Delete and print names.
  233. else if (option2 == 4)
  234. {
  235. multiPurposeMethods.displaySubMenu();
  236. System.out.println("Please Enter Sub Option.");
  237. int subOption = keyboard.nextInt();
  238. while (subOption != 4)
  239. {
  240. if (subOption == 1)
  241. {
  242. keyboard.nextLine();
  243. System.out.println("Please enter the employee name you would like to edit!");
  244. String nameToEdit = keyboard.nextLine();
  245. employeeStore.getEditEmployee(nameToEdit);
  246. }
  247. if (subOption == 2)
  248. {
  249. keyboard.nextLine();
  250. System.out.println("Name of employee that you would like to print the details of! ");
  251. String nameToPrint = keyboard.nextLine();
  252. employeeStore.getEmployeeByName(nameToPrint);
  253. }
  254. if (subOption == 3)
  255. {
  256. keyboard.nextLine();
  257. System.out.println("Name of employee you would like to delete the details of! ");
  258. String deleteName = keyboard.nextLine();
  259. employeeStore.deleteEmployee(deleteName);
  260. }
  261. if (subOption == 4)
  262. {
  263.  
  264. multiPurposeMethods.displaySections();
  265.  
  266. System.out.println("Please Enter the Desired Option");
  267. section = keyboard.nextInt();
  268. }
  269. }
  270.  
  271. }
  272. //PART18 Return list of all messgaes by email and specified date
  273. else if (option2 == 5)
  274. {
  275.  
  276. }
  277. else if (option2 == 6)
  278. {
  279. ArrayList<Employee> listOfAllEmp = new ArrayList<>();
  280. listOfAllEmp = employeeStore.getAllEmployee();
  281. employeeStore.displayAll(listOfAllEmp);
  282. }
  283. else if (option2 == 7)
  284. {
  285. ArrayList<Employee> listOfAllAgents = new ArrayList<>();
  286. listOfAllAgents = employeeStore.getAgentList();
  287. employeeStore.displayAll(listOfAllAgents);
  288. }
  289. else if (option2 == 8)
  290. {
  291. // getTotalSalaryOfEmployeesMonth();
  292. }
  293.  
  294. System.out.println("Please Enter The desired Employee option: ");
  295. option2 = keyboard.nextInt();
  296.  
  297. }
  298.  
  299. if (option2 == 9)
  300. {
  301. multiPurposeMethods.displaySections();
  302. System.out.println("Please Enter the Desired Option");
  303. section = keyboard.nextInt();
  304. }
  305.  
  306. }
  307.  
  308. if (section == 3)
  309. {
  310.  
  311. employeeStore.updateFile();
  312. messageStore.updateFile();
  313. System.out.println("You have closed the programme!");
  314. System.out.print("-----------------------------");
  315. }
  316. if (section <= 0 || section > 3)
  317. {
  318. System.out.println("Not a Valid option,Please go again..");
  319. section = keyboard.nextInt();
  320. }
  321. }
  322. }
  323.  
  324. }
  325. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement