-
Notifications
You must be signed in to change notification settings - Fork 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
[Kairos Koh] iP #189
base: master
Are you sure you want to change the base?
[Kairos Koh] iP #189
Changes from 9 commits
98e53ab
e0d5c4d
ca6b0fe
13d9a37
9dcbc95
c3d9af5
72f7593
1e289bf
7b50777
af71eb3
6c57ecf
e8d8f41
11315c6
7c26728
3cf54db
15d6adf
57d09ac
eac25f9
c41f3af
b8098ba
dfb01a0
972d782
663b585
e41e1f4
bc60895
b2b063c
253abe3
4780c7e
411c77a
493ebcc
7db017f
2ac4093
0da697a
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,23 @@ | ||
public class Deadline extends Task{ | ||
|
||
protected final static char LETTER = 'D'; | ||
protected String date; | ||
|
||
public Deadline(String description, String date) { | ||
super(description); | ||
this.date = date; | ||
} | ||
|
||
public String toString() { | ||
return description; | ||
} | ||
|
||
public char getLetter() { | ||
return LETTER; | ||
} | ||
|
||
public String getDate() { | ||
return "(by: " + date + ")"; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,181 @@ | ||
|
||
import java.util.Scanner; | ||
|
||
public class Duke { | ||
|
||
public static void main(String[] args) { | ||
|
||
// Welcome Message | ||
PrintWelcomeMessage(); | ||
|
||
// Active Chat | ||
ActiveChat(); | ||
|
||
// Goodbye Message | ||
PrintGoodbyeMessage(); | ||
} | ||
|
||
private static void ActiveChat() { | ||
boolean isBye = false; | ||
boolean isEmptyList = true; | ||
String input; | ||
Scanner in = new Scanner(System.in); | ||
int counter = 0; | ||
Task[] list = 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. Perhaps 'tasks' is a more appropriate name, since it is plural. |
||
|
||
while(!isBye){ | ||
//store input | ||
input = in.nextLine(); | ||
//check if input is empty | ||
CheckIsEmptyList(list); | ||
//process input | ||
if (input.equals("bye")){ //check if bye | ||
isBye = true; | ||
} else if (input.equals("list")) { //check if list | ||
ProcessList(counter, list); | ||
} else if (input.contains("done") ) { //check if done | ||
ProcessDone(input, list); | ||
} else { | ||
counter = ProcessTasks(input, counter, list); //process tasks | ||
} | ||
} | ||
} | ||
|
||
private static void CheckIsEmptyList(Task[] 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. 'checkIsEmptyList' for 'CheckIsEmptyList', or perhaps even just 'isEmptyList' for boolean naming. |
||
boolean isEmptyList; | ||
if(list[0] != null) { | ||
isEmptyList = false; | ||
} | ||
} | ||
|
||
private static void ProcessList(int counter, Task[] list) { | ||
if (list[0] != null){ | ||
PrintListMessage(counter, list); | ||
} else { | ||
PrintListButEmptyMessage(); | ||
} | ||
} | ||
|
||
private static void ProcessDone(String input, Task[] list) { | ||
int donePos = input.indexOf("done"); | ||
if (list[0] != null) { | ||
if (input.length() < donePos + 5) { | ||
PrintDoneButNotSpecificMessage(); //when input contains done but no number | ||
} else { | ||
ProcessDone(input, list, donePos); //when input contains done and specified number | ||
} | ||
} else { | ||
PrintDoneButEmptyMessage(); //when input contains done but list is empty | ||
} | ||
} | ||
|
||
private static void ProcessDone(String input, Task[] list, int donePos) { | ||
String itemNumDone = input.substring(donePos + 5, donePos + 6); | ||
int itemNum = Integer.parseInt(itemNumDone); | ||
list[itemNum - 1].setDone(); | ||
PrintDoneMessage(list, itemNum); | ||
} | ||
|
||
private static int ProcessTasks(String input, int counter, Task[] list) { | ||
if (input.contains("todo")) { | ||
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 might be cleaner to replace the strings "todo", "deadline", etc. with named constants of type |
||
String description = input.substring(5); | ||
ToDo newTask = new ToDo(description); | ||
list[counter] = newTask; | ||
counter += 1; | ||
PrintAddedTaskMessage(newTask, counter); | ||
} else if (input.contains("deadline")) { | ||
int donePos = input.indexOf("/"); //finds pos of '/' | ||
String description = input.substring(9,donePos); | ||
String date = input.substring(donePos + 4); | ||
Deadline newTask = new Deadline(description,date); | ||
list[counter] = newTask; | ||
counter += 1; | ||
PrintAddedTaskMessage(newTask, counter); | ||
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 might be cleaner to refactor this into a separate method. |
||
} else if (input.contains("event")) { | ||
int donePos = input.indexOf("/"); //finds pos of '/' | ||
String description = input.substring(6,donePos); | ||
String date = input.substring(donePos + 4); | ||
Event newTask = new Event(description,date); | ||
list[counter] = newTask; | ||
counter += 1; | ||
PrintAddedTaskMessage(newTask, counter); | ||
} else { | ||
System.out.println("Please specify tasks: todo, deadline or event"); | ||
System.out.println("Example - type in the following: todo read book"); | ||
} | ||
return counter; | ||
} | ||
|
||
private static void PrintDoneMessage(Task[] list, int itemNum) { | ||
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. Nice use of specific PrintMessage methods to keep the overall code cleaner and easier to understand |
||
System.out.println("--------------------"); | ||
System.out.println("Nice! I've marked this task as done:"); | ||
System.out.println( itemNum + ".[" + list[itemNum - 1].getStatusIcon() + "] " + list[itemNum - 1].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. Linked to the comment on overriding the
|
||
System.out.println("--------------------"); | ||
} | ||
|
||
private static void PrintListMessage(int counter, Task[] list) { | ||
System.out.println("--------------------"); | ||
System.out.println("Here are the tasks in your list:"); | ||
for(int i = 0; i < counter; i += 1){ | ||
PrintListOfTaskSubMessage(list[i], i); | ||
} | ||
System.out.println("--------------------"); | ||
} | ||
|
||
private static void PrintListButEmptyMessage() { | ||
System.out.println("--------------------"); | ||
System.out.println("List is empty. Time to get productive!"); | ||
System.out.println("--------------------"); | ||
} | ||
|
||
private static void PrintDoneButNotSpecificMessage() { | ||
System.out.println("Please specify which task is done."); | ||
} | ||
|
||
private static void PrintDoneButEmptyMessage() { | ||
System.out.println("--------------------"); | ||
System.out.println("Unable to tick off list."); | ||
System.out.println("List is empty. Time to get productive!"); | ||
System.out.println("--------------------"); | ||
} | ||
|
||
private static void PrintAddedTaskMessage(Task task, int i) { | ||
System.out.println("--------------------"); | ||
System.out.println("Got it. I've added this task: "); | ||
System.out.println("[" + task.getLetter() + "] " | ||
+ "[" + task.getStatusIcon() + "] " | ||
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. nice use of wrapped lines! |
||
+ task.getDescription() | ||
+ task.getDate() ); | ||
System.out.println("Now you have " + i + " tasks in the list."); | ||
System.out.println("--------------------"); | ||
} | ||
|
||
private static void PrintListOfTaskSubMessage(Task task, int i) { | ||
System.out.println(i + 1 | ||
+ ".[" + task.getLetter() + "] " | ||
+ "[" + task.getStatusIcon() + "] " | ||
+ task.getDescription() ); | ||
} | ||
|
||
private static void PrintGoodbyeMessage() { | ||
System.out.println("--------------------"); | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
System.out.println(""); | ||
System.out.println("--------------------"); | ||
} | ||
|
||
private static void PrintWelcomeMessage() { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
|
||
System.out.println("--------------------"); | ||
System.out.println("Hello! I'm Duke"); | ||
System.out.println("What can I do for you?"); | ||
System.out.println(""); | ||
System.out.println("--------------------"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
public class Event extends Task{ | ||
|
||
protected final static char LETTER = 'E'; | ||
protected String date; | ||
|
||
public Event(String description, String date) { | ||
super(description); | ||
this.date = date; | ||
} | ||
|
||
public String toString() { | ||
return description; | ||
} | ||
|
||
public char getLetter() { | ||
return LETTER; | ||
} | ||
|
||
public String getDate() { | ||
return "(at: " + date + ")"; | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; | ||
|
||
public Task(){ | ||
this.description = ""; | ||
isDone = false; | ||
} | ||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
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. Perhaps it will be cleaner to override the
It is also possible to further override the function in the subclasses.
|
||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); // mark done task with X | ||
} | ||
|
||
public String getDescription(){ | ||
return this.description; | ||
} | ||
|
||
public void setDone(){ | ||
this.isDone = true; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
public char getLetter() { | ||
return ' '; | ||
} | ||
|
||
public String getDate() { | ||
return " "; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
public class ToDo extends Task{ | ||
|
||
protected final static char LETTER = 'T'; | ||
|
||
public ToDo(String description) { | ||
super(description); | ||
} | ||
|
||
public String toString() { | ||
return description; | ||
} | ||
|
||
public char getLetter() { | ||
return LETTER; | ||
} | ||
|
||
public String getDate() { | ||
return ""; | ||
} | ||
|
||
} |
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.
I think 'ActiveChat' should be 'activeChat' instead, since methods should be in camelCase.