-
Notifications
You must be signed in to change notification settings - Fork 184
[vimalapugazhan] iP #188
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
base: master
Are you sure you want to change the base?
[vimalapugazhan] iP #188
Changes from 4 commits
ab7d967
5c6c705
0eb2de1
e2343e0
b8381d7
8b4b87b
57b6d91
ccd3da5
715c55b
f0eae4a
71994ee
5e83761
99799cb
bfe0e6b
95805b8
5ae1ba1
1883fae
bb9cd02
b699596
8a24c8d
a5baff9
afaa95b
8fd188b
69ce325
293f494
b0f1acc
b47a8a7
7d25560
92e02c7
8a35d1f
2b44a52
f82932b
78ff600
0c91c3a
a0889ec
9a357a8
2b37913
3e38bc3
976252d
1fbd29e
f7cf060
d60df8f
0536bf5
c73af7b
726b533
744f5d9
c143f9e
c6dd136
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 |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Aragorn { | ||
|
|
||
| public static void main(String[] args) { | ||
| String LINE = " __________________________________________________________\n"; | ||
| String GREET = " Hello! I am Aragorn son of Arathorn, and am called Elessar, the Elfstone, Dúnadan,\n" + | ||
| " the heir of Isildur Elendil's son of Gondor.\n" + | ||
| " What can I do for you?\n"; | ||
| String EXIT = " Bye. Hope to see you again soon!\n"; | ||
| String TAB = " "; | ||
| Task[] list = new Task[100]; | ||
|
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 the length of the task array a variable |
||
| int listLength = 0; | ||
| System.out.println(LINE + GREET + LINE); | ||
| int index; | ||
| String echo; | ||
| Scanner in = new Scanner(System.in); | ||
| while(true) { | ||
| String userInput = in.nextLine(); | ||
|
|
||
| if (userInput.equals("bye")) { | ||
| System.out.println(LINE + TAB + EXIT + LINE); | ||
|
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. consider using multiple print statements to make the code more readable |
||
| return; | ||
| } | ||
|
|
||
| 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. Consider refactoring the code to reduce the length in void main |
||
| System.out.println(LINE); | ||
| System.out.println("Here are the tasks in your list: "); | ||
| for (int i = 0; i < listLength; i += 1) { | ||
| System.out.println(TAB + "[" + list[i].getStatusIcon() + "] " + (i + 1) + ". " + list[i].getDescription()); | ||
| } | ||
| System.out.println(LINE); | ||
| continue; | ||
| } | ||
|
|
||
| if (userInput.contains("unmark")) { | ||
| index = Integer.parseInt(userInput.substring(7)) - 1; | ||
| list[index].markAsUndone(); | ||
| System.out.println(LINE + TAB + "OK, I've marked this task as not done yet:\n" + TAB + | ||
| " [ ] " + list[index].getDescription() +"\n" + LINE); | ||
| continue; | ||
| } | ||
|
|
||
| else if (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. else if should be placed on the same line as on 42 |
||
| index = Integer.parseInt(userInput.substring(5)) - 1; | ||
| list[index].markAsDone(); | ||
| System.out.println(LINE + TAB + "Nice! I've marked this task as done:\n" + TAB + | ||
| " [X] " + list[index].getDescription() +"\n" + LINE); | ||
|
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. Missing a space between + and "\n" |
||
| continue; | ||
| } | ||
|
|
||
| list[listLength] = new Task(userInput); | ||
| listLength += 1; | ||
| echo = userInput; | ||
| System.out.println(LINE + TAB + "added: " + echo + "\n" + LINE); | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
|
|
||
| public class Task { | ||
| protected String description; | ||
| protected boolean isDone; | ||
|
|
||
| public Task(String description) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| public String getStatusIcon() { | ||
| return (isDone ? "X" : " "); // mark done task with X | ||
|
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. ideal to refer to all instance parameters with the this keyword, e.g. this.isDone 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 use of ternary statements, though brackets are not needed to evaluate them |
||
| } | ||
|
|
||
| public void markAsDone() { | ||
| this.setDone(true); | ||
| } | ||
|
|
||
| public void markAsUndone() { | ||
| this.setDone(false); | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| public void setDone(boolean done) { | ||
| isDone = done; | ||
| } | ||
|
|
||
| } | ||
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.
Import was explicitly listed