Skip to content
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

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open

Conversation

kairoskoh
Copy link

No description provided.

Copy link

@lamkwjonathan lamkwjonathan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall quite nicely done. Just watch out for camelCase when naming methods.

String input;
Scanner in = new Scanner(System.in);
int counter = 0;
Task[] list = new Task[100];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps 'tasks' is a more appropriate name, since it is plural.

PrintGoodbyeMessage();
}

private static void ActiveChat() {

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.

}
}

private static void CheckIsEmptyList(Task[] list) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'checkIsEmptyList' for 'CheckIsEmptyList', or perhaps even just 'isEmptyList' for boolean naming.
Similar camelCase method naming issues in other places as well.

System.out.println("--------------------");
System.out.println("Got it. I've added this task: ");
System.out.println("[" + task.getLetter() + "] "
+ "[" + task.getStatusIcon() + "] "

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice use of wrapped lines!

this.description = description;
this.isDone = false;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it will be cleaner to override the .toString() method to return the entire [T][ ] task name string, instead of needing separate public getLetter() and getStatusIcon() methods.

public String toString() {
    String checkbox = isCompleted ? "[X]" : "[ ]";
    return checkbox + " " + taskName;
}

It is also possible to further override the function in the subclasses.
Example for Deadline subclass

@Override
public String toString() {
    String checkbox = isCompleted ? "[X]" : "[ ]";
    return "[D]" + super.toString() + " " + "(by: " + by + ")";
}

}

private static int ProcessTasks(String input, int counter, Task[] list) {
if (input.contains("todo")) {

Choose a reason for hiding this comment

The 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 static final String

return counter;
}

private static void PrintDoneMessage(Task[] list, int itemNum) {

Choose a reason for hiding this comment

The 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

private static void PrintDoneMessage(Task[] list, int itemNum) {
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() );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linked to the comment on overriding the .toString() method in Task. By doing so, this part of code can be simplified to

System.out.println( itemNum + "." + list[itemNum - 1])

Comment on lines 87 to 93
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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be cleaner to refactor this into a separate method.
One way is to have additional methods in the Duke class that handles the different Task subclasses.
Another is to create a separate class TaskManager that stores the array of Tasks and has functions to add the different Task subclasses to keep the main Duke class clean. (I think this will be the best approach)
Another is to overload the subclass constructors to take in String[] or a similar data structure.

Copy link

@ongweisheng ongweisheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally well done, do take note if comments are unnecessary do remove them and see if you can abstract more of your code

Comment on lines 9 to 17
// Welcome Message
printWelcomeMessage();

// Active Chat
activeChat();

// Goodbye Message
printGoodbyeMessage();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note if the comments are necessary, else remove them if they are not

Comment on lines 19 to 44
private static void activeChat() {
boolean isBye = false;
String input;
Scanner in = new Scanner(System.in);
int counter = 0;
Task[] list = new Task[100];

while(!isBye){
//store input
input = in.nextLine();
//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 {
try {
counter = processTasks(input, counter, list); //process tasks
} catch ( IllegalTaskException e ) {
System.out.println("Please include /by for deadline and /at for event");
}
}
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider implementing a Parser class to parse user inputs instead of putting everything in main/Duke

Comment on lines 46 to 111
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 {
processValidDone(input, list, donePos); //when input contains done and specified number
}
} else {
printDoneButEmptyMessage(); //when input contains done but list is empty
}
}

private static void processValidDone(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) throws IllegalTaskException{
if ( ( input.contains("deadline") || input.contains("event") ) && !input.contains("/")){
throw new IllegalTaskException();
}
if (input.contains("todo")) {
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);
if (!input.substring(donePos + 1, donePos + 3).equals("by")) {
throw new IllegalTaskException();
}
String date = input.substring(donePos + 4);
Deadline newTask = new Deadline(description,date);
list[counter] = newTask;
counter += 1;
printAddedTaskMessage(newTask, counter);
} else if (input.contains("event")) {
int donePos = input.indexOf("/"); //finds pos of '/'
String description = input.substring(6,donePos);
if (!input.substring(donePos + 1, donePos + 3).equals("by")) {
throw new IllegalTaskException();
}
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;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider creating TaskManger class to handle task manipulation as well as storing their data for your task list

Comment on lines 113 to 186
private static void printDoneMessage(Task[] list, int itemNum) {
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() );
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() + "] "
+ 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()
+ task.getDate() );
}

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("--------------------");
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider creating a UI class to handle your print statements instead

Comment on lines 1 to 26
package duke;

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 + ")";
}


}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider creating packages for your Event, Todo classes etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants