-
Notifications
You must be signed in to change notification settings - Fork 461
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
[Tan Hong Liang] iP #501
base: master
Are you sure you want to change the base?
[Tan Hong Liang] iP #501
Changes from 3 commits
0d13617
e176f21
ff600bd
04c50e0
cf80052
14fbfe9
5442e79
de18707
bd191ca
32a4edb
812a5f8
d42fd1f
cc19d6b
a3a39b8
7408a38
c1cb522
7718dc5
ba58ab6
c85360a
9e9dcd7
b248eee
1d8b29d
bde3039
174ec22
92b2745
76b923c
632ab49
fc92a48
fd15136
c49356d
53c523e
e2959fd
13377a1
f48f75f
1ff9775
41ea42d
0957668
7c80298
0d7c9c1
21f3c2f
52c8f42
4e05947
7963072
636d061
909bc1c
c59219f
7d75648
0356d41
3a7811c
fe7c2af
ebf81e5
b696e2a
02e1d24
63a9b27
a01d243
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 dateTime; | ||
|
||
public Deadline(String description, String dateTime) { | ||
super(description); | ||
this.dateTime = dateTime; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("[D]%s (by:%s)", super.toString(), this.dateTime); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,118 @@ | ||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
|
||
public class Duke { | ||
private static ArrayList<Task> tasks = new ArrayList<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. can consider making this a private static final variable |
||
private static boolean isEnd = false; | ||
|
||
private static final String UI_LINE_SPACING = "----------------------------------------\n"; | ||
|
||
private static final String COMMAND_LIST = "list"; | ||
private static final String COMMAND_BYE = "bye"; | ||
private static final String COMMAND_TODO = "todo"; | ||
private static final String COMMAND_DEADLINE = "deadline"; | ||
private static final String COMMAND_EVENT = "event"; | ||
private static final String COMMAND_MARK = "mark"; | ||
private static final String COMMAND_UNMARK = "unmark"; | ||
|
||
public static void main(String[] args) { | ||
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 love the design of code, but it would be great if the main "command execution" part could be extracted out to another class (which is required in Week 3 ip task [A-MoreOOP], so it might be easier if we change the code earlier) |
||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
String greeting = "Hello! I'm Duke \n" + "What can I do for you?\n"; | ||
Scanner userInput = new Scanner(System.in); | ||
chat(greeting); | ||
while (!isEnd) { | ||
String userStatement = userInput.nextLine(); | ||
String splitUserStatement[] = userStatement.split(" ", 2); | ||
String command = splitUserStatement[0]; | ||
String userArgs = ""; | ||
if (splitUserStatement.length > 1) { | ||
userArgs = splitUserStatement[1]; | ||
} | ||
/*String[] splitUserArgs = userArgs.split("/by", 2); | ||
String dateTime = ""; | ||
String description = splitUserArgs[0]; | ||
if (splitUserArgs.length > 1) { | ||
dateTime = splitUserArgs[1]; | ||
} */ | ||
switch(command) { | ||
case COMMAND_LIST: | ||
chat("Here are the tasks in your list: \n" + list()); | ||
break; | ||
case COMMAND_BYE: | ||
chat("Bye! Hope to see you again!\n"); | ||
isEnd = true; | ||
break; | ||
case COMMAND_TODO: | ||
ToDo toDoToAdd = new ToDo(userArgs); | ||
tasks.add(toDoToAdd); | ||
chat("Got it, I've added this task:\n " + toDoToAdd + "\n" + outputNumOfTasks()); | ||
break; | ||
case COMMAND_DEADLINE: | ||
String[] splitUserArgs = userArgs.split("/by", 2); | ||
String dateTime = ""; | ||
String description = splitUserArgs[0]; | ||
if (splitUserArgs.length > 1) { | ||
dateTime = splitUserArgs[1]; | ||
} | ||
Deadline deadlineToAdd = new Deadline(description, dateTime); | ||
tasks.add(deadlineToAdd); | ||
chat("Got it, I've added this task:\n " + deadlineToAdd + "\n" + outputNumOfTasks()); | ||
break; | ||
case COMMAND_EVENT: | ||
String[] splitUserArgs2 = userArgs.split("/at", 2); | ||
String dateTime2 = ""; | ||
String description2 = splitUserArgs2[0]; | ||
if (splitUserArgs2.length > 1) { | ||
dateTime2 = splitUserArgs2[1]; | ||
} | ||
Event eventToAdd = new Event(description2, dateTime2); | ||
tasks.add(eventToAdd); | ||
chat("Got it, I've added this task:\n " + eventToAdd + "\n" + outputNumOfTasks()); | ||
break; | ||
case COMMAND_MARK: | ||
mark(Integer.parseInt(userArgs)); | ||
break; | ||
case COMMAND_UNMARK: | ||
unmark(Integer.parseInt(userArgs)); | ||
break; | ||
default: | ||
chat("Not a command, just wanna chat?"); | ||
} | ||
} | ||
} | ||
|
||
public static String list() { | ||
String output = ""; | ||
int count = 1; | ||
for (Task task : tasks) { | ||
output += String.valueOf(count) + ". " + task + "\n"; | ||
count += 1; | ||
} | ||
return output; | ||
} | ||
|
||
public static void mark(int taskNum) { | ||
Task targetTask = tasks.get(taskNum-1); | ||
targetTask.mark(); | ||
System.out.println(UI_LINE_SPACING + "Nice! I've marked this task as done:\n" + targetTask + "\n" + UI_LINE_SPACING); | ||
|
||
} | ||
|
||
public static void unmark(int taskNum) { | ||
Task targetTask = tasks.get(taskNum-1); | ||
targetTask.unmark(); | ||
System.out.println(UI_LINE_SPACING + "OK, I've marked this task as not done yet:\n" + targetTask + "\n" + UI_LINE_SPACING); | ||
} | ||
|
||
public static String outputNumOfTasks() { | ||
return String.format("Now you have %d tasks in the list \n", tasks.size()); | ||
} | ||
|
||
public static void chat(String message) { | ||
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 great if JavaDoc could be added (but I highly understand that you might want to add comments once for all when the variables/func names are confirmed. |
||
System.out.println(UI_LINE_SPACING + message + UI_LINE_SPACING); | ||
} | ||
|
||
public static void end() { | ||
System.out.println(UI_LINE_SPACING + "Bye! Hope to see you again!" + UI_LINE_SPACING); | ||
isEnd = 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. Overall code is clear and the logic flows and should have no problem completing the IP |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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. I think you might need a white space before the curly brace according to the code standard. |
||
|
||
protected String duration; | ||
|
||
public Event(String description, String duration) { | ||
super(description); | ||
this.duration = duration; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("[E]%s (at:%s)", super.toString(), this.duration); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
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. Seems that there is an extra white space followed by "protected" according to coding standard. 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. Yes this violates the coding standard |
||
|
||
Task (String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
Task (String description, boolean isDone) { | ||
this.description = description; | ||
this.isDone = isDone; | ||
} | ||
|
||
public String getDescription() { | ||
return this.description; | ||
} | ||
|
||
public void mark() { | ||
this.isDone = true; | ||
} | ||
|
||
public void unmark() { | ||
this.isDone = false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
char mark; | ||
if (this.isDone) { | ||
mark = 'X'; | ||
} else { | ||
mark = ' '; | ||
} | ||
return ("[" + mark + "] " + this.getDescription()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
enum TaskType { | ||
TODO, | ||
DEADLINE, | ||
EVENT | ||
} |
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 String.format("[T]%s", 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.
Similar to Event class, I think you might need a white space before the curly brace according to the code standard.