File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -158,6 +158,43 @@ public static void main(String[] args) {
158158 }
159159 break ;
160160
161+ case "delete" :
162+ System .out .println ("Enter index:" );
163+ int ind = getUserIndex .nextInt () - 1 ;
164+ if (ind < 0 || ind >= listPointer ) {
165+ System .out .println ("Invalid index." );
166+ } else {
167+
168+ System .out .println ("Noted. I've removed this task:" );
169+
170+ System .out .println (userList [listPointer ].display ());
171+
172+ Task [] newUserList = new Task [100 ];
173+
174+ for (int a = 0 , k = 0 ; a < listPointer ; a ++) {
175+
176+ // if the index is
177+ // the removal element index
178+ if (a == ind ) {
179+ continue ;
180+ }
181+
182+ // if the index is not
183+ // the removal element index
184+ newUserList [k ++] = userList [a ];
185+ }
186+
187+ listPointer = listPointer - 1 ;
188+
189+ userList = newUserList ;
190+
191+ System .out .println ("Now you have " + listPointer + " tasks in the list." );
192+
193+ }
194+
195+ break ;
196+
197+
161198 default :
162199 System .out .println ("OOPS!!! I'm sorry, but I don't know what that means :-(" );
163200
You can’t perform that action at this time.
0 commit comments