Skip to content

Commit

Permalink
Level 3
Browse files Browse the repository at this point in the history
Completed Level 3. Mark as Done

Implement "todo" command from level 4 for use to add tasks with multiple words
  • Loading branch information
gachia committed Aug 21, 2019
1 parent eeb23ea commit b73aaee
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,36 @@ public static void main(String[] args) {
String startMessage = lineSpace + "Hello! I'm Duke\nWhat can I do for you?\n" + lineSpace;
System.out.println(startMessage);
Scanner sc = new Scanner(System.in);
ArrayList<String> list = new ArrayList();
ArrayList<Task> list = new ArrayList();
while(sc.hasNext()){
String userInput = sc.nextLine();
if(userInput.equals("bye")){
String userCmd = sc.next();
if(userCmd.equals("bye")){
System.out.println(lineSpace + "Bye. Hope to see you again soon!\n" + lineSpace);
break;
}
switch(userInput) {
switch(userCmd) {
case "list":
System.out.print(lineSpace);
System.out.println(lineSpace + "Here are the tasks in your list:");
for(int i=0; i < list.size(); i++){
System.out.println(i+1 + ". " + list.get(i));
System.out.println(i+1 + "." + list.get(i));
}
System.out.print(lineSpace);
break;
case "todo":
String taskName = sc.nextLine();
taskName = taskName.trim();
list.add(new Task(taskName));
System.out.println(lineSpace + "added: " + taskName + "\n" + lineSpace);
break;
case "done":
int taskNo = sc.nextInt();
list.get(taskNo-1).markAsDone();
System.out.println(lineSpace + "Nice! I've marked this task as done:\n"
+ list.get(taskNo-1) + "\n" + lineSpace);
break;
default:
list.add(userInput);
System.out.println(lineSpace + "added: " + userInput + "\n" + lineSpace);
list.add(new Task(userCmd));
System.out.println(lineSpace + "added: " + userCmd + "\n" + lineSpace);
//Level-1 code
//System.out.println(lineSpace + "\n" + userInput + "\n" + lineSpace);
}
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class Task {
protected String description;
protected boolean isDone;

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

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

public void markAsDone() {
isDone = true;
}

public String getTask(){
String output = "[" + getStatusIcon() + "] " + description;
return output;
}

@Override
public String toString(){
return getTask();
}
}

0 comments on commit b73aaee

Please sign in to comment.