-
Notifications
You must be signed in to change notification settings - Fork 461
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
[Singh Abdullah Alexander] iP #519
base: master
Are you sure you want to change the base?
Changes from 1 commit
556af3f
df365b5
1346cd5
35f557b
1427298
924806e
7a099dd
23228eb
79c8c7b
a9e73ff
c267e54
08cf255
917c4da
dafa0e1
ab17e07
ee3871e
2b04497
c453a9a
0770b6e
8e27eb5
d930758
ddbd5f6
36fb04e
b055c54
c225250
d2722ef
d88c342
a5e7b67
56ab4d6
dfc760d
59bf323
4da3212
fd0c357
692246c
4cfda08
2bfa59e
0567cc5
e386799
b668147
c46ee09
0f7a2fe
1c5c16d
9c75ccf
bbf40fc
19c3253
ce78d08
01a6f58
ddd0c10
a0be07b
81eec33
9de9aa0
723befa
59e259f
2bf9003
36401c4
8619248
4562947
ee1e14a
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 |
---|---|---|
|
@@ -6,15 +6,43 @@ public static void main(String[] args) { | |
System.out.println("Hello! I'm Chacha\n" + "What can I do for you?"); | ||
Scanner input = new Scanner(System.in); | ||
String s = input.nextLine(); | ||
ArrayList<String> list = new ArrayList<String>(); | ||
ArrayList<Task> taskList = new ArrayList<Task>(); | ||
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. Good that the variable names are in camel case 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. Can consider making taskList a private static final field in the class |
||
while (!s.equals("bye")) { | ||
if (s.equals("list")) { | ||
for (int i = 0; i < list.size();i++) { | ||
System.out.println(i + 1 + ". " + list.get(i)); | ||
for (int i = 0; i < taskList.size();i++) { | ||
Task t = taskList.get(i); | ||
System.out.println(i + 1 + | ||
".[" + | ||
t.getStatusIcon() + | ||
"] " + | ||
t.getDescription()); | ||
} | ||
|
||
} else if (s.contains("unmark")) { | ||
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. Can consider using s.startsWith function to check if the task type is indeed the first input |
||
|
||
String[] split = s.split("\\s+"); | ||
Task task = taskList.get(Integer.valueOf(split[1]) - 1); | ||
task.unmarkAsDone(); | ||
System.out.println("OK, I've marked this task as not done yet:\n [" + | ||
task.getStatusIcon() + | ||
"] " + | ||
task.getDescription()); | ||
|
||
} else if (s.contains("mark")) { | ||
System.out.println(s.substring(0, 3)); | ||
String[] split = s.split("\\s+"); | ||
Task task = taskList.get(Integer.valueOf(split[1]) - 1); | ||
System.out.println("here"); | ||
task.markAsDone(); | ||
System.out.println("Nice! I've marked this task as done:\n [" + | ||
task.getStatusIcon() + | ||
"] " + | ||
task.getDescription()); | ||
|
||
} else { | ||
list.add(s); | ||
System.out.println("added: " + s); | ||
Task task = new Task(s); | ||
taskList.add(task); | ||
System.out.println("added: " + task.getDescription()); | ||
|
||
} | ||
s = input.nextLine(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
public class Task { | ||
private String description; | ||
private boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public void markAsDone() { | ||
this.isDone = true; | ||
} | ||
|
||
public void unmarkAsDone() { | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); // mark done task with X | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
} |
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.
Maybe can name s differently? To a clearer variable