Advertisement
Guest User

Untitled

a guest
Nov 25th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.23 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("Please enter the year: ");
  162. int y1 = keyboard.nextInt();
  163.  
  164. System.out.println("Please enter the month: ");
  165. int m1 = keyboard.nextInt();
  166.  
  167. System.out.println("Please enter the day: ");
  168. int d1 = keyboard.nextInt();
  169.  
  170. listOfDate = messageStore.getMessageByDate(y1, m1, d1);
  171. messageStore.display(listOfDate);
  172. }
  173. //PART9 Sort messages by date
  174. else if (option == 9)
  175. {
  176. ArrayList<Message> sortByDate = messageStore.sortMessageByDate();
  177. messageStore.display(sortByDate);
  178. }
  179. //PART10 Sort messages by message ID
  180. else if (option == 10)
  181. {
  182. ArrayList<Message> messagesSortedByID = new ArrayList<>();
  183. messagesSortedByID = messageStore.sortMessageById(messagesSortedByID);
  184. messageStore.display(messagesSortedByID);
  185. }
  186. //PART11 get message by user-defined two emails
  187. else if (option == 11)
  188. {
  189. System.out.println("Please enter the Two Dates to display the Messages between them: ");
  190.  
  191. System.out.println("First date, Please enter the year: ");
  192. int y1 = keyboard.nextInt();
  193.  
  194. System.out.println("First date, Please enter the month: ");
  195. int m1 = keyboard.nextInt();
  196.  
  197. System.out.println("First date, Please enter the day: ");
  198. int d1 = keyboard.nextInt();
  199.  
  200. System.out.println("Second Date, Please enter the year: ");
  201. int y2 = keyboard.nextInt();
  202.  
  203. System.out.println("Second Date, Please enter the month: ");
  204. int m2 = keyboard.nextInt();
  205.  
  206. System.out.println("Second Date, Please enter the day: ");
  207. int d2 = keyboard.nextInt();
  208. ArrayList<Message> list = messageStore.getMessageByTwoDates(y1, m1, d1, y2, m2, d2);
  209. messageStore.display(list);
  210.  
  211. }
  212.  
  213. else if (option == 12)
  214. {
  215. ArrayList<Message> recentMessages = new ArrayList<>();
  216. recentMessages = messageStore.MessagesInLast10Days();
  217. messageStore.display(recentMessages);
  218. }
  219.  
  220. System.out.println("Please Enter The desired option: ");
  221. option = keyboard.nextInt();
  222. }
  223. if (option == 13)
  224. {
  225. multiPurposeMethods.displaySections();
  226.  
  227. System.out.println("Please Enter the Desired Option");
  228. section = keyboard.nextInt();
  229. }
  230. }
  231.  
  232. if (section == 2)
  233. {
  234. //------------------- EMPLOYEE QUESTIONS 13-16 -------------------//
  235. //PART13 Create and add new Employee to the system.
  236. multiPurposeMethods.displayEmployeeMenu();
  237. System.out.println("Please Enter the Desired Employee Option");
  238. int option2 = keyboard.nextInt();
  239. while (option2 != 9)
  240. {
  241. if (option2 == 1)
  242. {
  243. employeeStore.newEmployeeDetails();
  244. }
  245.  
  246. else if (option2 == 2)
  247. {
  248. //PART14 Return a list of all Employees
  249. ArrayList<String> empOnly = employeeStore.generateListEmployee();
  250.  
  251. //PART15 Pint a lisyt of all Employees in a system.
  252. employeeStore.display(empOnly);
  253. System.out.println("");
  254. }
  255. //PART16 Return a list of employees selected on a user defined name.
  256. else if (option2 == 3)
  257. {
  258. System.out.println("Name of employee you are searching: ");
  259. String name = keyboard.nextLine();
  260. employeeStore.getEmployeeByName(name);
  261. }
  262. //PART17 Edit Delete and print names.
  263. else if (option2 == 4)
  264. {
  265. multiPurposeMethods.displaySubMenu();
  266. System.out.println("Please Enter Sub Option.");
  267. int subOption = keyboard.nextInt();
  268. while (subOption != 4)
  269. {
  270. if (subOption == 1)
  271. {
  272. keyboard.nextLine();
  273. System.out.println("Please enter the employee name you would like to edit!");
  274. String nameToEdit = keyboard.nextLine();
  275. employeeStore.getEditEmployee(nameToEdit);
  276. }
  277. if (subOption == 2)
  278. {
  279. keyboard.nextLine();
  280. System.out.println("Name of employee that you would like to print the details of! ");
  281. String nameToPrint = keyboard.nextLine();
  282. employeeStore.getEmployeeByName(nameToPrint);
  283. }
  284. if (subOption == 3)
  285. {
  286. keyboard.nextLine();
  287. System.out.println("Name of employee you would like to delete the details of! ");
  288. String deleteName = keyboard.nextLine();
  289. employeeStore.deleteEmployee(deleteName);
  290. }
  291. if (subOption == 4)
  292. {
  293.  
  294. multiPurposeMethods.displaySections();
  295.  
  296. System.out.println("Please Enter the Desired Option");
  297. section = keyboard.nextInt();
  298. }
  299. }
  300.  
  301. }
  302. //PART18 Return list of all messgaes by email and specified date
  303. else if (option2 == 5)
  304. {
  305. System.out.println("Please enter the senders email address: ");
  306. String email = keyboard.nextLine();
  307.  
  308. System.out.println("First date, Please enter the year: ");
  309. int y1 = keyboard.nextInt();
  310.  
  311. System.out.println("First date, Please enter the month: ");
  312. int m1 = keyboard.nextInt();
  313.  
  314. System.out.println("First date, Please enter the day: ");
  315. int d1 = keyboard.nextInt();
  316.  
  317. System.out.println("Second Date, Please enter the year: ");
  318. int y2 = keyboard.nextInt();
  319.  
  320. System.out.println("Second Date, Please enter the month: ");
  321. int m2 = keyboard.nextInt();
  322.  
  323. System.out.println("Second Date, Please enter the day: ");
  324. int d2 = keyboard.nextInt();
  325.  
  326. ArrayList<Message> list = new ArrayList<>();
  327. list = messageStore.MessagesByEmailAndDates(email, y1, m1, d1, y2, m2, d2);
  328. messageStore.display(list);
  329. }
  330. else if (option2 == 6)
  331. {
  332. ArrayList<Employee> listOfAllEmp = new ArrayList<>();
  333. listOfAllEmp = employeeStore.getAllEmployee();
  334. employeeStore.displayAll(listOfAllEmp);
  335. }
  336. else if (option2 == 7)
  337. {
  338. ArrayList<Employee> listOfAllAgents = new ArrayList<>();
  339. listOfAllAgents = employeeStore.getAgentList();
  340. employeeStore.displayAll(listOfAllAgents);
  341. }
  342. else if (option2 == 8)
  343. {
  344. // getTotalSalaryOfEmployeesMonth();
  345. }
  346.  
  347. System.out.println("Please Enter The desired Employee option: ");
  348. option2 = keyboard.nextInt();
  349.  
  350. }
  351.  
  352. if (option2 == 9)
  353. {
  354. multiPurposeMethods.displaySections();
  355. System.out.println("Please Enter the Desired Option");
  356. section = keyboard.nextInt();
  357. }
  358.  
  359. }
  360.  
  361. if (section == 3)
  362. {
  363.  
  364. employeeStore.updateFile();
  365. messageStore.updateFile();
  366. System.out.println("You have closed the programme!");
  367. System.out.print("-----------------------------");
  368. }
  369. if (section <= 0 || section > 3)
  370. {
  371. System.out.println("Not a Valid option,Please go again..");
  372. section = keyboard.nextInt();
  373. }
  374. }
  375. }
  376.  
  377. }
  378. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement