-
Notifications
You must be signed in to change notification settings - Fork 197
[Liam Van] IP #199
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?
[Liam Van] IP #199
Changes from 5 commits
ab76983
66f05b6
326cf60
e77c524
2cc0131
489244b
9cc6ba3
9939b56
c8898cc
c233d69
a760d20
238fb85
acd898a
6940bc1
96b58be
804bf2e
d9dc7c1
99237ca
f9bb7fe
73543ab
cef26a2
5886c71
c12849d
eee98c8
1b6cb39
c222d8e
660cda3
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,107 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Duke { | ||
|
|
||
| public Duke() { | ||
|
|
||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| Duke duke = new Duke(); | ||
| ArrayList<String> userInputs = new ArrayList<>(); | ||
| boolean isRun = true; | ||
| Scanner scan = new Scanner(System.in); | ||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
|
|
||
| greetUser(); | ||
|
|
||
| while (true) { | ||
| String input = scan.nextLine(); | ||
| if (input.equals("bye")) { | ||
| break; | ||
| } | ||
| if (input.equals("list")) { | ||
| listOut(userInputs); | ||
| } else if (input.length() >= 4 && input.substring(0, 4).equals("mark")) { | ||
| String[] tmpArr = input.split(" "); | ||
| markDone(Integer.parseInt(tmpArr[1]), userInputs, true); | ||
| } else if (input.length() >= 6 && input.substring(0, 6).equals("unmark")) { | ||
| String[] tmpArr = input.split(" "); | ||
| markDone(Integer.parseInt(tmpArr[1]), userInputs, false); | ||
| } else { | ||
| addToList(input, userInputs); | ||
| } | ||
| //echoCmd(input); | ||
|
|
||
|
|
||
| } | ||
| exit(); | ||
| } | ||
|
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. Just nitpicking, but would be nice if there was a space after this :^) |
||
| public static void markDone(int index, ArrayList<String> userInputs, boolean isMark) { | ||
| if (isMark) { | ||
| String org = userInputs.get(index - 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. I think it would be better to use a more descriptive name -- not sure what |
||
| String newStr = org.replace("[ ]", "[X]"); | ||
| System.out.println(newStr); | ||
| userInputs.set(index - 1, newStr); | ||
| } else { | ||
| String org = userInputs.get(index - 1); | ||
| String newStr = org.replace("[X]", "[ ]"); | ||
| System.out.println(newStr); | ||
| userInputs.set(index - 1, newStr); | ||
| } | ||
| System.out.println("\t____________________________________________________________"); | ||
| if (isMark) { | ||
| System.out.println("\t Nice! I've marked this task as done:"); | ||
| } else { | ||
| System.out.println("\t OK, I've marked this task as not done yet:"); | ||
| } | ||
| int idx = userInputs.get(index - 1).indexOf("["); | ||
| System.out.println("\t" + " " + userInputs.get(index - 1).substring(idx)); | ||
| System.out.println("\t____________________________________________________________"); | ||
| } | ||
| public static void addToList(String cmd, ArrayList<String> userInputs) { | ||
| System.out.println("\t____________________________________________________________"); | ||
| System.out.println("\tadded: " + cmd); | ||
| System.out.println("\t____________________________________________________________"); | ||
| userInputs.add(cmd); | ||
| userInputs.set(userInputs.size() - 1, userInputs.size() + ". [ ] " + userInputs.get(userInputs.size() - 1)); | ||
| } | ||
|
|
||
| public static void listOut(ArrayList<String> userInputs) { | ||
| System.out.println("\t____________________________________________________________"); | ||
| for (int i = 0; i < userInputs.size(); i++) { | ||
| System.out.println("\t" + userInputs.get(i)); | ||
| } | ||
| System.out.println("\t____________________________________________________________"); | ||
|
|
||
| } | ||
| public static void echoCmd(String cmd) { | ||
| System.out.println("\t____________________________________________________________"); | ||
| System.out.println("\t " + cmd); | ||
| System.out.println("\t____________________________________________________________"); | ||
|
|
||
| } | ||
|
|
||
| public static void greetUser() { | ||
| System.out.println("\t____________________________________________________________"); | ||
| System.out.println("\tHello! I'm Duke"); | ||
| System.out.println("\tWhat can I do for you?"); | ||
| System.out.println("\t____________________________________________________________"); | ||
|
|
||
| } | ||
|
|
||
| public static void exit() { | ||
| System.out.println("\t____________________________________________________________"); | ||
| System.out.println("\tBye. Hope to see you again soon!"); | ||
| System.out.println("\t____________________________________________________________"); | ||
|
|
||
| } | ||
|
|
||
| } | ||
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.
Like your naming for the ArrayList!