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

[Yifan] ip #70

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

[Yifan] ip #70

wants to merge 29 commits into from

Conversation

AmethystQ
Copy link

several new functions are added

@AmethystQ AmethystQ changed the title Add several new functions [Yifan] ip Aug 31, 2022
/**
*
*/
private static final int MAXLISTNUM = 100;

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.

final String commandType = commandTypeAndParams[0];
final String commandArgs = commandTypeAndParams[1];
switch (commandType) {
case "todo":

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

return response;
}

protected String[] parseDescriptions(String commandArgs) {

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

@@ -0,0 +1,11 @@
public class Todo extends Task{

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 {

Copy link

@richwill28 richwill28 left a 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.

Comment on lines +16 to +28
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);
}
}

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.

Comment on lines 12 to 28
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.";

Choose a reason for hiding this comment

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

Good SLAP!

Comment on lines 21 to 31
try {
boolean isFileCreated = file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
} else {
try {
readFileAndRestore(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}

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?

protected boolean isDone;

public Task(String commandArgs) {
//descriptions = parseDescriptions(commandArgs);

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.

Comment on lines 5 to 8
//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;

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.

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

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.

Comment on lines 17 to 64
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;

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.

@@ -0,0 +1,61 @@
public class Util {

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.

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.

3 participants