Skip to content

Commit

Permalink
Level-6: Delete
Browse files Browse the repository at this point in the history
  • Loading branch information
gx-huang committed Jan 21, 2020
1 parent 47cdd69 commit 00963bc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public static void main(String[] args) {
int taskNo = Integer.parseInt(context);
tasks.markDone(taskNo);

} else if (action.equalsIgnoreCase("delete")) {
String context = command_broken[1];
int taskNo = Integer.parseInt(context);
tasks.removeTask(taskNo);

} else if (action.equalsIgnoreCase(("deadline"))) {
String context = command_broken[1];
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/UserText.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,39 @@
import java.util.List;

public class UserText {
private List<Task> userInput;
private List<Task> allTasks;

public UserText() {
userInput = new ArrayList<>();
allTasks = new ArrayList<>();
}

public void addInput(Task s) {
this.userInput.add(s);
System.out.println("Now you have " + userInput.size() + " tasks in the list.");
this.allTasks.add(s);
System.out.println("Now you have " + allTasks.size() + " tasks in the list.");
}

public void printInputs() {
int count = 1;
System.out.println("Here is your list");
for (Task s : userInput) {
for (Task s : allTasks) {
System.out.println(count + ". " + s);
count++;
}
}

public Task getTask(int n) {
return this.userInput.get(n-1);
return this.allTasks.get(n-1);
}

public void markDone(int taskNo) {
userInput.get(taskNo - 1).markAsDone();
allTasks.get(taskNo - 1).markAsDone();
System.out.println("Nice! I marked this task as done");
}

public void removeTask(int taskNo) {
Task tempTask = allTasks.remove(taskNo - 1);
System.out.println("Noted. I have removed this task");
System.out.println(" " + tempTask);
System.out.println("Now you have " + allTasks.size() + " tasks in the list.");
}
}

0 comments on commit 00963bc

Please sign in to comment.