-
Notifications
You must be signed in to change notification settings - Fork 200
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
base: master
Are you sure you want to change the base?
[TJ-Hoo] iP #190
Changes from 8 commits
a1fb5b3
50e9438
8f06dc1
15e6f91
f19569e
aeb3c02
8b22744
1feb6e5
7c31d51
1bf5e36
3d6f6e3
875ec03
2f9f975
6bdd653
e1391de
8206b33
2e3fd7c
4375e13
905f7d0
1ebdea6
31322c7
3986655
9c0ba57
f221b77
ce6d09e
c25b455
f8faf8e
9366fd6
4eb7c4a
24afabf
3f092ce
dc79a03
fd2c8f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,42 @@ | ||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
public class Duke { | ||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
System.out.println("Hello! I'm Duke \nWhat can I do for you?"); | ||
Scanner in = new Scanner(System.in); | ||
ArrayList<Task> taskList = new ArrayList<Task>(); | ||
|
||
String userInput; | ||
while(in.hasNext()){ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps this space can be removed |
||
userInput = in.nextLine(); | ||
if(userInput.equals("bye")){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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")){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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")){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
taskList.add(taskList.size(), new Task(userInput,false)); | ||
System.out.println("added: "+userInput); | ||
} | ||
} | ||
System.out.println("Bye. Hope to see you again soon!"); | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import java.util.ArrayList; | ||
|
||
public class List { | ||
private ArrayList<Task> toDoList; | ||
|
||
public List() { | ||
this.toDoList = new ArrayList<Task>(); | ||
} | ||
|
||
public void addTask(String userInput) { | ||
toDoList.add(new Task(userInput)); | ||
} | ||
|
||
public void printList() { | ||
int counter = 1; | ||
for (Task task : toDoList) { | ||
System.out.println(counter + ". " + task.printName()); | ||
counter++; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class Task { | ||
protected String name; | ||
protected boolean isCompleted; | ||
public Task(String name, boolean isCompleted) { | ||
this.name = name; | ||
isCompleted = false; | ||
} | ||
|
||
public String markTask (){ | ||
return(isCompleted?"[X]":"[ ]"); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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