-
Notifications
You must be signed in to change notification settings - Fork 114
[Mikolaj Jedrzejewski] iP #97
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?
Changes from 5 commits
68c58c1
03523ec
81a9c53
f8bb5fb
4b6a8b1
66187d7
e62452e
934dabd
5089664
266dda4
37e3f9b
97047ec
f4594ed
c7d735b
7aead71
5682555
73d4c22
e117036
a76c9ad
f1a9136
bb903a4
7119092
bcd72f0
7cb4643
a144c7c
a58e2d5
6702bb4
4f34a67
acf8c93
44da9b8
2c38341
ed28a9d
3b5a414
1031f84
ede59cb
cbc2fdc
2f33e97
cb9105a
7762786
5e18e76
e561e10
a754e2e
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,38 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.Scanner; | ||
|
|
||
| public class IO { | ||
| private static Scanner scanner;; | ||
|
|
||
| public static void init() { | ||
| scanner = new Scanner(System.in); | ||
| } | ||
|
|
||
| public static void printResponse(String text) { | ||
| String lineSeparator = "-------------------------------"; | ||
| text = lineSeparator + "\n" + text + "\n" + lineSeparator + "\n"; | ||
| String formattedText = text.replaceAll("(?m)^", "\t"); | ||
| System.out.print(formattedText); | ||
| } | ||
|
|
||
| public static String getRequest() { | ||
| return scanner.nextLine(); | ||
| } | ||
|
|
||
| public static void printAddedTask(String text) { | ||
| printResponse(text.toLowerCase()); | ||
| } | ||
|
|
||
| public static void printTaskList(ArrayList<Task> taskList) { | ||
| StringBuilder taskListString = new StringBuilder(); | ||
| for (int i = 0; i < taskList.size(); i++) { | ||
| taskListString.append(i + 1); | ||
| taskListString.append(". "); | ||
| taskListString.append(taskList.get(i).toString()); | ||
| if (i < taskList.size() - 1) { | ||
| taskListString.append("\n"); | ||
| } | ||
| } | ||
| printResponse(taskListString.toString()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import java.util.ArrayList; | ||
|
|
||
| public class Pythia { | ||
| private static String botName = "Pythia"; | ||
| private static String logo = | ||
| "____ _ _ _ \n" + | ||
| "| _ \\ _ _| |_| |__ (_) __ _ \n" + | ||
| "| |_) | | | | __| '_ \\| |/ _` |\n" + | ||
| "| __/| |_| | |_| | | | | (_| |\n" + | ||
| "|_| \\__, |\\__|_| |_|_|\\__,_|\n" + | ||
| " |___/ "; | ||
|
|
||
| private static boolean byeSaid = false; | ||
| private static ArrayList<Task> taskList = new ArrayList<Task>(); | ||
|
|
||
| public static void greet() { | ||
| String helloMsg = "Welcome, seeker. I am " + botName + ".\n" + | ||
| "What brings you here?"; | ||
| IO.printResponse(helloMsg); | ||
|
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. Spacing looks a little off to me. |
||
| } | ||
|
|
||
| public static void echo(String text) { | ||
| IO.printResponse(text); | ||
| } | ||
|
|
||
| public static void sayBye() { | ||
| String byeMsg = "Your path is set. Until we meet again."; | ||
| IO.printResponse(byeMsg); | ||
| byeSaid = true; | ||
| } | ||
|
|
||
| public static void listTasks() { | ||
| IO.printTaskList(taskList); | ||
| } | ||
|
|
||
| public static void chooseAction(String request) { | ||
| String key = request.split(" ")[0]; | ||
| String value = ""; | ||
|
|
||
| if (request.split(" ").length > 1) { | ||
| value = request.substring(key.length() + 1); | ||
| } | ||
|
|
||
| switch (key) { | ||
| case "bye" -> sayBye(); | ||
| case "list" -> listTasks(); | ||
| case "add" -> addTask(value); | ||
| case "mark" -> markTask(Integer.parseInt(value)); | ||
| default -> IO.printResponse("Hmm. I am not sure what you mean."); | ||
|
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 you handled edge 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. nice change to make this much more readable! |
||
| } | ||
| } | ||
|
|
||
| public static void addTask(String taskName) { | ||
| taskList.add(new Task(taskName)); | ||
| IO.printAddedTask("added: " + taskName); | ||
| } | ||
|
|
||
| public static void markTask(Integer taskNumber) { | ||
| if (taskNumber <= taskList.size()) { | ||
| taskList.get(taskNumber - 1).markAsDone(); | ||
| String msg = "Nice! I've marked this task as done:\n\t" + taskList.get(taskNumber - 1).toString(); | ||
| IO.printResponse(msg); | ||
| } else { | ||
| IO.printResponse("There is no such 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 change to follow coding standard. |
||
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| IO.init(); | ||
| greet(); | ||
|
|
||
| while (!byeSaid) { | ||
| String request = IO.getRequest(); | ||
| chooseAction(request); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| public class Task { | ||
| private String name; | ||
| private boolean status; | ||
|
|
||
| public Task(String name, boolean status) { | ||
| this.name = name; | ||
| this.status = status; | ||
| } | ||
|
|
||
| public Task(String name) { | ||
| this.name = name; | ||
| this.status = false; | ||
| } | ||
|
|
||
|
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. LGTM |
||
| public void markAsDone() { | ||
| this.status = true; | ||
| } | ||
|
|
||
| public void markAsNotDone() { | ||
| this.status = false; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public boolean getStatus() { | ||
| return status; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| if (status == false) { | ||
| return "[ ] " + name; | ||
| } else { | ||
|
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 changes to maintain code quality standard. |
||
| return "[X] " + name; | ||
| } | ||
| } | ||
| } | ||
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.
I think the original looks good already.