@@ -24,19 +24,20 @@ private enum Command {
2424 DEADLINE ,
2525 EVENT ,
2626 DELETE ,
27- FIND
27+ FIND ,
28+ HI
2829 }
2930
3031 /**
3132 * Parses the user input and performs the corresponding action.
3233 *
3334 * @param userInput the user input to be parsed
3435 * @param taskList the TaskList object to perform actions on
35- * @return true if the application should continue running, false otherwise
36+ * @return response from chatbot
3637 * @throws MondayExceptions if there are errors related to the Monday application
3738 * @throws IllegalArgumentException if the user input is in the wrong format
3839 */
39- public static boolean mondayParser (String userInput , TaskList taskList ) throws MondayExceptions {
40+ public static String mondayParser (String userInput , TaskList taskList ) throws MondayExceptions {
4041 String [] input = userInput .split (" " , 2 );
4142 String command = input [0 ];
4243 String content = input .length > 1 ? input [1 ] : null ;
@@ -45,20 +46,19 @@ public static boolean mondayParser(String userInput, TaskList taskList) throws M
4546
4647
4748 switch (commandEnum ) {
49+ case HI :
50+ return Ui .greet ();
4851 case BYE :
49- Ui .exit ();
50- return false ;
52+ return Ui .exit ();
5153 case LIST :
52- taskList .displayList ();
53- break ;
54+ return taskList .displayList ();
5455 case MARK : {
5556 if (content == null ) {
5657 throw new MondayExceptions ("Mark requires a index to mark the task as completed." );
5758 }
5859 int index = Integer .parseInt (content );
5960
60- taskList .mark (index );
61- break ;
61+ return taskList .mark (index );
6262 }
6363 case UNMARK : {
6464 if (content == null ) {
@@ -67,17 +67,15 @@ public static boolean mondayParser(String userInput, TaskList taskList) throws M
6767
6868 int index = Integer .parseInt (content );
6969
70- taskList .unMark (index );
71- break ;
70+ return taskList .unMark (index );
7271 }
7372 case TODO :
7473 if (content == null ) {
7574 throw new MondayExceptions ("The description of a todo cannot be empty.\n "
7675 + "Usage: todo (task)" );
7776 }
7877
79- taskList .addToTask (new ToDo (content ));
80- break ;
78+ return taskList .addToTask (new ToDo (content ));
8179 case DEADLINE :
8280 try {
8381 if (content == null ) {
@@ -89,12 +87,11 @@ public static boolean mondayParser(String userInput, TaskList taskList) throws M
8987 String description = taskDetails [0 ];
9088 String date = taskDetails [1 ];
9189
92- taskList .addToTask (new Deadline (description .trim (), date .trim ()));
90+ return taskList .addToTask (new Deadline (description .trim (), date .trim ()));
9391 } catch (ArrayIndexOutOfBoundsException e ) {
9492 throw new IllegalArgumentException ("Invalid Format. "
9593 + "Usage: deadline (task) /by (time)" );
9694 }
97- break ;
9895 case EVENT :
9996 try {
10097 if (content == null ) {
@@ -108,22 +105,20 @@ public static boolean mondayParser(String userInput, TaskList taskList) throws M
108105 String start = taskTiming [0 ];
109106 String end = taskTiming [1 ];
110107
111- taskList .addToTask (new Event (description .trim (),
108+ return taskList .addToTask (new Event (description .trim (),
112109 start .trim (),
113110 end .trim ()));
114111 } catch (ArrayIndexOutOfBoundsException e ) {
115112 throw new IllegalArgumentException ("Invalid Format. "
116113 + "Usage: event (task) /from (start time) /to (end time)" );
117114 }
118- break ;
119115 case DELETE :
120116 if (content == null ) {
121117 throw new MondayExceptions ("Delete requires a index to delete the task" );
122118 }
123119 int index = Integer .parseInt (content );
124120
125- taskList .delete (index );
126- break ;
121+ return taskList .delete (index );
127122 case FIND :
128123 if (content == null ) {
129124 throw new MondayExceptions ("Find requires a keyword to find the tasks" );
@@ -136,12 +131,10 @@ public static boolean mondayParser(String userInput, TaskList taskList) throws M
136131 + "Usage: find (keyword), there should only be one keyword." );
137132 }
138133
139- taskList .find (keywordDetails [0 ]);
140- break ;
134+ return taskList .find (keywordDetails [0 ]);
141135 default :
142136 throw new MondayExceptions ("Sorry, I do not understand what that means.\n "
143137 + "Please provide a valid input/command. e.g todo read book" );
144138 }
145- return true ;
146139 }
147140}
0 commit comments