Skip to content

Commit 2f08961

Browse files
committed
Level 3. Mark as done
1 parent 136f1a6 commit 2f08961

File tree

2 files changed

+67
-6
lines changed

2 files changed

+67
-6
lines changed

src/main/java/Duke.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import duke.pack.Task;
2+
13
import java.util.Scanner;
24
import java.util.ArrayList;
35

46
public class Duke {
57
// ArrayList of tasks
6-
private static ArrayList<String> arrList;
8+
private static ArrayList<Task> arrList;
79

810
public static void main(String[] args) {
911
// Scanner object
@@ -19,12 +21,21 @@ public static void main(String[] args) {
1921

2022
// continue processing user's command, as long as command is not bye
2123
while (!command.equals("bye")) {
24+
String[] c = command.split(" ");
25+
2226
if (command.equals("list")) {
2327
// prints tasks in list if command is list
2428
printList();
29+
30+
} else if (c[0].equals("done")){
31+
// mark the specified task as done
32+
int taskNum = Integer.parseInt(c[1]);
33+
arrList.get(taskNum - 1).markAsDone();
34+
2535
} else {
2636
// add task to list
27-
add(command);
37+
Task t = new Task(command);
38+
add(t);
2839
}
2940

3041
command = sc.nextLine();
@@ -67,12 +78,12 @@ public static void echo(String comm) {
6778

6879
/**
6980
* adds user's command to arrList
70-
* @param comm command given by user
81+
* @param t command given by user
7182
*/
72-
public static void add(String comm) {
73-
arrList.add(comm);
83+
public static void add(Task t) {
84+
arrList.add(t);
7485
System.out.println(" ------------------------------------------------------------");
75-
System.out.println(" added: " + comm);
86+
System.out.println(" added: " + t);
7687
System.out.println(" ------------------------------------------------------------");
7788
}
7889

@@ -81,6 +92,8 @@ public static void add(String comm) {
8192
*/
8293
public static void printList() {
8394
System.out.println(" ------------------------------------------------------------");
95+
System.out.println(" Here are your tasks:");
96+
8497
for (int i = 1; i <= arrList.size(); i++) {
8598
System.out.println(" " + i + ". " + arrList.get(i - 1));
8699
}

src/main/java/duke/pack/Task.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package duke.pack;
2+
3+
public class Task {
4+
protected String description;
5+
protected boolean isDone;
6+
7+
/**
8+
* creates a task with the specified description
9+
* @param description the task description
10+
*/
11+
public Task(String description) {
12+
this.description = description;
13+
this.isDone = false;
14+
}
15+
16+
/**
17+
* gets the status of task, whether it is done or not
18+
* @return A string that shows the corresponding tick/cross symbol
19+
*/
20+
public String getStatusIcon() {
21+
return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols
22+
}
23+
24+
/**
25+
* gets description of task
26+
* @return a string that is the task's description
27+
*/
28+
public String getDescription() {
29+
return description; //return task description
30+
}
31+
32+
/**
33+
* marks the task as done
34+
*/
35+
public void markAsDone() {
36+
isDone = true;
37+
38+
System.out.println(" ------------------------------------------------------------");
39+
System.out.println(" Fantastic job! I have marked this task as done:");
40+
System.out.println(" " + description + " [" + getStatusIcon() + "] ");
41+
System.out.println(" ------------------------------------------------------------");
42+
}
43+
44+
@Override
45+
public String toString() {
46+
return (description + " [" + getStatusIcon() + "]");
47+
}
48+
}

0 commit comments

Comments
 (0)