[Timothy Chang] iP#82
Conversation
| @@ -0,0 +1,17 @@ | |||
| public class Deadline extends Task { | |||
| protected String ddate; | |||
There was a problem hiding this comment.
Maybe could use a more descriptive name for this? For example dueDate instead of just ddate.
| @@ -1,10 +1,104 @@ | |||
| import java.util.*; | |||
There was a problem hiding this comment.
Maybe you could import just the ArrayList instead of everything from the Java util library?
| @@ -0,0 +1,16 @@ | |||
| public class Event extends Task{ | |||
| protected String edate; | |||
There was a problem hiding this comment.
Same as previous comment, maybe could use more specific variable name?
| public class Task { | ||
|
|
||
| protected String description; | ||
| protected boolean isTaskDone; |
There was a problem hiding this comment.
I like the naming of this boolean variable, it is clear what it is representing.
| this.isTaskDone = isTaskDone; | ||
| } | ||
|
|
||
| public String getDescription(){ |
There was a problem hiding this comment.
I like how you follow the Java coding standards and stuck with K&R brackets, as well as writing your methods in camelCase
Nineves
left a comment
There was a problem hiding this comment.
Good job! Some details may be improved.
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
|
|
||
| ArrayList<Task> tasks = new ArrayList<Task>(); |
| System.out.println(tasks.get(index - 1).getDescription()); | ||
| } | ||
| } | ||
| else if(userInput.startsWith("todo")){ |
There was a problem hiding this comment.
Clean code, could think about refactoring the statements into functions to demonstrate SLAP.
| @@ -0,0 +1,17 @@ | |||
| public class Deadline extends Task { | |||
| protected String ddate; | |||
There was a problem hiding this comment.
I also think dueDate is a better variable name
xseh
left a comment
There was a problem hiding this comment.
Good attempt! Do take note of the Java coding standards and improve code readability with more SLAP.
| import java.util.*; | ||
| import java.lang.*; |
There was a problem hiding this comment.
According to the Java standard code,
Imported classes should always be listed explicitly.
| public static void main(String[] args) throws IndexOutOfBoundsException { | ||
|
|
||
| Scanner sc = new Scanner(System.in); | ||
| DukeException ex = new DukeException(); | ||
|
|
||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
|
|
||
| ArrayList<Task> tasks = new ArrayList<Task>(); | ||
|
|
||
| System.out.println("Hello from\n" + logo); | ||
| System.out.println("Hello! I'm Duke.Duke\n" + "What can I do for you?"); | ||
| displayOptions(); | ||
| String userInput; | ||
| do { | ||
| userInput = sc.nextLine(); | ||
| if(userInput.equals("list")){ | ||
| System.out.println("-------------------------------------------------------------------------\n" + "Here are the tasks in your list:"); | ||
|
|
||
| int i=1; | ||
| for(Task task: tasks){ | ||
| System.out.println(i + ": " + task.getDescription()); | ||
| i++; | ||
| } | ||
| i=0; | ||
| System.out.println("-------------------------------------------------------------------------"); | ||
| } | ||
| else if(userInput.equals("bye")){ | ||
| break; | ||
| } | ||
| else if(userInput.startsWith("mark")){ | ||
| String[] input = new String[10]; | ||
| input = userInput.split(" "); | ||
| int index = Integer.parseInt(input[1]); //index of task to be marked | ||
| if(tasks.get(index-1).getTaskStatus() == true){ | ||
| System.out.println("The task is already marked!"); | ||
| System.out.println("-------------------------------------------------------------------------"); | ||
| } | ||
| else{ | ||
| tasks.get(index-1).setMark(); | ||
| System.out.println("-------------------------------------------------------------------------\n" + "Nice! I've marked this task as done: "); | ||
| System.out.println(tasks.get(index-1).getDescription()); | ||
| } | ||
| } | ||
| else if(userInput.startsWith("unmark")){ | ||
| String[] input = new String[10]; | ||
| input = userInput.split(" "); | ||
| int index = Integer.parseInt(input[1]); //index of task to be unmarked | ||
| if(tasks.get(index-1).getTaskStatus()==false){ | ||
| System.out.println("The task is not completed yet!"); | ||
| System.out.println("-------------------------------------------------------------------------"); | ||
| } | ||
| else { | ||
| tasks.get(index - 1).setUnmark(); | ||
| System.out.println("-------------------------------------------------------------------------\n" + "OK, I've marked this task as not done yet:"); | ||
| System.out.println(tasks.get(index - 1).getDescription()); | ||
| } | ||
| } | ||
| else if(userInput.startsWith("todo")){ | ||
| try{ | ||
| String newtodo = userInput.split("todo")[1].trim(); | ||
| Todo newTodo = new Todo(newtodo); | ||
| tasks.add(newTodo); | ||
| System.out.println("-------------------------------------------------------------------------"); | ||
| System.out.println("Got it! I've added this task: " + newTodo.getDescription()); | ||
| System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
| } catch(IndexOutOfBoundsException e){ | ||
| ex.missingDescription("todo"); | ||
| } finally{ | ||
| System.out.println("What else should I do for you?"); | ||
| } | ||
| } | ||
| else if(userInput.startsWith("deadline")){ | ||
| try{ | ||
| String[] input = userInput.split("/by"); | ||
| String ddate = input[1].trim(); | ||
| String deadline = input[0].split("deadline")[1].trim(); | ||
| Deadline newDeadline = new Deadline(deadline, ddate); | ||
| tasks.add(newDeadline); | ||
| System.out.println("-------------------------------------------------------------------------"); | ||
| System.out.println("Got it! I've added this task: "); | ||
| System.out.println(newDeadline.getDescription()); | ||
| System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
| } catch(IndexOutOfBoundsException e){ | ||
| ex.missingDescription("deadline"); | ||
| } finally{ | ||
| System.out.println("What else should I do for you?"); | ||
| } | ||
| } | ||
| else if(userInput.startsWith("event")){ | ||
| try{ | ||
| String[] input = userInput.split("/at"); | ||
| String eventDate = input[1].trim(); | ||
| String event = input[0].split("event")[1].trim(); | ||
| Event newEvent = new Event(event, eventDate); | ||
| tasks.add(newEvent); | ||
| System.out.println("-------------------------------------------------------------------------"); | ||
| System.out.println("Got it! I've added this task: "); | ||
| System.out.println(newEvent.getDescription()); | ||
| System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
| } catch(IndexOutOfBoundsException e){ | ||
| ex.missingDescription("event"); | ||
| } finally{ | ||
| System.out.println("What else should I do for you?"); | ||
| } | ||
| } | ||
| else{ | ||
| Task newTask = new Task(userInput); | ||
| tasks.add(newTask); | ||
| System.out.println("added: "+ userInput); | ||
| } | ||
| }while(!userInput.equals("bye")); | ||
|
|
||
| System.out.println("Bye. Hope to see you again soon!"); | ||
| } |
There was a problem hiding this comment.
Avoid long methods (> 30 LoCs). Consider refactoring and SLAP to improve code readability.
| do { | ||
| userInput = sc.nextLine(); | ||
| if(userInput.equals("list")){ | ||
| System.out.println("-------------------------------------------------------------------------\n" + "Here are the tasks in your list:"); |
There was a problem hiding this comment.
Avoid magic literals. Consider putting the constants into variables. For example, "-------------------------------------------------------------------------\n" can be declared as MESSAGE_BORDER.
| System.out.println(i + ": " + task.getDescription()); | ||
| i++; | ||
| } | ||
| i=0; |
There was a problem hiding this comment.
Avoid magic numbers. If the value is an iterator, consider putting into a for loop instead.
| } | ||
| else if(userInput.equals("bye")){ |
There was a problem hiding this comment.
According to the Java coding standard, the if-else statements should resemble:
if (condition) {
statements;
} else if (condition) {
statements;
} else {
statements;
}
| String[] input = new String[10]; | ||
| input = userInput.split(" "); | ||
| int index = Integer.parseInt(input[1]); //index of task to be marked | ||
| if(tasks.get(index-1).getTaskStatus() == true){ |
There was a problem hiding this comment.
Avoid complicated expressions. Consider refactoring the expressions into different methods.
| else if(userInput.startsWith("mark")){ | ||
| String[] input = new String[10]; | ||
| input = userInput.split(" "); | ||
| int index = Integer.parseInt(input[1]); //index of task to be marked |
There was a problem hiding this comment.
Avoid magic numbers. Instead of a comment, consider declaring a variable for the integers (e.g. INDEX_MARK_TASK)
| } | ||
| else { | ||
| tasks.get(index - 1).setUnmark(); | ||
| System.out.println("-------------------------------------------------------------------------\n" + "OK, I've marked this task as not done yet:"); |
There was a problem hiding this comment.
According to the Java coding standard,
Line length should be no longer than 120 chars.
If the line exceeds the limit, use line wrapping at appropriate places of the line.
| String[] input = userInput.split("/by"); | ||
| String ddate = input[1].trim(); | ||
| String deadline = input[0].split("deadline")[1].trim(); | ||
| Deadline newDeadline = new Deadline(deadline, ddate); | ||
| tasks.add(newDeadline); | ||
| System.out.println("-------------------------------------------------------------------------"); | ||
| System.out.println("Got it! I've added this task: "); | ||
| System.out.println(newDeadline.getDescription()); | ||
| System.out.println("Now you have " + tasks.size() + " tasks in the list."); |
There was a problem hiding this comment.
Consider further SLAP to improve code readability.
| package duke; | ||
|
|
||
| public class DukeException extends Exception { | ||
| public void missingDescription(String command){ |
There was a problem hiding this comment.
According to the Java coding standard, there should be a whitespace between the brackets ){.
No description provided.