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

[Yuki Akizuki] iP #172

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

Conversation

yuki-cell
Copy link

No description provided.

Copy link

@YangJiyu98 YangJiyu98 left a comment

Choose a reason for hiding this comment

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

Very neat code! very easy to read

@@ -0,0 +1,32 @@
package duke;

Choose a reason for hiding this comment

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

Maybe can consider having a empty new line to group your package/import statements

Choose a reason for hiding this comment

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

I agree

Choose a reason for hiding this comment

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

I second the suggestion made by @YangJiyu98


} else {
// invalid input
if (!loading){

Choose a reason for hiding this comment

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

You might have missed a whitespace here

Choose a reason for hiding this comment

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

I agree

Choose a reason for hiding this comment

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

I second that

ui.showError(e.getMessage());
}

} else if (instructionType.equals("event")){

Choose a reason for hiding this comment

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

You might have missed a white space here

Choose a reason for hiding this comment

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

I agree

Choose a reason for hiding this comment

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

I second that

Comment on lines 57 to 59
/**
* run todo app
*/

Choose a reason for hiding this comment

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

Not sure if this would be necessary as it is simple enough fro a reader to understand

Copy link

@yeohhq yeohhq left a comment

Choose a reason for hiding this comment

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

I think your code is generally easy to read and follow, with inline comments to also improve readability which is good! :)

@@ -1,6 +1,7 @@
package duke;
Copy link

Choose a reason for hiding this comment

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

Maybe you can have a new empty line indentation after your package line before your import statements?

Choose a reason for hiding this comment

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

I agree

Choose a reason for hiding this comment

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

Repeated suggestion. I second this as well.

@@ -47,4 +47,14 @@ public Task getTask(int index) {
Task task = taskList.get(index);
return task;
}

public ArrayList<Task> find(String keyword) {
Copy link

Choose a reason for hiding this comment

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

I like how you return your output as an ArrayList to be processed later instead of immediately returning a processed string since this could improve adaptability and extensibility of your program! 👍

Choose a reason for hiding this comment

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

I agree


public void showFoundTask(ArrayList<Task> foundTasks) {
System.out.println("Here are the matching tasks in your list:");
int index = 1;
Copy link

Choose a reason for hiding this comment

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

Perhaps it would be more readable if you had the for-loop in the form of:
for (int i = 1; i < foundTasks.size() + 1; i++) ?

Choose a reason for hiding this comment

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

I think that the current way is fine and I actually like it more

@@ -1,6 +1,7 @@
package duke;

Choose a reason for hiding this comment

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

I agree

@@ -0,0 +1,32 @@
package duke;

Choose a reason for hiding this comment

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

I agree

ui.showError(e.getMessage());
}

} else if (instructionType.equals("event")){

Choose a reason for hiding this comment

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

I agree


} else {
// invalid input
if (!loading){

Choose a reason for hiding this comment

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

I agree


public void showFoundTask(ArrayList<Task> foundTasks) {
System.out.println("Here are the matching tasks in your list:");
int index = 1;

Choose a reason for hiding this comment

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

I think that the current way is fine and I actually like it more

Comment on lines 24 to 25
tasks = new TaskList();
tasks = new TaskList(storage.load(this));

Choose a reason for hiding this comment

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

Perhaps there is a way of changing your code design so that you can initialise with just one line of code instead of calling the constructor twice?

while (!isExit) {
try {
String fullCommand = ui.readCommand();
ui.showLine(); // show the divider line ("_______")

Choose a reason for hiding this comment

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

Perhaps you can put your comment on top of the line of code instead of beside it?
Not really sure if this violates Java coding standard.

Comment on lines 69 to 172
// quit
ui.showGoodBye();
System.exit(0);

} else if (instructionType.equals("list")) {
// list task
ui.showListOfTask(tasks.taskList);

} else if (instructionType.equals("done")) {
// mark done
// parse instruction
int index = Parser.parseMarkDoneInstr(user_input);
// execute
Task chosenTask = tasks.getTask(index);
chosenTask.markAsDone();
if (!loading){
ui.showMarkedDoneTask(chosenTask);
}

} else if (instructionType.equals("delete")) {
// delete task
// parse instruction
int index = Parser.parseDeleteInstr(user_input);
// execute
Task chosenTask = tasks.getTask(index);
tasks.deleteTask(index);
if (!loading){
ui.showDeletedTask(chosenTask, tasks.taskList);
}

} else if (instructionType.equals("find")) {
// find task
// parse instruction
String keyword = Parser.parseFindInstr(user_input);
// execute
ArrayList<Task> foundTasks = tasks.find(keyword);
if (!loading){
ui.showFoundTask(foundTasks);
}

} else if (instructionType.equals("todo")) {
// make todo
try {
// parse instruction
String description = Parser.parseAddTodoInstr(user_input);
// execute
Task todo = new Todo(description);
tasks.addTask(todo);
if (!loading){
ui.showAddedTask(todo, tasks.taskList);
}
} catch (DukeException e) {
ui.showError(e.getMessage());
}

} else if (instructionType.equals("deadline")) {
// make deadline
try {
// parse instruction
HashMap<String, Object> parsedData = Parser.parseAddDeadlineInstr(user_input);
String description = (String) parsedData.get("description");
LocalDate l_time = (LocalDate) parsedData.get("time");
// execute
Task deadline = new Deadline(description, l_time);
tasks.addTask(deadline);
if (!loading) {
ui.showAddedTask(deadline, tasks.taskList);
}
} catch (DukeException e) {
ui.showError(e.getMessage());
}

} else if (instructionType.equals("event")){
// make event
try {
// parse instruction
HashMap<String, Object> parsedData = Parser.parseAddEventInstr(user_input);
String description = (String) parsedData.get("description");
LocalDate l_time = (LocalDate) parsedData.get("time");
// execute
Task event = new Event(description, l_time);
tasks.addTask(event);
if (!loading){
ui.showAddedTask(event, tasks.taskList);
}
} catch (DukeException e) {
ui.showError(e.getMessage());
}

} else {
// invalid input
if (!loading){
throw new DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
}
}

// save Data for every user input
Storage.save(tasks.taskList);
}
}

Choose a reason for hiding this comment

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

Should this be extracted out? Any reasons why you chose to have the input processing method in Duke.java instead of a separate class?

*/
public class Task {
protected String description;
protected boolean isDone;

Choose a reason for hiding this comment

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

I like how you named this member. It is very clear that its going to be a boolean!

@@ -47,4 +47,14 @@ public Task getTask(int index) {
Task task = taskList.get(index);
return task;
}

public ArrayList<Task> find(String keyword) {

Choose a reason for hiding this comment

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

I agree

Copy link

@yongping827 yongping827 left a comment

Choose a reason for hiding this comment

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

I would suggest to gitignore build files, i.e. in this context, the directories iP/.idea and iP/out. The reason behind this is any changes to the code would change the files in these directories, and would create too many unnecessary changes in the git history.

@@ -0,0 +1,32 @@
package duke;

Choose a reason for hiding this comment

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

I second the suggestion made by @YangJiyu98

protected LocalDate deadline;

/**
* constructor of Deadline

Choose a reason for hiding this comment

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

Perhaps capitalize the beginning of JavaDoc comments? This applies to all other JavaDoc comments as well.

@@ -1,6 +1,7 @@
package duke;

Choose a reason for hiding this comment

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

Repeated suggestion. I second this as well.

import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;

Choose a reason for hiding this comment

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

Perhaps group imports based on the packages and leave an empty line between groups?

Command c = Parser.parse(fullCommand);
c.execute(tasks, ui, storage);
isExit = c.isExit();
*/

Choose a reason for hiding this comment

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

Not part of the Java coding standard, but perhaps remove commented code that I would presume is unwanted?

ui.showError(e.getMessage());
}

} else if (instructionType.equals("event")){

Choose a reason for hiding this comment

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

I second that


} else {
// invalid input
if (!loading){

Choose a reason for hiding this comment

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

I second that

Comment on lines 20 to 23
ui = new Ui();
storage = new Storage(filePath);
try {
// need empty tasks to load properly

Choose a reason for hiding this comment

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

From the java coding standards: "Logical units within a block should be separated by one blank line."
Consider leaving a line before the try block?

// parse instruction
HashMap<String, Object> parsedData = Parser.parseAddEventInstr(user_input);
String description = (String) parsedData.get("description");
LocalDate l_time = (LocalDate) parsedData.get("time");

Choose a reason for hiding this comment

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

Variable name could be more descriptive.

Comment on lines 59 to 76
static HashMap<String, Object> parseAddDeadlineInstr(String user_input) throws DukeException {
// check if input is valid
if (user_input.split(" ", 2).length == 1) {
throw new DukeException("☹ OOPS!!! The description of a deadline cannot be empty.");
}
String task = user_input.split(" ", 2)[1];
if (task.split(" /by ", 2).length < 2) {
throw new DukeException("☹ OOPS!!! The description and time is required for deadline");
}
// get data
String description = task.split(" /by ", 2)[0];
String time = task.split(" /by ")[1];
LocalDate l_time = LocalDate.parse(time);
HashMap<String, Object> parsedData = new HashMap<String, Object>(){
{ put("description", description); put("time", l_time); }
};
return parsedData;
}

Choose a reason for hiding this comment

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

This block is generally abit chaotic, perhaps add in line breaks to separate different logical units?

}

/**
* show welcome message when app is started

Choose a reason for hiding this comment

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

Javadocs:

  • "show" should be "Shows"
  • add a full stop after the function description

before: root = CS2103 > iP(redundant folder) > folders
after: root = CS2103 > folders
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.

None yet

6 participants