/*
  * Prints the mail help informaton.
  */
 private void showHelp() {
   Terminal.println("Mail Help:");
   Terminal.println("\t ?\t\t\tThis help information");
   Terminal.println("\t i\t\t\tDisplay inbox");
   Terminal.println("\t [n]\t\tRead Message [n]");
   Terminal.println("\t q\t\t\tQuit Mail");
 }
    /*
     * Shows the contents of the inbox.
     */
    private void showInbox() {
      Terminal.println("id\t\t\t from\t\t\t\t\t  " + "date\t\t\t\t\t   subject");

      List<Mail> mail = mailbox.getAllMail();
      Mail m;
      int tabCount;

      for (int i = 0; i < mail.size(); i++) {
        m = mail.get(i);

        // Print number
        if (i < 10) {
          Terminal.print(' ');
        }
        Terminal.print(i + " ");

        // Print sender
        Terminal.print(m.getSender());
        tabCount = 7 - (int) Math.round((double) m.getSender().length() / ScreenBuffer.TAB_LENGTH);
        printTabs(tabCount);

        // Print date
        Terminal.print(m.getDate());
        tabCount = 6 - (int) Math.floor((double) m.getDate().length() / ScreenBuffer.TAB_LENGTH);
        printTabs(tabCount);

        // Print subject
        Terminal.print(m.getSubject());
        Terminal.println();
      }
    }
 /*
  * Opens a mail.
  */
 private void openMail(int id) {
   Mail m = mailbox.getMail(id);
   Terminal.println();
   if (m != null) {
     m.open();
     Terminal.println();
   }
 }
    @Override
    protected void run() {
      String input;

      // Simple input loop
      while (isRunning()) {
        Terminal.print(getPrompt());
        input = Terminal.readLine();
        if (input.equalsIgnoreCase("quit")) {
          Terminal.println("It's been nice talking with you!  " + "Goodbye!");
          terminate();
        } else {
          /* Alicia gives a random response regardless of what the
             user types. What a great listener!
          */
          Terminal.println(getRandomResponse());
        }
      }
    }
    @Override
    protected void run() {
      String input;

      while (isRunning()) {
        // Print prompt
        Terminal.print(getPrompt());

        // Read input from the user
        input = Terminal.readLine();

        // Check if the user typed one of the mail commands
        switch (input) {
          case "i":
            showInbox();
            continue;
          case "q":
            terminate();
            continue;
          case "?":
            showHelp();
            continue;
        }

        String mailIDStr = "";
        char c;

        // Extracts a number from the user-typed string
        for (int i = 0; i < Math.min(4, input.length()); i++) {
          c = input.charAt(i);
          if (c > 0x29 && c < 0x3A) {
            // Append the character if it is a numeric char
            mailIDStr += c;
          } else {
            // Break at the first occurance of a non-numeric char
            break;
          }
        }

        if (mailIDStr.isEmpty()) {
          Terminal.println(DEFAULT_MESSAGE);
          continue;
        }

        // Open the specified mail
        int mailID = Integer.parseInt(mailIDStr);
        openMail(mailID);
      }
    }
 @Override
 protected void onLaunch() {
   showInbox();
   Terminal.println(DEFAULT_MESSAGE);
 }
 @Override
 protected void onLaunch() {
   Terminal.println("Welcome to Alicia, your virtual therapist.  " + "(type quit to exit)");
 }