-
Notifications
You must be signed in to change notification settings - Fork 77
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
[Yifan] ip #70
base: master
Are you sure you want to change the base?
[Yifan] ip #70
Conversation
src/main/java/Duke.java
Outdated
/** | ||
* | ||
*/ | ||
private static final int MAXLISTNUM = 100; |
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.
Constant names requires underscore to separate words.
src/main/java/Duke.java
Outdated
final String commandType = commandTypeAndParams[0]; | ||
final String commandArgs = commandTypeAndParams[1]; | ||
switch (commandType) { | ||
case "todo": |
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.
Consider using a constant string instead of magic string for the cases
src/main/java/Event.java
Outdated
return response; | ||
} | ||
|
||
protected String[] parseDescriptions(String commandArgs) { |
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.
Good that you followed the naming convention
src/main/java/Todo.java
Outdated
@@ -0,0 +1,11 @@ | |||
public class Todo extends Task{ |
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.
There seems to be a missing space before {
merge the branch 7
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.
Overall, good work. For the next iterations, you could consider how to improve the overall architecture of the code.
while (true) { | ||
String inputText = scanner.nextLine(); | ||
while (inputText.trim().isEmpty()) | ||
inputText = scanner.nextLine(); | ||
try { | ||
isProgramEnd = taskManager.handleTask(inputText); | ||
} catch (DukeException e) { | ||
e.handleError(); | ||
} | ||
if (isProgramEnd) { | ||
System.exit(0); | ||
} | ||
} |
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.
[Code Quality] The happy path in this section could be more fleshed out.
src/main/java/DukeException.java
Outdated
case "TaskTypeError": | ||
errorMessage = " OOPS!!! I'm sorry, but I don't know what that means :-("; | ||
break; | ||
case "TodoDescriptionError": | ||
errorMessage = " OOPS!!! The description of a todo cannot be empty."; | ||
break; | ||
case "EventDescriptionError": | ||
errorMessage = " OOPS!!! The description of a event is wrong."; | ||
break; | ||
case "DeadlineDescriptionError": | ||
errorMessage = " OOPS!!! The description of a deadline is wrong."; | ||
break; | ||
case "RestorationFileCorrupted": | ||
errorMessage = " OOPS!!! File Restoration Corrupted. Restoration Process Stopped."; | ||
break; | ||
default: | ||
errorMessage = " OOPS!!! Some unknown errors happen."; |
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.
Good SLAP!
src/main/java/Record.java
Outdated
try { | ||
boolean isFileCreated = file.createNewFile(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} else { | ||
try { | ||
readFileAndRestore(file); | ||
} catch (FileNotFoundException e) { | ||
e.printStackTrace(); | ||
} |
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.
[Code Quality] The try-catch
clauses can be combined to improve readability and control flow. Also, do keep in mind that you should remove printStackTrace()
in production-grade code. Figure out why?
src/main/java/Task.java
Outdated
protected boolean isDone; | ||
|
||
public Task(String commandArgs) { | ||
//descriptions = parseDescriptions(commandArgs); |
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.
[Code Quality] Please remove the unused comment.
src/main/java/TaskManager.java
Outdated
//private static final int MAX_LIST_NUM = 100; | ||
//private static Task[] taskList = new Task[MAX_LIST_NUM]; | ||
private static ArrayList<Task> taskList = new ArrayList<Task>(); | ||
//private static int listLength = 0; |
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.
[Code Quality] Again, please remove the unused comments to reduce clutter in the codebase.
src/main/java/TaskManager.java
Outdated
public class TaskManager { | ||
//private static final int MAX_LIST_NUM = 100; | ||
//private static Task[] taskList = new Task[MAX_LIST_NUM]; | ||
private static ArrayList<Task> taskList = new ArrayList<Task>(); |
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.
[Code Design] For future iterations, you can consider whether taskList
should be static
or not.
src/main/java/TaskManager.java
Outdated
case "todo": | ||
Todo todo = new Todo(commandArgs); | ||
taskList.add(todo); | ||
response = taskList.get(taskList.size()-1).getResponse(); | ||
Util.printTaskResponse(response, taskList.size()); | ||
updateRestorationFile(); | ||
break; | ||
case "deadline": | ||
Deadline deadline = new Deadline(commandArgs); | ||
taskList.add(deadline); | ||
response = taskList.get(taskList.size()-1).getResponse(); | ||
Util.printTaskResponse(response, taskList.size()); | ||
updateRestorationFile(); | ||
break; | ||
case "event": | ||
Event event = new Event(commandArgs); | ||
taskList.add(event); | ||
response = taskList.get(taskList.size()-1).getResponse(); | ||
Util.printTaskResponse(response, taskList.size()); | ||
updateRestorationFile(); | ||
break; | ||
case "list": | ||
showAllTasks(); | ||
break; | ||
case "delete": | ||
index = Integer.valueOf(commandArgs); | ||
response = taskList.get(index-1).getResponse(); | ||
taskList.remove(index-1); | ||
Util.printDeleteResponse(response, taskList.size()); | ||
updateRestorationFile(); | ||
break; | ||
case "mark": | ||
index = Integer.valueOf(commandArgs); | ||
taskList.get(index-1).setStringState(true); | ||
response = taskList.get(index-1).getResponse(); | ||
Util.printMarkResponse(response); | ||
updateRestorationFile(); | ||
break; | ||
case "unmark": | ||
index = Integer.valueOf(commandArgs); | ||
taskList.get(index-1).setStringState(false); | ||
response = taskList.get(index-1).getResponse(); | ||
Util.printUnmarkResponse(response); | ||
updateRestorationFile(); | ||
break; | ||
case "bye": | ||
Util.showExitMessage(); | ||
return true; |
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.
[Code Quality] Consider isolating/extracting the logic in each case for better SLAP. Another benefit of doing this is also to reduce the complexity of this entire method. Remember that functions should be small.
src/main/java/Util.java
Outdated
@@ -0,0 +1,61 @@ | |||
public class Util { |
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.
[Code Design] Good that you make a dedicated utility class. But I think the methods here are more suited to a separate UI class.
several new functions are added