@@ -113,6 +113,14 @@ public void chatDuke() {
113113 taskName , eventStartTime , eventEndTime , allTasks .size () + 1 );
114114 allTasks .add (event );
115115 event .printEventTask ();
116+ } else if (command .startsWith ("delete" )) {
117+ missingIndexException (command );
118+ invalidIndexException (command , allTasks .size ());
119+ String [] str = command .split (" " );
120+ int taskIndex = Integer .parseInt (str [1 ]) - 1 ;
121+ Task task = allTasks .get (taskIndex );
122+ task .printDelete ();
123+ allTasks .remove (taskIndex );
116124 } else if (command .equals ("bye" )){
117125 saidBye = true ;
118126 this .printByeMessage ();
@@ -121,6 +129,10 @@ public void chatDuke() {
121129 }
122130 } catch (DukeException d ) {
123131 System .out .println (d .getMessage ());
132+ } catch (NumberFormatException nfe ) {
133+ System .out .println ("\t ____________________________________________________________" +
134+ "\n \t ☹ OOPS!!! The task index to delete or un/mark a task cannot be a non-integer." +
135+ "\n \t ____________________________________________________________" );
124136 }
125137 }
126138 }
@@ -153,12 +165,6 @@ public void printCommandList(List<Task> allTasks) {
153165 System .out .println ("\t ____________________________________________________________" );
154166 }
155167
156- public void echoCommand (String command ) {
157- System .out .println ("\t ____________________________________________________________" +
158- "\n \t " + " added: " + command +
159- "\n \t ____________________________________________________________" );
160- }
161-
162168 public void printByeMessage () {
163169 System .out .println ("\t ____________________________________________________________" +
164170 "\n \t Bye. Hope to see you again soon!" +
@@ -207,24 +213,29 @@ public void missingIndexException(String command) throws DukeException {
207213 throw new DukeException ("\t ____________________________________________________________" +
208214 "\n \t ☹ OOPS!!! The task index to unmark a task as not done cannot be empty." +
209215 "\n \t ____________________________________________________________" );
216+ } else if (command .equals ("delete" )) {
217+ throw new DukeException ("\t ____________________________________________________________" +
218+ "\n \t ☹ OOPS!!! The task index to delete a task as not done cannot be empty." +
219+ "\n \t ____________________________________________________________" );
210220 }
211221 }
212222
213223 public void invalidIndexException (String command , int taskSize ) throws DukeException {
214- if (command .startsWith ("mark" ) || command .startsWith ("unmark" )) {
224+ if (command .startsWith ("mark" ) || command .startsWith ("unmark" )
225+ ||command .startsWith ("delete" )) {
215226 String index = command .split (" " )[1 ];
216227 int index1 = Integer .parseInt (index );
217228 if (index1 <= 0 ) {
218229 throw new DukeException ("\t ____________________________________________________________" +
219- "\n \t ☹ OOPS!!! The task index to mark a task as done cannot be zero or less." +
230+ "\n \t ☹ OOPS!!! The task index to delete or un/ mark a task cannot be zero or less." +
220231 "\n \t ____________________________________________________________" );
221232 } else if (index .equals ("" )) {
222233 throw new DukeException ("\t ____________________________________________________________" +
223- "\n \t ☹ OOPS!!! The task index to mark a task as done cannot be empty." +
234+ "\n \t ☹ OOPS!!! The task index to delete or un/ mark a task cannot be empty." +
224235 "\n \t ____________________________________________________________" );
225236 } else if (index1 > taskSize ) {
226237 throw new DukeException ("\t ____________________________________________________________" +
227- "\n \t ☹ OOPS!!! The task index to mark a task as done cannot be more than" +
238+ "\n \t ☹ OOPS!!! The task index to delete or un/ mark a task cannot be more than" +
228239 " number of tasks." +
229240 "\n \t ____________________________________________________________" );
230241 }
@@ -240,5 +251,4 @@ public void invalidCommandException(String command) throws DukeException {
240251 "\n \t ____________________________________________________________" );
241252 }
242253 }
243-
244254}
0 commit comments