11package model ;
22
3+ import exceptions .IllegalPositionException ;
4+
35import java .time .LocalDate ;
46
57import java .util .ArrayList ;
@@ -65,9 +67,15 @@ public String add(Task task) {
6567 * @param position A position within the bound of the list.
6668 * @return response of the remove action.
6769 */
68- public String remove (int position ) {
70+ public String remove (int position ) throws IllegalPositionException {
6971 assert this .internalList .size () > 0 : "task list is empty, cannot delete" ;
7072
73+
74+ if (position < 0 || position >= internalList .size ()) {
75+ throw new IllegalPositionException ("Oops!!! The input position "
76+ + Integer .toString (position )
77+ + " is out of the boundary!\n " );
78+ }
7179 Task deletedTask = internalList .get (position );
7280 internalList .remove (position );
7381 return ECHO_DELETE_TASK
@@ -84,9 +92,14 @@ public String remove(int position) {
8492 * @param position A position within the bound of the list.
8593 * @return response of the mark action.
8694 */
87- public String markTaskAsDone (Integer position ) {
95+ public String markTaskAsDone (int position ) throws IllegalPositionException {
8896 assert this .internalList .size () > 0 : "task list is empty, cannot mark" ;
8997
98+ if (position < 0 || position >= internalList .size ()) {
99+ throw new IllegalPositionException ("Oops!!! The input position "
100+ + Integer .toString (position )
101+ + " is out of the boundary!\n " );
102+ }
90103 Task finishedTask = this .internalList .get (position );
91104 finishedTask .markAsDone ();
92105 return ECHO_COMPLETE_TASK
0 commit comments