-
Notifications
You must be signed in to change notification settings - Fork 184
[yuhengr] ip #193
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?
[yuhengr] ip #193
Changes from 5 commits
cfe27b7
6db6312
efcec81
3440622
cec49c2
55b6be6
a23e514
98de3d5
b04d05d
43028d3
c504b93
894d758
17b2bac
f28f0ce
eb7ebe6
0af291b
ab8d095
1bb8666
2032036
e46f8a7
68e709b
5a43cbc
1e5b368
ff6ffbf
accdf6f
b9139c0
616a5d4
7622977
5aa8ebe
3a67fa2
dc65e62
101a9a0
86e95f3
2e41c85
6af42f4
400cc86
6738b93
6fd592c
4c0e67f
a702714
b4baa94
449d6ca
ea0b2b4
2b97a19
6152c52
f7ab8bc
0428822
ea631e8
ff8bf1e
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,3 +1,5 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Duke { | ||
| public static void main(String[] args) { | ||
| String logo = " ____ _ \n" | ||
|
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. Ditto with the comment by your peer. Remove code that is commented out! |
||
|
|
@@ -6,5 +8,72 @@ public static void main(String[] args) { | |
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
|
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. Should the logo variable be deleted since it's not used? |
||
| System.out.println("Hello from\n" + logo); | ||
| System.out.println("I'm Ekud! What can I do for you?"); | ||
|
|
||
| String userInput; | ||
| Scanner in = new Scanner(System.in); | ||
| Task[] tasks = new Task[100]; | ||
|
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. I like the use of plural form to indicate multiple tasks |
||
| int taskCount = 0; | ||
| userInput = in.nextLine(); | ||
|
|
||
| while(!userInput.equals("bye")){ | ||
| String[] words = userInput.split(" "); | ||
| if(userInput.equals("list")){ | ||
|
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. This if-else chain is nested and very long. This usually hints that there can be room for improvement for making your code SLAP more. To aid you in achieving SLAP, here are some guiding questions...
|
||
| System.out.println("Here are the tasks in your list:"); | ||
| for(int i = 0; i < taskCount; i++){ | ||
| System.out.println((i + 1) + "." + tasks[i]); | ||
| } | ||
| } | ||
| else if(words[0].equals("mark")){ | ||
| int taskIndex = Integer.parseInt(words[1]) - 1; | ||
| tasks[taskIndex].markAsDone(); | ||
| System.out.println("Nice! I've marked this task as done:"); | ||
| System.out.println(tasks[taskIndex]); | ||
| } | ||
| else if(words[0].equals("unmark")){ | ||
| int taskIndex = Integer.parseInt(words[1]) - 1; | ||
| tasks[taskIndex].markAsNotDone(); | ||
| System.out.println("OK, I've marked this task as not done yet:"); | ||
| System.out.println(tasks[taskIndex]); | ||
| } | ||
| else if(words[0].equals("todo")){ | ||
| int dividerPosition = userInput.indexOf(" "); | ||
| tasks[taskCount] = new Todo(userInput.substring(dividerPosition + 1)); | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(tasks[taskCount]); | ||
| taskCount++; | ||
| System.out.println("Now you have " + taskCount + " tasks in the list."); | ||
| } | ||
| else if(words[0].equals("deadline")){ | ||
| int dividerPosition = userInput.indexOf(" "); | ||
| int slashPosition = userInput.indexOf("/by"); | ||
| tasks[taskCount] = new Deadline(userInput.substring(dividerPosition + 1, slashPosition - 1), userInput.substring(slashPosition + 4)); | ||
|
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. Maybe you can consider line wrapping for this line also? |
||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(tasks[taskCount]); | ||
| taskCount++; | ||
| System.out.println("Now you have " + taskCount + " tasks in the list."); | ||
| } | ||
| else if(words[0].equals("event")){ | ||
| int dividerPosition = userInput.indexOf(" "); | ||
| int fromPosition = userInput.indexOf("/from"); | ||
| int toPosition = userInput.indexOf("/to"); | ||
|
|
||
| tasks[taskCount] = new Event(userInput.substring(dividerPosition + 1, fromPosition - 1), userInput.substring(fromPosition + 6, toPosition - 1), userInput.substring(toPosition + 4)); | ||
|
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. Maybe you can consider line wrapping? This line seems quite long. |
||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(tasks[taskCount]); | ||
| taskCount++; | ||
| System.out.println("Now you have " + taskCount + " tasks in the list."); | ||
| } | ||
| else{ | ||
| tasks[taskCount] = new Todo(userInput); | ||
| System.out.println("Got it. I've added this task."); | ||
| System.out.println(tasks[taskCount]); | ||
| taskCount++; | ||
| System.out.println("Now you have " + taskCount + " tasks in the list."); | ||
| } | ||
| userInput = in.nextLine(); | ||
| } | ||
|
|
||
| System.out.println("Bye. Hope to see you again soon."); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| public class Event extends Task{ | ||
|
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. Formatting error with the curly brace! |
||
|
|
||
| protected String startTime; | ||
| protected String endTime; | ||
|
|
||
| public Event(String description, String startTime, String endTime) { | ||
| super(description); | ||
| this.startTime = startTime; | ||
| this.endTime = endTime; | ||
| } | ||
|
|
||
| public String toString() { | ||
| return "[E]" + super.toString() + " (from: " + this.startTime + " to: " + this.endTime + ")"; | ||
| } | ||
| } | ||
| 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() { | ||
| this.isDone = true; | ||
| } | ||
|
|
||
| public void markAsNotDone() { | ||
| this.isDone = false; | ||
| } | ||
|
Comment on lines
+10
to
+
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. Method names are good as they sound like verbs |
||
|
|
||
| @Override | ||
| public String toString() { | ||
| return String.format("[%s] %s", this.getStatusIcon(), this.description); | ||
| } | ||
| } | ||
| 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.
Formatting error with the curly brace!