Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package oop_ca2;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Scanner;
- /**
- *
- * @author Emil
- */
- public class MainApp
- {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args)
- {
- MessageStore messageStore = new MessageStore();
- EmployeeStore employeeStore = new EmployeeStore();
- messageStore.MessageBox("Messages.txt");
- employeeStore.createList("Employee.txt");
- boolean accessGranted = false;
- boolean passAccess = false;
- boolean idAccess = false;
- Scanner keyboard = new Scanner(System.in);
- if (accessGranted != true)
- {
- System.out.println("Please Enter Login Password");
- String loginPass = keyboard.nextLine();
- int login = loginPass.hashCode();
- System.out.println("Please Enter the ID");
- long loginID = keyboard.nextInt();
- String LoginIdString = "" + loginID;
- while (!LoginIdString.matches("[0-9]+"))
- {
- System.out.println("Invalid number");
- }
- passAccess = employeeStore.checkEmployeePass(login, loginID);
- while (passAccess == false)
- {
- System.out.println("Wrong login Details, Please try again!");
- loginPass = keyboard.nextLine();
- System.out.println("Please Enter Login Password");
- loginPass = keyboard.nextLine();
- login = loginPass.hashCode();
- System.out.println("Please Enter the ID");
- loginID = keyboard.nextInt();
- passAccess = employeeStore.checkEmployeePass(login, loginID);
- if (passAccess == true)
- {
- accessGranted = true;
- }
- }
- }
- if (passAccess == true)
- {
- multiPurposeMethods.displaySections();
- System.out.println("Please Enter the Desired Option");
- int section = keyboard.nextInt();
- while (section != 3)
- {
- if (section == 1)
- {
- // multiPurposeMethods.displayListOfOptions();
- multiPurposeMethods.displayMessageMenu();
- System.out.println("Please Enter the Desired Message Option");
- int option = keyboard.nextInt();
- while (option != 13)
- {
- keyboard.nextLine();
- //------------------- MESSAGE QUESTIONS 1-12 -------------------//
- //PART1 Create and add A new message to the messageStore.
- if (option == 1)
- {
- messageStore.newMessageDetails();
- }
- //PART2 Print all message details from a list of messages
- else if (option == 2)
- {
- messageStore.displayMessageList();
- }
- //PART3 Return the details of a message selected by message ID.
- else if (option == 3)
- {
- ArrayList<Message> listById = new ArrayList<>();
- System.out.println("Plese Input the index of the message you would like: ");
- int Id = keyboard.nextInt();
- listById = messageStore.getMessageByID(Id);
- messageStore.display(listById);
- }
- //PART4 Return a list of all messages sent from a user-defined email address.
- else if (option == 4)
- {
- ArrayList<Message> listOfSentEmailsByUser = new ArrayList<>();
- System.out.println("");
- System.out.println("Input The Email Address!(Sender)");
- String SenderEmail = keyboard.nextLine();
- listOfSentEmailsByUser = messageStore.getMessageBySender(SenderEmail);
- messageStore.display(listOfSentEmailsByUser);
- }
- //PART5 Return a list of all messages that contain a user-defined substring in the message subject or message body.
- else if (option == 5)
- {
- System.out.println("");
- ArrayList<Message> listOfSubstringEmails = new ArrayList<>();
- System.out.println("Input The SubString to look for:");
- String subString = keyboard.nextLine();
- listOfSubstringEmails = messageStore.getSubStringOfEmail(subString);
- messageStore.display(listOfSubstringEmails);
- }
- //PART6 Return a list of all messages sent to a user-defined email address.
- else if (option == 6)
- {
- System.out.println("");
- ArrayList<Message> listOfRecievedEmailsByUser = new ArrayList<>();
- System.out.println("Input The Email Address!(Reciever)");
- String RecieverEmail = keyboard.nextLine();
- listOfRecievedEmailsByUser = messageStore.getMessageByReciever(RecieverEmail);
- messageStore.display(listOfRecievedEmailsByUser);
- }
- //PART7 Return a list of all messages with a user-defined priority.
- else if (option == 7)
- {
- System.out.println("");
- ArrayList<Message> listOfPriority = new ArrayList<>();
- System.out.println("Input The Priority Level Wanted (Low/Medium/High)");
- String priorety = keyboard.nextLine();
- listOfPriority = messageStore.getMessageByPriority(priorety);
- messageStore.display(listOfPriority);
- }
- //PART8 Return a list of all messages with a user defined date.
- else if (option == 8)
- {
- System.out.println("");
- ArrayList<Message> listOfDate = new ArrayList<>();
- System.out.println("Please enter the year: ");
- int y1 = keyboard.nextInt();
- System.out.println("Please enter the month: ");
- int m1 = keyboard.nextInt();
- System.out.println("Please enter the day: ");
- int d1 = keyboard.nextInt();
- listOfDate = messageStore.getMessageByDate(y1, m1, d1);
- messageStore.display(listOfDate);
- }
- //PART9 Sort messages by date
- else if (option == 9)
- {
- ArrayList<Message> sortByDate = messageStore.sortMessageByDate();
- messageStore.display(sortByDate);
- }
- //PART10 Sort messages by message ID
- else if (option == 10)
- {
- ArrayList<Message> messagesSortedByID = new ArrayList<>();
- messagesSortedByID = messageStore.sortMessageById(messagesSortedByID);
- messageStore.display(messagesSortedByID);
- }
- //PART11 get message by user-defined two emails
- else if (option == 11)
- {
- System.out.println("Please enter the Two Dates to display the Messages between them: ");
- System.out.println("First date, Please enter the year: ");
- int y1 = keyboard.nextInt();
- System.out.println("First date, Please enter the month: ");
- int m1 = keyboard.nextInt();
- System.out.println("First date, Please enter the day: ");
- int d1 = keyboard.nextInt();
- System.out.println("Second Date, Please enter the year: ");
- int y2 = keyboard.nextInt();
- System.out.println("Second Date, Please enter the month: ");
- int m2 = keyboard.nextInt();
- System.out.println("Second Date, Please enter the day: ");
- int d2 = keyboard.nextInt();
- ArrayList<Message> list = messageStore.getMessageByTwoDates(y1, m1, d1, y2, m2, d2);
- messageStore.display(list);
- }
- else if (option == 12)
- {
- ArrayList<Message> recentMessages = new ArrayList<>();
- recentMessages = messageStore.MessagesInLast10Days();
- messageStore.display(recentMessages);
- }
- System.out.println("Please Enter The desired option: ");
- option = keyboard.nextInt();
- }
- if (option == 13)
- {
- multiPurposeMethods.displaySections();
- System.out.println("Please Enter the Desired Option");
- section = keyboard.nextInt();
- }
- }
- if (section == 2)
- {
- //------------------- EMPLOYEE QUESTIONS 13-16 -------------------//
- //PART13 Create and add new Employee to the system.
- multiPurposeMethods.displayEmployeeMenu();
- System.out.println("Please Enter the Desired Employee Option");
- int option2 = keyboard.nextInt();
- while (option2 != 9)
- {
- if (option2 == 1)
- {
- employeeStore.newEmployeeDetails();
- }
- else if (option2 == 2)
- {
- //PART14 Return a list of all Employees
- ArrayList<String> empOnly = employeeStore.generateListEmployee();
- //PART15 Pint a lisyt of all Employees in a system.
- employeeStore.display(empOnly);
- System.out.println("");
- }
- //PART16 Return a list of employees selected on a user defined name.
- else if (option2 == 3)
- {
- System.out.println("Name of employee you are searching: ");
- String name = keyboard.nextLine();
- employeeStore.getEmployeeByName(name);
- }
- //PART17 Edit Delete and print names.
- else if (option2 == 4)
- {
- multiPurposeMethods.displaySubMenu();
- System.out.println("Please Enter Sub Option.");
- int subOption = keyboard.nextInt();
- while (subOption != 4)
- {
- if (subOption == 1)
- {
- keyboard.nextLine();
- System.out.println("Please enter the employee name you would like to edit!");
- String nameToEdit = keyboard.nextLine();
- employeeStore.getEditEmployee(nameToEdit);
- }
- if (subOption == 2)
- {
- keyboard.nextLine();
- System.out.println("Name of employee that you would like to print the details of! ");
- String nameToPrint = keyboard.nextLine();
- employeeStore.getEmployeeByName(nameToPrint);
- }
- if (subOption == 3)
- {
- keyboard.nextLine();
- System.out.println("Name of employee you would like to delete the details of! ");
- String deleteName = keyboard.nextLine();
- employeeStore.deleteEmployee(deleteName);
- }
- if (subOption == 4)
- {
- multiPurposeMethods.displaySections();
- System.out.println("Please Enter the Desired Option");
- section = keyboard.nextInt();
- }
- }
- }
- //PART18 Return list of all messgaes by email and specified date
- else if (option2 == 5)
- {
- System.out.println("Please enter the senders email address: ");
- String email = keyboard.nextLine();
- System.out.println("First date, Please enter the year: ");
- int y1 = keyboard.nextInt();
- System.out.println("First date, Please enter the month: ");
- int m1 = keyboard.nextInt();
- System.out.println("First date, Please enter the day: ");
- int d1 = keyboard.nextInt();
- System.out.println("Second Date, Please enter the year: ");
- int y2 = keyboard.nextInt();
- System.out.println("Second Date, Please enter the month: ");
- int m2 = keyboard.nextInt();
- System.out.println("Second Date, Please enter the day: ");
- int d2 = keyboard.nextInt();
- ArrayList<Message> list = new ArrayList<>();
- list = messageStore.MessagesByEmailAndDates(email, y1, m1, d1, y2, m2, d2);
- messageStore.display(list);
- }
- else if (option2 == 6)
- {
- ArrayList<Employee> listOfAllEmp = new ArrayList<>();
- listOfAllEmp = employeeStore.getAllEmployee();
- employeeStore.displayAll(listOfAllEmp);
- }
- else if (option2 == 7)
- {
- ArrayList<Employee> listOfAllAgents = new ArrayList<>();
- listOfAllAgents = employeeStore.getAgentList();
- employeeStore.displayAll(listOfAllAgents);
- }
- else if (option2 == 8)
- {
- // getTotalSalaryOfEmployeesMonth();
- }
- System.out.println("Please Enter The desired Employee option: ");
- option2 = keyboard.nextInt();
- }
- if (option2 == 9)
- {
- multiPurposeMethods.displaySections();
- System.out.println("Please Enter the Desired Option");
- section = keyboard.nextInt();
- }
- }
- if (section == 3)
- {
- employeeStore.updateFile();
- messageStore.updateFile();
- System.out.println("You have closed the programme!");
- System.out.print("-----------------------------");
- }
- if (section <= 0 || section > 3)
- {
- System.out.println("Not a Valid option,Please go again..");
- section = keyboard.nextInt();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement