-
Notifications
You must be signed in to change notification settings - Fork 73
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
[Jingtan]iP #51
base: master
Are you sure you want to change the base?
[Jingtan]iP #51
Changes from 8 commits
65f72a8
0112efe
cfd6da7
6e6ace1
a3ca5a4
7b60e81
c4678f7
30efbae
88d53b0
507e0c5
a76509a
fe534da
9cb4fc3
c8d841c
8dd00b3
10b91e7
41b2e87
b5dffc2
49c4e44
ce678f9
21746f9
79a49ba
55b86ca
69abf30
8c5fe95
6624f8c
a6c4cc2
a28ff87
34d44a8
e149a6a
099dc7e
bb1ae6a
4116a14
51dc541
80a856b
9232bc8
c93b0d6
5a8a358
bf391b2
e4e865f
13325ba
a2d1f30
9c66984
28862e9
05c3f9f
9961085
e74dc07
d87fa9b
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,97 @@ | ||
import java.util.Scanner; | ||
public class Duke { | ||
|
||
private static 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 think it was mentioned not to use magic numbers, perhaps a static int could be used instead |
||
private static int taskCount = 0; | ||
|
||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
greet(); | ||
|
||
String userResponde; | ||
Scanner in = new Scanner(System.in); | ||
do { | ||
userResponde = in.nextLine(); | ||
dukeResponde(userResponde); | ||
|
||
}while(!userResponde.equals("bye")); | ||
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. It would be nice if there was a space between } and "while" so that it is easier to read. |
||
|
||
} | ||
|
||
public static void greet(){ | ||
printLine(); | ||
System.out.println("\tHello! I'm Duke"); | ||
System.out.println("\tWhat can I do for you?"); | ||
printLine(); | ||
System.out.println(); | ||
} | ||
|
||
public static void dukeResponde(String userResponde){ | ||
printLine(); | ||
if(userResponde.equals("bye")){ | ||
sayBye(); | ||
} | ||
else if(userResponde.equals("list")) { | ||
listTask(); | ||
} | ||
else if(userResponde.startsWith("done")) { | ||
markAsDone(userResponde); | ||
} | ||
else{ | ||
addNewTask(userResponde); | ||
} | ||
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. With reference to the coding standard, it is recommended that "else" is on the same line as "}" of the previous case. |
||
printLine(); | ||
System.out.println(); | ||
} | ||
|
||
public static void printLine(){ | ||
System.out.println("\t____________________________________________________________"); | ||
} | ||
|
||
public static void sayBye(){ | ||
System.out.println("\tBye. Hope to see you again soon!"); | ||
} | ||
|
||
public static void listTask(){ | ||
System.out.println("\tHere are the tasks in your list:"); | ||
for(int i = 0; i < taskCount; i++) { | ||
System.out.println("\t" + (i + 1) + "." + tasks[i]); | ||
} | ||
} | ||
|
||
public static void markAsDone(String userResponde){ | ||
int doneCount = Integer.parseInt(userResponde.substring(5)) - 1; | ||
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. The variable name for this seems to be slightly misleading as count is usually used to keep count, this is more of an index. Just an opinion though. |
||
tasks[doneCount].markAsDone(); | ||
System.out.println("\tNice! I've marked this task as done:"); | ||
System.out.println("\t [\u2713] " + tasks[doneCount].getDescription()); | ||
} | ||
|
||
public static void addNewTask(String userResponde){ | ||
if(userResponde.startsWith("todo")){ | ||
tasks[taskCount] = new Todo(userResponde.substring(5)); | ||
} | ||
else if(userResponde.startsWith("deadline")){ | ||
int dividerPosition = userResponde.indexOf(" /by"); | ||
String taskName = userResponde.substring(9,dividerPosition); | ||
String deadlineTime = userResponde.substring(dividerPosition + 5); | ||
tasks[taskCount] = new Deadline(taskName,deadlineTime); | ||
} | ||
else if(userResponde.startsWith("event")){ | ||
int dividerPosition = userResponde.indexOf(" /at"); | ||
String taskName = userResponde.substring(6,dividerPosition); | ||
String deadlineTime = userResponde.substring(dividerPosition + 5); | ||
tasks[taskCount] = new Event(taskName,deadlineTime); | ||
} | ||
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. With reference to the coding standard, it is recommended that "else" is on the same line as "}" of the previous case. |
||
System.out.println("\tGot it. I've added this task:"); | ||
System.out.println("\t " + tasks[taskCount]); | ||
System.out.println("\tNow you have " + (taskCount+1) + " tasks in the list"); | ||
taskCount++; | ||
} | ||
|
||
} | ||
|
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,29 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public Task(){ | ||
|
||
} | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols | ||
} | ||
|
||
public String getDescription(){ | ||
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. For consistency, it might be better to decide on having a space between "()" and "{" |
||
return description; | ||
} | ||
|
||
public void markAsDone(){ | ||
isDone = true; | ||
} | ||
|
||
public String toString(){ | ||
return "[" + getStatusIcon() + "] " + this.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.
For readability, it might be better to have a new line to separate main code and import lines.