Skip to content

[TJ-Hoo] iP#190

Open
TJ-Hoo wants to merge 33 commits into
nus-cs2113-AY2223S2:masterfrom
TJ-Hoo:master
Open

[TJ-Hoo] iP#190
TJ-Hoo wants to merge 33 commits into
nus-cs2113-AY2223S2:masterfrom
TJ-Hoo:master

Conversation

@TJ-Hoo

@TJ-Hoo TJ-Hoo commented Jan 31, 2023

Copy link
Copy Markdown

No description provided.

@Stella1585 Stella1585 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good, you followed the coding standards quite well. Overall, you can try to find more suitable variable names that helps to get your intention across. Also the nesting is quite deep for the mark/unmark section. Lastly you can try extracting methods from main as it is quite long.

Comment thread src/main/java/Duke.java Outdated
System.out.print(i+1+".");
System.out.println(taskList.get(i).markTask()+taskList.get(i).name);
}
} else if(userInput.contains("unmark") || userInput.contains("mark")){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

(not coding standard related but) Since you are using contains and not equals, do you think contains(unmark) is necessary?

Comment thread src/main/java/Duke.java Outdated
}
} else if(userInput.contains("unmark") || userInput.contains("mark")){
Integer itemNumber = new Integer(0);
String [] IndexArr = userInput.split(" ",2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this is a variable so camel case should be used, also maybe a better variable name can be used as this array contains both the command and the index.

Comment thread src/main/java/Duke.java Outdated
boolean isFinished = false;
List toDoList = new List();
Scanner in = new Scanner(System.in);
ArrayList<Task> taskList = new ArrayList<Task>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

plural form should be used for collection of objects, so perhaps using names such as tasks would be better

Comment thread src/main/java/Duke.java Outdated
if(userInput.equals("list")){
for(int i = 0; i<taskList.size(); i++){
System.out.print(i+1+".");
System.out.println(taskList.get(i).markTask()+taskList.get(i).name);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

for your function .get, perhaps be clearer about what you are getting, such using as getStatus or getName.

Comment thread src/main/java/Duke.java Outdated
if(userInput.equals("bye")){
break;
}
if(userInput.equals("list")){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

any reason why you did not continue with else if?

Comment thread src/main/java/Duke.java Outdated
Comment on lines +13 to +81
if(userInput.equals("bye")){
break;
}
if(userInput.equals("list")) {
for (int i = 0; i < taskList.size(); i++) {
System.out.print(i + 1 + ".");
System.out.println(taskList.get(i).toString());
}
} else if (userInput.contains("todo")) {
String info = userInput.substring(5).trim();
taskList.add(new Todo(info));
int finalTask = taskList.size() - 1;
System.out.println("Got it. I've added this task:");
System.out.println(taskList.get(finalTask).toString());
if (taskList.size() == 1){
System.out.println("Now you have " +taskList.size()+" task in the list.");
} else {
System.out.println("Now you have " + taskList.size() + " tasks in the list.");
}
} else if (userInput.contains("deadline")) {
String [] listArray = userInput.split("/",2);
String description = listArray[0];
String dueDate = listArray[1];
String info = description.substring(8).trim();
String due = dueDate.substring(3).trim();
taskList.add(new Deadline(info, due));
int finalTask = taskList.size() - 1;
System.out.println("Got it. I've added this task:");
System.out.println(taskList.get(finalTask).toString());
if (taskList.size() == 1){
System.out.println("Now you have " +taskList.size()+" task in the list.");
} else {
System.out.println("Now you have " + taskList.size() + " tasks in the list.");
}
} else if (userInput.contains("event")) {
String [] listArray = userInput.split("/",3);
String description = listArray[0];
String startTime = listArray[1];
String endTime = listArray[2];
String info = description.substring(6).trim();
String start = startTime.substring(5).trim();
String end = endTime.substring(3).trim();
taskList.add(new Event(info, start, end));
int finalTask = taskList.size() - 1;
System.out.println("Got it. I've added this task:");
System.out.println(taskList.get(finalTask).toString());
if (taskList.size() == 1){
System.out.println("Now you have " +taskList.size()+" task in the list.");
} else {
System.out.println("Now you have " + taskList.size() + " tasks in the list.");
}
} else if(userInput.contains("unmark") || userInput.contains("mark")){
Integer itemNumber;
String [] IndexArr = userInput.split(" ",2);
itemNumber = Integer.parseInt(IndexArr[1])-1;
if (userInput.contains("unmark")) {
System.out.println("OK, I've marked this task as not done yet:");
taskList.get((int) itemNumber).isCompleted = false;
System.out.println(taskList.get(itemNumber).toString());
}
else {
System.out.println("Nice! I've marked this task as done:");
taskList.get(itemNumber).isCompleted = true;
System.out.println(taskList.get(itemNumber).toString());
}
} else {
taskList.add(new Task(userInput,false));
System.out.println("added: "+userInput);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like how you avoided deep-nesting

Comment thread src/main/java/Duke.java Outdated
int finalTask = taskList.size() - 1;
System.out.println("Got it. I've added this task:");
System.out.println(taskList.get(finalTask).toString());
if (taskList.size() == 1){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps you can leave a space between your round bracket and curly bracket, so that your formatting looks consistent

Comment thread src/main/java/Duke.java

String userInput;
while(in.hasNext()){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps this space can be removed

Comment thread src/main/java/Duke.java Outdated
Comment on lines +27 to +31
if (taskList.size() == 1){
System.out.println("Now you have " +taskList.size()+" task in the list.");
} else {
System.out.println("Now you have " + taskList.size() + " tasks in the list.");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can consider refactoring this portion of code into a method as it is repeated multiple times in the if-else statements

Comment thread src/main/java/Duke.java Outdated
System.out.println("Got it. I've added this task:");
System.out.println(taskList.get(finalTask).toString());
if (taskList.size() == 1){
System.out.println("Now you have " +taskList.size()+" task in the list.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps you can include spaces like this to be more consistent in your formatting

Suggested change
System.out.println("Now you have " +taskList.size()+" task in the list.");
System.out.println("Now you have " + taskList.size() + " task in the list.");

@slightlyharp slightlyharp left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good job in term of code standard. However there are still room for improvement for readability. Please take note of the naming of variables, improve on abstractions and remember to give comments to your code.

@@ -0,0 +1,11 @@
public class Deadline extends Task {
protected String due;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use noun for variable. Perhaps dueDate is a better name for it.

Comment thread src/main/java/Duke.java Outdated
String [] listArray = userInput.split("/",2);
String description = listArray[0];
String dueDate = listArray[1];
String info = description.substring(8).trim();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider avoid all these magic numbers, use named constant instead.
Perhaps use space to split up the phrase instead of hardcoding the character position.

@@ -0,0 +1,11 @@
public class Deadline extends Task {
protected String due;
public Deadline(String info, String due) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps name is a better naming for the variable instead of info

Comment thread src/main/java/Duke.java Outdated
System.out.println("Now you have " + tasks.size() + " tasks in the list.");
}
} else if (userInput.contains("deadline")) {
String [] listArray = userInput.split("/",2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider changing to a more meaningful name such as phrases

Comment thread src/main/java/Duke.java Outdated
String userInput;
while(in.hasNext()){
userInput = in.nextLine();
if(userInput.equals("bye")){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Leave a space before the open curly bracket

Comment thread src/main/java/Duke.java Outdated
if (tasks.size() == 1) {
System.out.println("Now you have " + tasks.size() + " task in the list.");
} else {
System.out.println("Now you have " + tasks.size() + " tasks in the list.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider creating a method for this since it is used a few times in the code

Comment thread src/main/java/Duke.java Outdated
System.out.println("Now you have " + tasks.size() + " tasks in the list.");
}
} else if(userInput.contains("mark")){
Integer itemNumber;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can still use normal int data type

Comment thread src/main/java/Duke.java Outdated
String [] listArray = userInput.split("/",3);
String description = listArray[0];
String startTime = listArray[1];
String endTime = listArray[2];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

User might not give the desired input. Consider implement some error handling taught in week 5

Comment thread src/main/java/Todo.java
public Todo (String info) {
super (info);
}
public String toString() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps adding override annotation to indicate that the method is overriding a method from the parent class. Be consistent in the annotations for all the classes.

Comment thread src/main/java/Duke.java
}
}
}
} No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Relatively long and deep nested code. Consider break up the code with more abstractions. (create method for segments that are used repeatedly and a method for each command)

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