-
Notifications
You must be signed in to change notification settings - Fork 191
[Silin Chen] iP #192
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?
[Silin Chen] iP #192
Changes from 9 commits
8bf8991
5876d3a
02672d8
d75ba2c
c77d04f
308eacf
97a6781
64e85b9
48ce882
653a21d
7f61f2d
dfcf04b
ccd2556
b4c1c68
7f4ad3f
06d40a3
d308886
2c8103d
2a89619
d41de47
3e52e94
8320297
fd35808
c492a3b
e61603d
1e115d9
2faad66
bb57228
ebba67b
999995d
4168e98
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,14 @@ | ||
| public class Deadline extends Task { | ||
|
|
||
| protected String by; | ||
|
|
||
| public Deadline(String description, String by) { | ||
| super(description); | ||
| this.by = by; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[D]" + super.toString() + "(by: " + by + ")"; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,93 @@ | ||
| import java.util.Scanner; | ||
|
|
||
|
|
||
| public class Duke { | ||
| public static void hi() { | ||
|
||
| System.out.println("Hello I'm Duke"); | ||
| System.out.println("What can I do for you?"); | ||
| } | ||
|
|
||
| public static void bye() { | ||
|
||
| System.out.println("Bye. Hope to see you again soon!"); | ||
| } | ||
|
|
||
| public static void running() { | ||
|
||
| Task[] tasks= new Task[100]; | ||
| int taskNumber = 0; | ||
| String line; | ||
| Scanner in = new Scanner(System.in); | ||
|
||
| while (true) { | ||
| //new scanner | ||
| line = in.nextLine(); | ||
| //if goodbye | ||
| if (line.equals("bye")) { | ||
| return; | ||
| } | ||
| //if want to list out tasks or mark as done or add items | ||
| if (line.equals("list")) { | ||
| for (int i = 0; i < taskNumber; i++) { | ||
| System.out.println((i + 1) + "." + tasks[i]); | ||
| } | ||
|
||
| } else if (line.startsWith("done")) { | ||
| int index = Integer.parseInt(line.substring(5)) - 1; | ||
| tasks[index].setDone(); | ||
| System.out.println("Nice! I've marked this task as done:"); | ||
| System.out.println(" " + tasks[index].getStatusIcon() + " " + tasks[index].getDescription()); | ||
| } else if (line.startsWith("todo")) { | ||
| tasks[taskNumber] = new ToDo(line.substring(5)); | ||
| taskNumber++; | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(" " + tasks[taskNumber - 1]); | ||
| System.out.println("Now you have " + taskNumber + " tasks in the list"); | ||
| } else if (line.startsWith("deadline")) { | ||
| String[] words = line.split(" "); | ||
| int index = 0; | ||
| String deadlineDescription = ""; | ||
| String by = ""; | ||
| for (int i = 0; i < words.length; i++) { | ||
| if (words[i].equals("/by")) { | ||
| index = i; | ||
| break; | ||
| } | ||
| } | ||
| for (int i = 1; i < index; i++) { | ||
| deadlineDescription = deadlineDescription + words[i] + " "; | ||
| } | ||
| by = words[index + 1]; | ||
| tasks[taskNumber] = new Deadline(deadlineDescription, by); | ||
| taskNumber++; | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(" " + tasks[taskNumber - 1]); | ||
| System.out.println("Now you have " + taskNumber + " tasks in the list"); | ||
| } else if (line.startsWith("event")) { | ||
| String[] words = line.split(" "); | ||
| int index = 0; | ||
| String eventDescription = ""; | ||
| String at = ""; | ||
| for (int i = 0; i < words.length; i++) { | ||
| if (words[i].equals("/at")) { | ||
| index = i; | ||
| break; | ||
| } | ||
| } | ||
| for (int i = 1; i < index; i++) { | ||
| eventDescription = eventDescription + words[i] + " "; | ||
| } | ||
| for (int i = index + 1; i < words.length; i++) { | ||
| at = at + words[i] + " "; | ||
| } | ||
| tasks[taskNumber] = new Event(eventDescription, at); | ||
| taskNumber++; | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(" " + tasks[taskNumber - 1]); | ||
| System.out.println("Now you have " + taskNumber + " tasks in the list"); | ||
| } | ||
|
||
| } | ||
| } | ||
|
||
|
|
||
| public static void main(String[] args) { | ||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| hi(); | ||
| running(); | ||
| bye(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| public class Event extends Task { | ||
|
|
||
| protected String at; | ||
|
|
||
| public Event(String description, String at) { | ||
| super(description); | ||
| this.at = at; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[E]" + super.toString() + "(at: " + at + ")"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| public class Task { | ||
| protected String description; | ||
| protected boolean isDone; | ||
|
|
||
| public Task(String description) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| public void setDone() { | ||
| this.isDone = true; | ||
| } | ||
|
||
|
|
||
| public String getDescription() { | ||
| return this.description; | ||
| } | ||
|
|
||
| public String getStatusIcon() { | ||
| return (isDone ? "[X]" : "[ ]"); // mark done task with X | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return this.getStatusIcon() + " " + this.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); | ||
| } | ||
|
|
||
| @Override | ||
| 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.
Clear! Reader would not be confused.