Class MessageApp

Object
MessageApp

public class MessageApp extends Object
  • Field Details

  • Constructor Details

    • MessageApp

      public MessageApp(ArrayList<OpenMessage> messages)
      Initialize the ArrayList of OpenMessages
      Parameters:
      messages - ArrayList of OpenMessages
  • Method Details

    • go

      public void go()
      Runs the program, keep going until user input is "x". If "x" is entered, stop the program.
    • processCommand

      public void processCommand(String command)
      Checks the command (options from the menu) and calls appropriate methods for its functionality. Does nothing if a command is not known (no need for help dialog). Implemented in Lab 12
      Parameters:
      command - command entered by user
    • keyByName

      public int keyByName(String keyName)
      A helper method that searches through the keys list to see if a Key exists for a particular user. This search ignores case and spacing, so "Cheshire Cat" and "cheshirecat" will match. You can use the .trim() method on a String to remove spaces. If the Key is found, return the index where the Key is found in the keys list. If the Key is not found after the entire search, return -1.
      Parameters:
      keyName - Name of user that will compare to each Key's name in the keys list
      Returns:
      int index of where Key is in the keys list if found, or -1 if not found
    • searchHelper

      private String searchHelper()
      Asks user for what type of search and what they are searching for, then returns the message if found. Implemented in Lab 10.
      Returns:
      String that is a list of all messages found that satisfy the search
    • composeHelper

      private void composeHelper()
      This method will be modified from Lab 12.

      It should:

      • Get input from user about TO, FROM, SUBJECT, and BODY information.
      • Ask user what file they would like to write the message to.
      • Inside a try/catch block, make a new PrintWriter to the file the user chose.
      • Make a Scanner that reads from "key.txt"
      • While the Scanner has lines, split the line on commas. Use the information from the line to construct a new Key object and add the Key to the keys list. HINT: There are many ways to implement this, but a simple solution is to create a String array, and use the .split() method on the Scanner nextLine to split the line at every comma, breaking up your information and storing it in the String array. This is very common for CSV files, or "Comma-separated-values". You can then access the proper index of the array to get the information needed to make your new Key object.
      • Some users have a Key associated with their name, and others do not. If there is a Key for a particular recipient (message's "TO"), meaning the result of searching for the Key in the keys list is >-1 (HINT: Remember your helper methods!), then make an EncryptedMessage object and encrypt the BODY of the message based on encryption type. Your boss decided that instead of encrypting TO, FROM, and SUBJECT, the program should only encrypt the BODY portion. Print the message with encrypted body to the PrintWriter. If there is no Key found for the recipient, then create an OpenMessage and print your message to the PrintWriter with no encryption.
      • Add your newly composed message to the messages list.
      • Don't forget to close your PrintWriter and catch a FileNotFoundException!