forked from nusCS2113-AY1920S1/duke
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
039658d
commit dffa4d5
Showing
2 changed files
with
55 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,53 @@ | ||
import java.util.*; | ||
|
||
public class Duke{ | ||
public static void printStr(String str) { | ||
System.out.println(str); | ||
} | ||
|
||
public static void main(String[] args) { | ||
//DECLARE | ||
String str = "This is the\n" | ||
+ " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n\n" | ||
+ "Hello! What can I do for you?"; | ||
+ " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n\n" | ||
+ "Hello! What can I do for you?"; | ||
Scanner scanner = new Scanner(System.in); | ||
Boolean stay = true; | ||
List<String> stuff = new ArrayList<String>(); | ||
//SHOW | ||
System.out.println(str); | ||
//UH OH | ||
ArrayList<Task> stuff = new ArrayList<Task>(); | ||
int x = 0; | ||
|
||
//START HERE | ||
printStr(str); | ||
while(stay){ | ||
str = scanner.nextLine(); | ||
switch(str){ | ||
String[] part = str.split(" ", 2); | ||
switch(part[0]){ | ||
case "bye": | ||
stay = false; | ||
break; | ||
case "done": | ||
x = Integer.parseInt(part[1]) - 1; | ||
stuff.get(x).markAsDone(); | ||
printStr("Nice! I've marked this task as done:"); | ||
printStr("[" + stuff.get(x).getStatusIcon() + "] " + stuff.get(x).getDescription()); | ||
break; | ||
case "list": | ||
System.out.println(stuff); | ||
printStr("Here are the tasks in your list:"); | ||
x = 0; | ||
for(Task t : stuff){ | ||
x++; | ||
printStr(x + ".[" + t.getStatusIcon() + "] " + t.getDescription()); | ||
} | ||
break; | ||
default: | ||
stuff.add(str); | ||
System.out.println("added: " + str); | ||
stuff.add(new Task(str)); | ||
printStr("added: " + str); | ||
} | ||
} | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
printStr("Bye. Hope to see you again soon!"); | ||
scanner.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//import java.util.*; | ||
|
||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getDescription() { | ||
return this.description; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols | ||
} | ||
|
||
public void markAsDone() { | ||
this.isDone = true; | ||
} | ||
} |