Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Commit

Permalink
Merge branch 'branch-Level-6'
Browse files Browse the repository at this point in the history
  • Loading branch information
fsgmhoward committed Feb 14, 2021
2 parents 5a8c41c + b6cc5ad commit 9290969
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/main/java/duke/ActionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ protected static void byeHandler() {

// Print out everything in the list, index starts from 1
protected static void listHandler(Vector<Task> tasks) {
if (tasks.size() == 0) {
Helper.printlnWithIndent("You don't have a task in your list!");
return;
}
Helper.printlnWithIndent("Here are the tasks in your list:");
for (int i = 0; i < tasks.size(); i += 1) {
Helper.printlnWithIndent(String.format("%d.\t%s", i + 1, tasks.get(i)));
Expand Down Expand Up @@ -55,6 +59,28 @@ protected static void doneHandler(Vector<Task> tasks, String[] arguments) throws
}
}

// Delete a task from the list
protected static void deleteHandler(Vector<Task> tasks, String[] arguments) throws InvalidInputException {
if (arguments.length < 2) {
// An index must be provided for the task to be marked "done"
Helper.printlnWithIndent("You will need to give me an index, like this: `delete 2`.");
} else {
try {
int index = Integer.parseInt(arguments[1]);
if (index > tasks.size() || index < 1) {
// This index is out of the boundary of our database
throw new InvalidInputException(InputExceptionType.INDEX_OUT_OF_BOUND);
}

Task task = tasks.remove(index - 1);
Helper.printlnWithIndent("Sure! I've removed this task:");
Helper.printlnWithIndent("\t" + task);
} catch (NumberFormatException e) {
throw new InvalidInputException(InputExceptionType.NOT_INTEGER, e);
}
}
}

// Create a deadline task
protected static void deadlineHandler(Vector<Task> tasks, String[] arguments) throws InvalidInputException {
int i = Helper.findIndex(arguments, "/by");
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public static void main(String[] args) {
case "done":
ActionHandler.doneHandler(tasks, arguments);
break;
case "delete":
ActionHandler.deleteHandler(tasks, arguments);
break;
case "deadline":
ActionHandler.deadlineHandler(tasks, arguments);
break;
Expand Down
30 changes: 30 additions & 0 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,35 @@
3. [D][✓] Deadline A (by: 1 Aug 2021)
------------------------------------------------------------
------------------------------------------------------------
Oops! We don't have an existing entry with this index.
------------------------------------------------------------
------------------------------------------------------------
Oops! Only integer is accepted as the argument.
------------------------------------------------------------
------------------------------------------------------------
Oops! We don't have an existing entry with this index.
------------------------------------------------------------
------------------------------------------------------------
Here are the tasks in your list:
1. [T][✓] Task A
2. [E][✓] Event A (at: 1 Apr 2021)
3. [D][✓] Deadline A (by: 1 Aug 2021)
------------------------------------------------------------
------------------------------------------------------------
Sure! I've removed this task:
[T][✓] Task A
------------------------------------------------------------
------------------------------------------------------------
Sure! I've removed this task:
[D][✓] Deadline A (by: 1 Aug 2021)
------------------------------------------------------------
------------------------------------------------------------
Sure! I've removed this task:
[E][✓] Event A (at: 1 Apr 2021)
------------------------------------------------------------
------------------------------------------------------------
You don't have a task in your list!
------------------------------------------------------------
------------------------------------------------------------
Bye. Hope to see you again soon!
------------------------------------------------------------
8 changes: 8 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ done -1
done Not_A_Number
done 1000
list
delete -1
delete Not_A_Number
delete 1000
list
delete 1
delete 2
delete 1
list
bye
6 changes: 5 additions & 1 deletion text-ui-test/runtest.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env bash
cwd=$(pwd)
cd $(dirname "$0")

# create bin directory if it doesn't exist
if [ ! -d "../bin" ]
Expand Down Expand Up @@ -35,4 +37,6 @@ then
else
echo "Test result: FAILED"
exit 1
fi
fi

cd $cwd

0 comments on commit 9290969

Please sign in to comment.