-
Notifications
You must be signed in to change notification settings - Fork 114
[kestryix] iP #96
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?
[kestryix] iP #96
Changes from 4 commits
beabdec
d4e2c74
d9c8a22
9e3f1f9
582b04f
1b21a14
0b90f88
b4c258f
345fde9
b74b7e6
458c528
80c39e8
6775b73
254e14a
e637fcb
2d72853
26619e2
47100fd
344e3f1
665dc42
3c85d94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| 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 | ||
| } | ||
|
Comment on lines
+25
to
+27
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. Maybe you can make the code more explicit here instead of using ternary if operator? |
||
|
|
||
| public void markAsDone() { | ||
| this.isDone = true; | ||
| } | ||
|
|
||
| public void markAsNotDone() { | ||
| this.isDone = false; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.Objects; | ||
| import java.util.Scanner; | ||
|
|
||
| public class TulipTask { | ||
|
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 renaming the class to "Tulip" as "TulipTask" suggests it might inherit from a "Task" class, which can be misleading. 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 class naming as it is not too long and not short. Nice work! |
||
| public static void main(String[] args) { | ||
| String logo = " \n" + | ||
|
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. Excellent job on storing these strings and not using them as Magic strings! |
||
| "--.-- | o --.-- | \n" + | ||
| " | . .| .,---. | ,---.,---.|__/ \n" + | ||
| " | | || || | | ,---|`---.| \\ \n" + | ||
| " ` `---'`---'`|---' ` `---^`---'` `\n" + | ||
| " |"; | ||
|
|
||
| ArrayList<Task> list = new ArrayList<>(); | ||
|
|
||
| System.out.println(logo); | ||
|
|
||
| System.out.println("--------------------------------------------"); | ||
| System.out.println("Hello, I'm TulipTask"); | ||
| System.out.println("What can I do for you today?"); | ||
| System.out.println("--------------------------------------------"); | ||
|
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 extracting the line as a public static final constant to improve maintainability and avoid duplication. |
||
|
|
||
| while (true) { | ||
| Scanner scanner = new Scanner(System.in); | ||
| String input = scanner.nextLine(); | ||
|
|
||
| // if (Objects.equals(input.toLowerCase(), "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. Consider removing the commented-out code if it is no longer needed for clarity and to keep the codebase clean. |
||
| // break; | ||
| // } | ||
| // | ||
| // if (Objects.equals(input.toLowerCase(), "list")) { | ||
| // listTasks(list); | ||
| // } | ||
| // | ||
| // if (input.toLowerCase().contains("mark")) { | ||
| // String[] splitStr = input.split(" "); | ||
| // System.out.println(splitStr[0]); | ||
| // System.out.println(splitStr[1]); | ||
| // } | ||
|
|
||
| String command; | ||
|
|
||
| if (input.toLowerCase().contains("mark")) { | ||
| String[] splitStr = input.split(" "); | ||
| command = splitStr[0]; | ||
| } else { | ||
| command = input.toLowerCase(); | ||
| } | ||
|
|
||
| switch(command) { | ||
| case "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. Maybe you could refactor to avoid magic strings! |
||
| listTasks(list); | ||
| break; | ||
|
|
||
| case "mark": | ||
| String[] splitStr = input.split(" "); | ||
| int index = Integer.parseInt(splitStr[1]) - 1; | ||
| markAsDone(list.get(index)); | ||
| break; | ||
|
|
||
| case "unmark": | ||
| String[] split = input.split(" "); | ||
| int idx = Integer.parseInt(split[1]) - 1; | ||
|
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 more descriptive variable names, such as "index" instead of "idx", for better readability. 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. Maybe avoid different levels of abstraction here (i.e. |
||
| markAsNotDone(list.get(idx)); | ||
| break; | ||
|
|
||
| case "bye": | ||
| System.out.println("--------------------------------------------"); | ||
| System.out.println("Bye! Hope to see you again soon :)"); | ||
| System.out.println("--------------------------------------------"); | ||
| return; | ||
|
|
||
| default: | ||
| Task task = new Task(command); | ||
| list.add(task); | ||
| echo(task); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static void echo (Task task) { | ||
| System.out.println("--------------------------------------------"); | ||
| System.out.println("added: " + task.description); | ||
| System.out.println("--------------------------------------------"); | ||
| } | ||
|
|
||
| public static void listTasks (ArrayList<Task> list) { | ||
| System.out.println("--------------------------------------------"); | ||
| System.out.println("Here are your tasks: "); | ||
| for (int i = 0; i < list.size(); i++) { | ||
| Task task = list.get(i); | ||
| System.out.println((i + 1) + ". " + "[" + task.getStatusIcon() + "] " + task.description); | ||
| } | ||
| System.out.println("--------------------------------------------"); | ||
| } | ||
|
|
||
| public static void markAsDone(Task task) { | ||
| task.markAsDone(); | ||
| System.out.println("--------------------------------------------"); | ||
| System.out.println("Great job! I have marked this task as done: \n" + " [" + task.getStatusIcon() + "] " + task.description); | ||
| System.out.println("--------------------------------------------"); | ||
| } | ||
|
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. I think you need to fix the spacings here. |
||
| public static void markAsNotDone(Task task) { | ||
| task.markAsNotDone(); | ||
| System.out.println("--------------------------------------------"); | ||
| System.out.println("Okay, I have marked this task as not done: \n" + " [" + task.getStatusIcon() + "] " + task.description); | ||
| System.out.println("--------------------------------------------"); | ||
| } | ||
| } | ||
|
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. You may consider adding comment statements here to explain to other engineers what and why you are doing this. |
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
The boolean variable name "isDone" is well-named, as it clearly indicates its purpose and state.