Skip to content

Commit

Permalink
Level-3: Mark as Done
Browse files Browse the repository at this point in the history
  • Loading branch information
gx-huang committed Jan 21, 2020
1 parent 5bd8340 commit 29c6129
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
13 changes: 10 additions & 3 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import java.util.Scanner;
import java.lang.Integer;

public class Duke {
public static void main(String[] args) {
Expand All @@ -13,7 +14,7 @@ public static void main(String[] args) {
Scanner input = new Scanner(System.in);

boolean isListening = true;
UserText inputs = new UserText();
UserText tasks = new UserText();

while(isListening) {
String command = input.nextLine();
Expand All @@ -22,10 +23,16 @@ public static void main(String[] args) {
System.out.println("Bye. Hope to see you again soon!");
isListening = false;
} else if (command.equalsIgnoreCase("list")) {
inputs.printInputs();
tasks.printInputs();
} else if (command.length()>3
&& command.substring(0,4).equalsIgnoreCase("done")) {
String s[] = command.split(" ");
int taskNo = Integer.parseInt(s[1]);
tasks.markDone(taskNo);

} else {
System.out.println(command);
inputs.addInput(command);
tasks.addInput(new Task(command));
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public class Task {
protected String description;
protected boolean isDone;

public Task(String description) {
this.description = description;
this.isDone = false;
}

public String getStatusIcon() {
return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols
}

public void markAsDone() {
this.isDone = true;
System.out.println(this);
}

@Override
public String toString() {
return "[" + this.getStatusIcon() + "] "
+ description;
}
}
15 changes: 12 additions & 3 deletions src/main/java/UserText.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@
import java.util.List;

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

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

public List<String> addInput(String s) {
public List<Task> addInput(Task s) {
this.userInput.add(s);
return this.userInput;
}

public void printInputs() {
int count = 1;
for (String s : userInput) {
for (Task s : userInput) {
System.out.println(count + ". " + s);
count++;
}
}

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

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

0 comments on commit 29c6129

Please sign in to comment.