-
Notifications
You must be signed in to change notification settings - Fork 191
[Edwin] iP #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[Edwin] iP #191
Changes from 7 commits
bcf20ee
2c2a310
da7c42b
7e2f13a
0b9ce39
074899d
4ce8ac0
c2a8cf3
e61f1e7
daef42c
3fc7b81
ed20d64
e8ce66f
acfd97c
88ad15e
d3cbc29
b573d4c
3974bd3
22af079
3c647fc
a294af8
86a9032
c3af9c5
92cbe7d
ea44036
d57c1a3
a2984d6
4a890e0
8a47b70
5217ca0
d3eb8f0
468e2f1
9c9496a
0f9c8b7
788449d
e8616f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <classpath> | ||
| <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
| <classpathentry kind="src" path="src/main/java"/> | ||
| <classpathentry kind="output" path="out/production/ip"/> | ||
| </classpath> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <projectDescription> | ||
| <name>ip</name> | ||
| <comment></comment> | ||
| <projects> | ||
| </projects> | ||
| <buildSpec> | ||
| <buildCommand> | ||
| <name>org.eclipse.jdt.core.javabuilder</name> | ||
| <arguments> | ||
| </arguments> | ||
| </buildCommand> | ||
| </buildSpec> | ||
| <natures> | ||
| <nature>org.eclipse.jdt.core.javanature</nature> | ||
| </natures> | ||
| </projectDescription> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| public class Deadlines extends Task { | ||
| protected String by; | ||
|
|
||
| public Deadlines(String description, String by) { | ||
| super(description); | ||
| this.by = by; | ||
| } | ||
|
|
||
| public String toString() { | ||
| return "[D]" + super.toString() + " (by: " + by + ")"; | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,99 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Duke { | ||
| private static Task[] items = new Task[100]; | ||
| private static int taskCount = 0; | ||
| private static String logo = " _____ ___ _____\n" | ||
| + "|___ | | ||_____| \n" | ||
| + " / / | | / / \n" | ||
| + " / / | | / / \n" | ||
| + " / /___ | | /_/__ \n" | ||
| + "|_____| | ||_____| \n"; | ||
| private static String border = "____________________________________________________________\n"; | ||
|
|
||
| public static void addedTaskMessage(Task task) { | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(task); | ||
| System.out.println("Now you have " + taskCount + " tasks in the list."); | ||
| } | ||
| public static void addEvent(String description, String time) { | ||
| Events newEvent = new Events(description, time); | ||
| items[taskCount] = newEvent; | ||
| taskCount++; | ||
| addedTaskMessage(newEvent); | ||
| } | ||
| public static void addDeadline(String description, String by) { | ||
| Deadlines newDeadline = new Deadlines(description, by); | ||
| items[taskCount] = newDeadline; | ||
| taskCount++; | ||
| addedTaskMessage(newDeadline); | ||
| } | ||
| public static void addTodo(String description) { | ||
| Todo newTodo = new Todo(description); | ||
| items[taskCount] = newTodo; | ||
| taskCount++; | ||
| addedTaskMessage(newTodo); | ||
| } | ||
| public static void addTask(String description) { | ||
| System.out.println(border + "added: " + description + '\n' + border); | ||
| Task newItem = new Task(description); | ||
| items[taskCount] = newItem; | ||
| taskCount++; | ||
| } | ||
| public static void printStartMessage() { | ||
| System.out.println(logo); | ||
| System.out.println(border + "Hi bro, my name is Echo"); | ||
| System.out.println("What do you want?\n" + border); | ||
| System.out.println("Type bye to exit\n" + border); | ||
| } | ||
| public static void printEndMessage() { | ||
| System.out.println(border); | ||
| System.out.println("chat again next time!\n" + border); | ||
| } | ||
| public static void main(String[] args) { | ||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| String line; | ||
| printStartMessage(); | ||
|
|
||
| do { | ||
|
||
| Scanner in = new Scanner(System.in); | ||
| line = in.nextLine(); | ||
| if (line.matches("list")) { | ||
| int j = 1; | ||
| System.out.println(border); | ||
| System.out.println("Here is your list"); | ||
|
|
||
| for (Task item : items) { | ||
| if (item != null) { | ||
| System.out.print(j + "."); | ||
| System.out.println(item); | ||
| j++; | ||
| } | ||
| } | ||
|
||
| System.out.println(border); | ||
|
|
||
|
||
| } else if (line.length() > 4 && line.substring(0,4).contains("done")) { | ||
|
||
| int dividerPosition = line.indexOf(" ") + 1; | ||
| int endPosition = line.length(); | ||
| if (endPosition > 5) { | ||
| String num = line.substring(dividerPosition, endPosition); | ||
| int taskNum = Integer.parseInt(num) - 1; | ||
| items[taskNum].markDone(); | ||
| System.out.println(border + "Nice! task is done " + '\n' + border); | ||
| } | ||
| } else if (line.length() > 4 && line.substring(0,4).contains("todo")) { //improve condition to first word | ||
| addTodo(line.replace("todo","").trim()); | ||
| } else if (line.length() > 5 &&line.substring(0,5).contains("event")) { | ||
| String time = line.split("/at")[1].trim(); | ||
| String description = line.split("/at")[0].trim().replace("event","").trim(); | ||
| addEvent(description, time); | ||
| } else if (line.length() > 8 && line.substring(0,8).contains("deadline")) { | ||
| String by = line.split("/by")[1].trim(); | ||
| String description = line.split("/by")[0].trim().replace("deadline","").trim(); | ||
| addDeadline(description, by); | ||
| } else { | ||
| addTask(line); | ||
| } | ||
| } while (!line.matches("bye")); | ||
| printEndMessage(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| public class Events extends Task { | ||
| protected String time; | ||
|
|
||
| public Events(String description, String time) { | ||
| super(description); | ||
| this.time = time; | ||
| } | ||
|
|
||
| public String toString() { | ||
| return "[E]" + super.toString() + " (at: " + time + ")"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| public class Task { | ||
| protected String description; | ||
| protected boolean isDone; | ||
|
|
||
| public Task(String description) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| public String getStatusIcon() { | ||
| return (isDone ? "X" : " "); // mark done task with X | ||
| } | ||
| public String getDescription() { | ||
| return this.description; | ||
| } | ||
|
|
||
| public void markDone() { | ||
| this.isDone = true; | ||
| } | ||
| public String toString() { | ||
| return "[" + getStatusIcon() + "]" + getDescription(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| public class Todo extends Task { | ||
|
|
||
| public Todo(String description) { | ||
| super(description); | ||
| } | ||
|
|
||
| public String toString() { | ||
| return "[T]" + super.toString(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it need to be past tense?