/* * 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(); } }
@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 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()); } } }
/* * Prints n tabs to the console. */ private void printTabs(int n) { for (int i = 0; i < n; i++) { Terminal.print('\t'); } }