Skip to content

Commit

Permalink
Add Marking
Browse files Browse the repository at this point in the history
Tasks cannot be marked as done or not done yet.

Add functionality for marking and unmarking
  • Loading branch information
rgonslayer committed Aug 24, 2022
1 parent 8d259a9 commit 6164900
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,51 @@ public class Duke {
public static void main(String[] args) {
Scanner inputScanner = new Scanner(System.in);

String nextInstruction;
String nextTask;
String introduction = "Hello! I'm Jarvis \n"
+ "What can I do for you?";
String farewell = "Bye. Hope to see you again soon!";
int curr = 0;

String[] taskList = new String[100];
Task[] taskList = new Task[100];

System.out.println(introduction);

while (true) {
nextInstruction = inputScanner.nextLine();
nextTask = inputScanner.nextLine();

if (nextInstruction.equals("bye")) {
if (nextTask.equals("bye")) {
break;
}

if (nextInstruction.equals("list")) {
if (nextTask.equals("list")) {
for (int i = 0; i < taskList.length; i ++) {
if (taskList[i] == null) {
break;
}
System.out.println((i + 1) + ". " + taskList[i]);
System.out.println((i + 1) + ". " + taskList[i].toString());
}
continue;
}

taskList[curr] = nextInstruction;
curr++;
if (nextTask.length() > 4 && nextTask.substring(0,4).equals("mark")) {
int toMark = Integer.parseInt(nextTask.substring(5)) - 1;
taskList[toMark].mark();
String markResponse = "Nice! I've marked this task as done:\n ";
System.out.println(markResponse + taskList[toMark].toString());
continue;
}

if (nextTask.length() > 6 && nextTask.substring(0,6).equals("unmark")) {
int toMark = Integer.parseInt(nextTask.substring(7)) - 1;
taskList[toMark].unmark();
String markResponse = "Ok, I've marked this task as not done yet:\n ";
System.out.println(markResponse + taskList[toMark].toString());
continue;
}

taskList[Task.count] = new Task(nextTask);

System.out.println("added: " + nextInstruction);
System.out.println("added: " + nextTask);

}

Expand Down
30 changes: 30 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
public class Task {
protected String description;
protected boolean isDone;

protected static int count = 0;

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

public void mark(){
isDone = true;
}

public void unmark() {
isDone = false;
}

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

@Override
public String toString() {
return "[" + getStatusIcon() + "] " + this.description;
}

}

0 comments on commit 6164900

Please sign in to comment.