|
2 | 2 |
|
3 | 3 | import java.util.Scanner; |
4 | 4 |
|
| 5 | +/** |
| 6 | + * Interface that handles user inputs and prints programme outputs |
| 7 | + */ |
5 | 8 | public class Ui { |
6 | 9 | private Scanner sc; |
7 | 10 |
|
| 11 | + /** |
| 12 | + * Constructor |
| 13 | + */ |
8 | 14 | public Ui() { |
9 | 15 | this.sc = new Scanner(System.in); |
10 | 16 | } |
11 | 17 |
|
| 18 | + /** |
| 19 | + * Reads one line of the user input |
| 20 | + * @return |
| 21 | + */ |
12 | 22 | public String readCommand() { |
13 | 23 | return this.sc.nextLine().strip(); |
14 | 24 | } |
15 | 25 |
|
| 26 | + /** |
| 27 | + * Closes the interface. |
| 28 | + * Once closed, the Ui will no longer read user inputs |
| 29 | + */ |
16 | 30 | public void close() { |
17 | 31 | this.sc.close(); |
18 | 32 | } |
19 | 33 |
|
20 | | - // format for greeting, echo and exit |
| 34 | + /** |
| 35 | + * Prints a message in the Duke format |
| 36 | + * @param message Message to be printed |
| 37 | + */ |
21 | 38 | public void printMessage(String message) { |
22 | 39 | String newMessage = message.replaceAll("\n", "\n "); |
23 | 40 | System.out.println(" ____________________________________________________________\n\n" + " " + newMessage |
24 | 41 | + "\n" + " ____________________________________________________________\n"); |
25 | 42 | } |
26 | 43 |
|
| 44 | + /** |
| 45 | + * Prints welcome message |
| 46 | + */ |
27 | 47 | public void showWelcome() { |
28 | 48 | String welcomeMessage = "Hello! I'm Duke\nWhat can I do for you?"; |
29 | 49 | printMessage(welcomeMessage); |
30 | 50 | } |
31 | 51 |
|
| 52 | + /** |
| 53 | + * Prints error for loading save file |
| 54 | + */ |
32 | 55 | public void showLoadingError() { |
33 | 56 | String loadingErrMessage = "OOPS!!! Was unable to load from save\nStarting a new task list..."; |
34 | 57 | printMessage(loadingErrMessage); |
35 | 58 | } |
36 | 59 |
|
| 60 | + /** |
| 61 | + * Shows error for reading save file |
| 62 | + */ |
37 | 63 | public void showReadingError() { |
38 | 64 | String loadingErrMessage = "OOPS!!! Was unable to parse save file\nStarting a new task list..."; |
39 | 65 | printMessage(loadingErrMessage); |
40 | 66 | } |
41 | 67 |
|
| 68 | + /** |
| 69 | + * Shows goodbye message |
| 70 | + */ |
42 | 71 | public void showGoodbye() { |
43 | 72 | String goodbyeMessage = "Bye. Hope to see you again soon!"; |
44 | 73 | printMessage(goodbyeMessage); |
|
0 commit comments