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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a1fb5b3
no message
TJ-Hoo Jan 25, 2023
50e9438
Revert "no message"
TJ-Hoo Jan 30, 2023
8f06dc1
no message
TJ-Hoo Jan 30, 2023
15e6f91
Revert "no message"
TJ-Hoo Jan 30, 2023
f19569e
Level 0
TJ-Hoo Jan 30, 2023
aeb3c02
Level 1
TJ-Hoo Jan 31, 2023
8b22744
Level 2
TJ-Hoo Jan 31, 2023
1feb6e5
Level 3
TJ-Hoo Feb 1, 2023
7c31d51
Level 4
TJ-Hoo Feb 1, 2023
1bf5e36
A-CodingStandard
TJ-Hoo Feb 9, 2023
3d6f6e3
A-CodingQuality
TJ-Hoo Feb 9, 2023
875ec03
Level-5
TJ-Hoo Feb 16, 2023
2f9f975
Level-6
TJ-Hoo Feb 22, 2023
6bdd653
Level-7
TJ-Hoo Feb 22, 2023
e1391de
Merge branch 'branch-level-7'
TJ-Hoo Feb 25, 2023
8206b33
Level-9
TJ-Hoo Feb 25, 2023
2e3fd7c
Merge pull request #1 from TJ-Hoo/branch-level-9
TJ-Hoo Feb 25, 2023
4375e13
A-JavaDoc
TJ-Hoo Feb 25, 2023
905f7d0
Merge pull request #2 from TJ-Hoo/branch-JavaDoc
TJ-Hoo Feb 25, 2023
1ebdea6
Update README.md
TJ-Hoo Feb 25, 2023
31322c7
Update README.md
TJ-Hoo Feb 25, 2023
3986655
no message
TJ-Hoo Feb 25, 2023
9c0ba57
Rename README.md to UserGuide
TJ-Hoo Feb 26, 2023
f221b77
Merge remote-tracking branch 'origin/master'
TJ-Hoo Feb 26, 2023
ce6d09e
Merge remote-tracking branch 'origin/master'
TJ-Hoo Feb 26, 2023
c25b455
Update README.md
TJ-Hoo Feb 26, 2023
f8faf8e
Update README.md
TJ-Hoo Feb 26, 2023
9366fd6
Update README.md
TJ-Hoo Feb 26, 2023
4eb7c4a
Minor Fixes
TJ-Hoo Feb 26, 2023
24afabf
Merge remote-tracking branch 'origin/master'
TJ-Hoo Feb 26, 2023
3f092ce
Minor improvements
TJ-Hoo Feb 28, 2023
dc79a03
Minor bug fixes
TJ-Hoo Feb 28, 2023
fd2c8f9
Minor fix
TJ-Hoo Mar 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
import java.util.Scanner;
import java.util.ArrayList;
public class Duke {
public static void main(String[] args) {
System.out.println("Hello! I'm Duke \nWhat can I do for you?");

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


String userInput;
Scanner scan = new Scanner(System.in);

while (!isFinished) {
userInput = scan.nextLine();
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

if (userInput.equals("bye")) {
System.out.println("Bye. Hope to see you again soon!");
isFinished = true;
} else if (userInput.equals("list")) {
toDoList.printList();
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

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?

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.

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

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.

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).markTask() + taskList.get(itemNumber).name);
}
else {
System.out.println("Nice! I've marked this task as done:");
taskList.get(itemNumber).isCompleted = true;
System.out.println(taskList.get(itemNumber).markTask() + taskList.get(itemNumber).name);
}
} else {
toDoList.addTask(userInput);
System.out.println("added: " + userInput);
taskList.add(taskList.size(), new Task(userInput,false));
System.out.println("added: "+userInput);
}
}
System.out.println("Bye. Hope to see you again soon!");
}
}
}

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)

12 changes: 7 additions & 5 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
public class Task {
private String name;

public Task(String name) {
protected String name;
protected boolean isCompleted;
public Task(String name, boolean isCompleted) {
this.name = name;
isCompleted = false;
}

public String printName() {
return name;
public String markTask (){
return(isCompleted?"[X]":"[ ]");
}
}