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

[TJ-Hoo] iP #190

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

[TJ-Hoo] iP #190

wants to merge 33 commits into from

Conversation

TJ-Hoo
Copy link

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

No description provided.

Copy link

@Stella1585 Stella1585 left a comment

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.

System.out.print(i+1+".");
System.out.println(taskList.get(i).markTask()+taskList.get(i).name);
}
} else if(userInput.contains("unmark") || userInput.contains("mark")){

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?

}
} else if(userInput.contains("unmark") || userInput.contains("mark")){
Integer itemNumber = new Integer(0);
String [] IndexArr = userInput.split(" ",2);

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.

boolean isFinished = false;
List toDoList = new List();
Scanner in = new Scanner(System.in);
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.

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

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

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.

if(userInput.equals("bye")){
break;
}
if(userInput.equals("list")){

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 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

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

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

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


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

Copy link

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 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

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

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

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.");

Copy link

@slightlyharp slightlyharp left a comment

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;

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.

String [] listArray = userInput.split("/",2);
String description = listArray[0];
String dueDate = listArray[1];
String info = description.substring(8).trim();

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) {

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

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

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

String userInput;
while(in.hasNext()){
userInput = in.nextLine();
if(userInput.equals("bye")){

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

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.");

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

System.out.println("Now you have " + tasks.size() + " tasks in the list.");
}
} else if(userInput.contains("mark")){
Integer itemNumber;

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

String [] listArray = userInput.split("/",3);
String description = listArray[0];
String startTime = listArray[1];
String endTime = listArray[2];

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

public Todo (String info) {
super (info);
}
public String toString() {

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.

}
}
}

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