-
Notifications
You must be signed in to change notification settings - Fork 76
[lckjosh] iP #74
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?
[lckjosh] iP #74
Changes from 7 commits
9af57b0
f35e5e1
c4e3f6e
d219a1f
2d8c682
663cf7c
87a3330
e4200c5
2a749bc
8060406
bd0006b
1d647e3
9e488c2
e2e415d
704093c
00bb9a7
a18d4c0
3223c2a
5637b71
e1dee36
713b1a3
8254280
995547b
8e41dc0
722041b
a9e8f7d
a2c02d8
f95d5a1
3957ae9
2868ee6
1ec406b
ff1c2ca
51145c6
690e241
59e9b5e
54dd0f9
63a2454
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,76 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| 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("____________________________________________________________"); | ||
| System.out.println("Hello from BotBuddy!"); | ||
| System.out.println("What can I do for you?"); | ||
| System.out.println("____________________________________________________________"); | ||
| String input; | ||
| String[] inputArr; | ||
| String command = ""; | ||
| String parameters = ""; | ||
| Task[] tasks = new Task[100]; | ||
| int noOfTasks = 0; | ||
| while (true) { | ||
| Scanner in = new Scanner(System.in); | ||
| input = in.nextLine().trim(); | ||
| inputArr = input.split(" ", 2); | ||
| command = inputArr[0]; | ||
| if (inputArr.length == 2) { | ||
| parameters = inputArr[1]; | ||
| } | ||
|
|
||
| switch (command) { | ||
| case "list": | ||
| if (noOfTasks == 0) { | ||
| 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 using a constant / final variable to represent the line divider |
||
| System.out.println("There are currently no tasks!"); | ||
| System.out.println("____________________________________________________________"); | ||
| break; | ||
| } | ||
| // print out tasks | ||
| System.out.println("____________________________________________________________"); | ||
| for (int i = 0; i < noOfTasks; i++) { | ||
| System.out.println(i + 1 + ". " + tasks[i].getStatusIcon() + " " + tasks[i].getDescription()); | ||
| } | ||
| System.out.println("____________________________________________________________"); | ||
| break; | ||
|
|
||
| case "mark": | ||
| int taskToMark = Integer.parseInt(parameters) - 1; | ||
| tasks[taskToMark].markAsDone(); | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("I've marked this task as done:"); | ||
| System.out.println(tasks[taskToMark].getStatusIcon() + " " + tasks[taskToMark].getDescription()); | ||
| 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 moving code in cases to another function to reduce verbosity |
||
| break; | ||
|
|
||
| case "unmark": | ||
| int taskToUnmark = Integer.parseInt(parameters) - 1; | ||
| tasks[taskToUnmark].markAsUndone(); | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("I've unmarked this task:"); | ||
| System.out.println(tasks[taskToUnmark].getStatusIcon() + " " + tasks[taskToUnmark].getDescription()); | ||
| System.out.println("____________________________________________________________"); | ||
| break; | ||
|
|
||
| case "bye": | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("Goodbye, hope to see you again soon!"); | ||
| System.out.println("____________________________________________________________"); | ||
| in.close(); | ||
|
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. Shift this to outside the loop and the condition becomes the loop condition |
||
| return; | ||
|
|
||
| default: | ||
| // add task | ||
| tasks[noOfTasks] = new Task(input); | ||
| noOfTasks++; | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("added: " + tasks[noOfTasks - 1].getDescription()); | ||
| System.out.println("____________________________________________________________"); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| public class Task { | ||
| protected String description; | ||
| protected boolean isDone; | ||
|
|
||
| public Task(String description) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| public String getStatusIcon() { | ||
| if (isDone) { | ||
| return "[X]"; | ||
| } else { | ||
| return "[ ]"; | ||
| } | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| public void markAsDone() { | ||
| isDone = true; | ||
| } | ||
|
|
||
| public void markAsUndone() { | ||
| isDone = false; | ||
| } | ||
| } |
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.
May cause an unintended program behaviour, consider setting the loop conditional to while the command is not bye