-
Notifications
You must be signed in to change notification settings - Fork 197
[paklongchiu] 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?
[paklongchiu] iP #192
Changes from 8 commits
a8435c7
1f4bfd9
0144f1c
e3bd341
7ce0ae2
0643a10
9ac4899
dd8334e
cb07f89
6771044
1eea51f
02b0f40
4f3ad6c
9be6807
9902379
217a2dd
5d4692d
bd41e9f
a8c554c
934cd37
27f12a9
ef12c47
bc5e903
21a639f
3dc8f6a
f5a0f9d
03f4d46
071a94a
620b83e
1c329ea
9cc84c0
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # Duke User Guide | ||
| # Elyk User Guide | ||
|
|
||
| // Update the title above to match the actual product name | ||
|
|
||
|
|
||
| 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 + ")"; | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Elyk { | ||
| public static int taskCounter = 0; | ||
| public static int taskNum = 0; | ||
| public static String input = ""; | ||
| public static String description = ""; | ||
| public static String from = ""; | ||
| public static String to = ""; | ||
| public static String by = ""; | ||
| public static Task[] taskList = new Task[100]; | ||
| public static Scanner command = new Scanner(System.in); | ||
|
|
||
| public static void main(String[] args) { | ||
| greet(); | ||
|
||
|
|
||
| while (true) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of while(true), maybe you can consider using this instead: do { |
||
| updateInput(); | ||
| switch (input) { | ||
| case "bye": | ||
| sayBye(); | ||
| System.exit(0); | ||
| case "list": | ||
| printTask(); | ||
| break; | ||
| case "mark": | ||
| markTaskDone(taskNum); | ||
| break; | ||
| case "unmark": | ||
| markTaskNotDone(taskNum); | ||
| break; | ||
| case "todo": | ||
| taskList[taskCounter++] = new Todo(description); | ||
|
||
| inputTask(); | ||
| break; | ||
| case "deadline": | ||
| taskList[taskCounter++] = new Deadline(description, by); | ||
| inputTask(); | ||
| break; | ||
| case "event": | ||
| taskList[taskCounter++] = new Event(description, from, to); | ||
| inputTask(); | ||
| break; | ||
| default: | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static void greet() { | ||
| String greet = "Hello! I'm Elyk\n" + | ||
| "What can I do for you?\n"; | ||
| System.out.println(greet); | ||
| } | ||
|
|
||
| public static void sayBye() { | ||
| String bye = "Bye. Hope to see you again soon!"; | ||
| System.out.println(bye); | ||
| } | ||
|
|
||
| public static void updateInput() { | ||
| input = command.nextLine(); | ||
| if (input.startsWith("mark") || input.startsWith("unmark")) { | ||
| String[] words = input.split(" "); | ||
| input = words[0]; | ||
| taskNum = Integer.parseInt(words[1]); | ||
|
||
| } else if (input.startsWith("todo")) { | ||
| description = input.substring(5); | ||
| input = "todo"; | ||
| } else if (input.startsWith("deadline")) { | ||
| int byPos = input.indexOf("/by"); | ||
| by = input.substring(byPos + 4); | ||
| description = input.substring(9, byPos - 1); | ||
| input = "deadline"; | ||
| } else if (input.startsWith("event")) { | ||
| int fromPos = input.indexOf("/from"); | ||
| int toPos = input.indexOf("/to"); | ||
| to = input.substring(toPos + 4); | ||
| from = input.substring(fromPos + 6, toPos - 1); | ||
| description = input.substring(6, fromPos - 1); | ||
|
||
| input = "event"; | ||
| } | ||
|
||
| } | ||
|
|
||
| public static void markTaskDone(int taskNum) { | ||
| taskList[taskNum - 1].markAsDone(); | ||
| System.out.println("Nice! I've marked this task as done:"); | ||
| System.out.println(" " + taskList[taskNum - 1]); | ||
| } | ||
|
|
||
| public static void markTaskNotDone(int taskNum) { | ||
| taskList[taskNum - 1].markAsNotDone(); | ||
|
||
| System.out.println("OK, I've marked this task as not done yet:"); | ||
| System.out.println(" " + taskList[taskNum - 1]); | ||
| } | ||
|
|
||
| public static void inputTask() { | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(" " + taskList[taskCounter - 1]); | ||
| System.out.println("Now you have " + taskCounter + " tasks in the list."); | ||
| } | ||
|
|
||
| public static void printTask() { | ||
| System.out.println("Here are the tasks in your list:"); | ||
| for (int i = 0; i < taskCounter; i++) { | ||
| System.out.println((i+1) + "." + taskList[i]); | ||
|
||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| public class Event extends Task { | ||
|
|
||
| protected String from; | ||
| protected String to; | ||
|
|
||
| public Event(String description, String from, String to) { | ||
| super(description); | ||
| this.from = from; | ||
| this.to = to; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[E]" + super.toString() + " (from: " + from + " to: " + to + ")"; | ||
| } | ||
| } |
| 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 String getStatusIcon() { | ||
| return (isDone ? "X" : " "); | ||
| } | ||
|
|
||
| public void markAsDone() { | ||
| isDone = true; | ||
| } | ||
|
|
||
| public void markAsNotDone() { | ||
| isDone = false; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[" + getStatusIcon() + "] " + description; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| 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.
The naming of these variables might suggest that they are the same. Maybe you can consider renaming them to make them clearer and more distinct.