-
Notifications
You must be signed in to change notification settings - Fork 462
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 1 commit
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 |
---|---|---|
|
@@ -2,79 +2,50 @@ | |
import java.util.ArrayList; | ||
|
||
public class Duke { | ||
|
||
private static class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
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()); | ||
} | ||
} | ||
private static ArrayList<Task> tasks = new ArrayList<Task>(); | ||
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_MARK = "mark"; | ||
private static final String COMMAND_UNMARK = "unmark"; | ||
|
||
|
||
public static void main(String[] args) { //runs chatbot UI | ||
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 greeting = "Hello! I'm Duke \n" + "What can I do for you?\n"; | ||
Scanner userInput = new Scanner(System.in); | ||
System.out.println(UI_LINE_SPACING + greeting + UI_LINE_SPACING); | ||
while (!isEnd) { | ||
String command = userInput.nextLine(); | ||
|
||
String userStatement = userInput.nextLine(); | ||
String splitUserStatement[] = userStatement.split(" ", 2); | ||
String command = splitUserStatement[0]; | ||
String userArgs = ""; | ||
if (splitUserStatement.length > 1) { | ||
userArgs = splitUserStatement[1]; | ||
} | ||
switch(command) { | ||
case COMMAND_LIST: | ||
System.out.println(UI_LINE_SPACING + list() + UI_LINE_SPACING); | ||
System.out.println(chat("Here are the tasks in your list: /n" + list())); | ||
break; | ||
case COMMAND_BYE: | ||
System.out.println("Bye! Hope to see you again!"); | ||
System.out.println(chat("Bye! Hope to see you again!")); | ||
isEnd = true; | ||
break; | ||
case COMMAND_TODO: | ||
ToDo taskToAdd = new ToDo(command); | ||
tasks.add(taskToAdd); | ||
System.out.println(chat("Got it, I've added this task:\n " + taskToAdd + "\n" + outputNumOfTasks())); | ||
break; | ||
case COMMAND_MARK: | ||
mark(Integer.parseInt(userArgs)); | ||
break; | ||
case COMMAND_UNMARK: | ||
unmark(Integer.parseInt(userArgs)); | ||
break; | ||
default: | ||
if (command.contains("mark")) { | ||
int taskNum = Integer.parseInt(command.substring(command.length() - 1)); | ||
if (command.contains("unmark")) { | ||
unmark(taskNum); | ||
} else { | ||
mark(taskNum); | ||
} | ||
} else { | ||
tasks.add(new Task(command)); | ||
System.out.println(UI_LINE_SPACING + "Added: " + command + "\n" + UI_LINE_SPACING); | ||
} | ||
System.out.println(chat("Not a command, just wanna chat?")); | ||
} | ||
} | ||
} | ||
|
@@ -102,6 +73,14 @@ public static void unmark(int taskNum) { | |
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 String chat(String message) { | ||
return 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,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 "[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.
can consider making this a private static final variable