-
Notifications
You must be signed in to change notification settings - Fork 191
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?
iP #188
Changes from 8 commits
0acc03a
e5a6c76
73e933e
9aa6701
9d224de
d10b249
431e205
423e4b6
dd62bad
0fd82f9
69645da
f2d4394
0a70a2e
8235c1d
199fc4c
e893cef
f0a5864
75c9f16
f192e85
b88ba29
da1e49e
23fdf30
4643e21
d87aae0
9609e5f
47dd64e
95d1f4f
692352e
d31772b
db8bd73
57a79f0
8e7fd03
21c0704
a1a550c
32656a1
7306402
c50db4d
a1ce7a1
52c2770
b32f9ed
a332d1a
7c7da8e
ebf987f
2f8ce8d
5dce913
4561808
a3b5c81
f16c13f
99cffd9
55f4c5b
6310239
4e96b08
5a77160
a1236a4
e6f1fd6
4f230f3
56fdebc
a279691
6022a07
d89f151
abf55fd
553b120
9d2ea67
7154720
effe27d
3b0adcf
55bc19a
d2019f2
3bc240c
56bb844
ffa2789
8cb4736
4466d03
b5a9282
b883ff9
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,15 @@ | ||
|
|
||
| public class Deadline extends Task { | ||
|
|
||
| protected String by; | ||
|
|
||
| public Deadline(String description, String by) { | ||
| super(description); | ||
| this.by = by; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[D][" + getStatusIcon() + "] " + super.toString() + " (by: " + by + ")"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,188 @@ | ||
| import java.util.Locale; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Duke { | ||
|
|
||
| private static int byeFlag = 0; | ||
| private static int positionCheck = 0; | ||
| private static Task[] commands = new Task[100]; | ||
|
|
||
| // sendCommands() is a method used to allow the user to send his/her commands to C3PO | ||
| private static void sendCommands() { | ||
| String line; | ||
| Scanner in = new Scanner(System.in); | ||
| while (byeFlag != 1) { | ||
| System.out.println("____________________________________________________________\n"); | ||
|
||
| System.out.print("Type something: "); | ||
| line = in.nextLine(); | ||
| System.out.println("____________________________________________________________\n"); | ||
| checkCommands(line); | ||
| } | ||
| } | ||
|
|
||
| // checkCommands() is a method that allows us to determine when the user says bye. | ||
| private static void checkCommands(String line) { | ||
|
||
| String[] input = line.split(" "); | ||
| if (line.equals("bye")) { | ||
| byeFlag = 1; | ||
| } else if (line.equals("list")) { | ||
| if (positionCheck == 0) { | ||
| sayEmpty(); | ||
| } else { | ||
|
||
| printList(); | ||
| } | ||
| } else if (line.equals("done")) { | ||
| sayNotSpecified(); | ||
| } else if (input[0].equals("done")) { | ||
| if ((Integer.parseInt(input[1]) > positionCheck ) || (Integer.parseInt(input[1]) <= 0)) { | ||
| sayInvalidNumber(); | ||
| } else if (positionCheck<=0) { | ||
| sayEmpty(); | ||
| } else { | ||
| markDone(Integer.parseInt(input[1])-1); | ||
| } | ||
| } else if (positionCheck >= 100) { | ||
| sayExceededCapacity(); | ||
| } else { | ||
| checkTypeOfTask(line); | ||
| } | ||
| } | ||
|
|
||
| public static void sayBye() { | ||
| System.out.println("Goodbye master! May the force be with you!\n"); | ||
| System.out.println("____________________________________________________________\n"); | ||
| } | ||
|
|
||
| public static void sayEmpty() { | ||
| System.out.println("There is no data in your list master!"); | ||
| } | ||
|
|
||
| public static void sayExceededCapacity() { | ||
| System.out.println("Oh dear me! We have exceeded my system's maximum capacity!"); | ||
| } | ||
|
|
||
| public static void sayNotSpecified() { | ||
| System.out.println("Oh no master, I am not quite sure which task you would like me to mark as done"); | ||
| } | ||
|
|
||
| public static void sayInvalidNumber() { | ||
| System.out.println("Please type in a valid number master! Type \"list\" to check the index number of your list data"); | ||
| } | ||
|
|
||
| public static void addDeadline(String[] input, int length) { | ||
| String description; | ||
| String by; | ||
| for (int i = 1 ; i < length ; i++) { | ||
| if ((input[i].equals("/by")) && (i != 1) && (i != (length-1))) { | ||
| description = input[1]; | ||
| by = input[i+1]; | ||
| for (int j = 2 ; j < i ; j++) { | ||
| description += (" " + input[j]); | ||
| } | ||
| for (int k = i+2 ; k < length ; k++) { | ||
| by += (" " + input[k]); | ||
| } | ||
| commands[positionCheck] = new Deadline(description,by); | ||
| System.out.println("Added to Galactic database:" ); | ||
| System.out.println(commands[positionCheck]); | ||
| positionCheck += 1; | ||
| return; | ||
| } | ||
| } | ||
| System.out.println("Sorry Master! I don't think you have properly keyed in the parameters. Please enter the task, followed by \"/by\",\n" + | ||
|
||
| "followed by the due date to specify the deadline Master!"); | ||
| } | ||
|
|
||
| public static void addEvent(String[] input, int length) { | ||
|
||
| String description; | ||
| String at; | ||
| for (int i = 1 ; i < length ; i++) { | ||
| if ((input[i].equals("/at")) && (i != 1) && (i != (length-1))) { | ||
| description = input[1]; | ||
| at = input[i+1]; | ||
| for (int j = 2 ; j < i ; j++) { | ||
| description += (" " + input[j]); | ||
| } | ||
| for (int k = i+2 ; k < length ; k++) { | ||
| at += (" " + input[k]); | ||
| } | ||
| commands[positionCheck] = new Event(description,at); | ||
| System.out.println("Added to Galactic database:" ); | ||
| System.out.println(commands[positionCheck]); | ||
| positionCheck += 1; | ||
| return; | ||
| } | ||
| } | ||
| System.out.println("Sorry Master! I don't think you have properly keyed in the parameters. \n" + | ||
| "Please enter the event, followed by \"/at\", followed by the event duration to specify \n" + | ||
| "the timing of the event Master!"); | ||
| } | ||
|
|
||
| public static void addTodo (String[] input, int length) { | ||
| if (length == 1) { | ||
| System.out.println("Sorry Master! I don't think you have properly keyed in the parameters.\n" + | ||
| " Please enter the task you wish to add to your Todo list Master!"); | ||
| } else { | ||
| String description = input[1]; | ||
| for (int i = 2 ; i < length ; i++) { | ||
| description += (" " + input[i]); | ||
| } | ||
| commands[positionCheck] = new Todo(description); | ||
| System.out.println("Added to Galactic database:" ); | ||
| System.out.println(commands[positionCheck]); | ||
| positionCheck += 1; | ||
| } | ||
| } | ||
|
|
||
| public static void checkTypeOfTask(String line) { | ||
| String[] input = line.split(" "); | ||
| int length = input.length; | ||
| if (input[0].toLowerCase().equals("deadline")) { | ||
| addDeadline(input,length); | ||
| } else if (input[0].toLowerCase().equals("event")) { | ||
| addEvent(input,length); | ||
| } else if (input[0].toLowerCase().equals("todo")) { | ||
| addTodo(input,length); | ||
| } else { | ||
| System.out.println("Sorry Master! Please specify the type of task that you wish to add as well!"); | ||
| } | ||
| } | ||
|
|
||
| private static void printList() { | ||
| System.out.println("Accessing archives..."); | ||
| for (int i = 0; i < positionCheck; i++) { | ||
| System.out.println((i+1) + ". " + commands[i]); | ||
| } | ||
| } | ||
|
|
||
| private static void markDone(int doneTaskNumber) { | ||
| commands[doneTaskNumber].markAsDone(); | ||
| System.out.println("The following task has been marked as done Master!"); | ||
| System.out.println((doneTaskNumber+1) + ". " + commands[doneTaskNumber]); | ||
| } | ||
|
|
||
| public static void greetUser() { | ||
| String logo = " /~\\\n" | ||
| + " |oo )\n" | ||
| + " _\\=/_\n" | ||
| + " / \\\n" | ||
| + " //|/.\\|\\\\\n" | ||
| + " || \\_/ ||\n" | ||
| + " || |\\ /| ||\n" | ||
| + " # \\_ _/ #\n" | ||
| + " | | |\n" | ||
| + " | | |\n" | ||
| + " []|[]\n" | ||
| + " | | |\n" | ||
| + " /_]_[_\\\n"; | ||
| System.out.println("____________________________________________________________\n"); | ||
| System.out.println("Hello! I am C3P0! Human-cyborg relations! \n" + " \n" + logo); | ||
| System.out.println("What can I do for you my master?\n"); | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| greetUser(); | ||
| sendCommands(); | ||
| sayBye(); | ||
| } | ||
| } | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| public class Event extends Task{ | ||
|
|
||
| protected String at; | ||
|
|
||
| public Event(String description, String at) { | ||
| super(description); | ||
| this.at = at; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[E][" + getStatusIcon() + "] " + super.toString() + " (at: " + at + ")"; | ||
| } | ||
| } |
| 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 | ||
| } | ||
|
|
||
| public void markAsDone() { | ||
| this.isDone = true; | ||
| } | ||
|
|
||
| public String toString() { | ||
| return description; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| public class Todo extends Task{ | ||
|
|
||
| public Todo(String description) { | ||
| super(description); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[T][" + getStatusIcon() + "] " + super.toString(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,40 @@ | ||
| Hello from | ||
| ____ _ | ||
| | _ \ _ _| | _____ | ||
| | | | | | | | |/ / _ \ | ||
| | |_| | |_| | < __/ | ||
| |____/ \__,_|_|\_\___| | ||
| ____________________________________________________________ | ||
|
|
||
| Hello! I am C3P0! Human-cyborg relations! | ||
|
|
||
| /~\ | ||
| |oo ) | ||
| _\=/_ | ||
| / \ | ||
| //|/.\|\\ | ||
| || \_/ || | ||
| || |\ /| || | ||
| # \_ _/ # | ||
| | | | | ||
| | | | | ||
| []|[] | ||
| | | | | ||
| /_]_[_\ | ||
|
|
||
| What can I do for you my master? | ||
|
|
||
| ____________________________________________________________ | ||
|
|
||
| Type something: ____________________________________________________________ | ||
|
|
||
| Added to Galactic database: | ||
| [T][ ] go the gym | ||
| ____________________________________________________________ | ||
|
|
||
| Type something: ____________________________________________________________ | ||
|
|
||
| Added to Galactic database: | ||
| [D][ ] submit assignment (by: 12) | ||
| ____________________________________________________________ | ||
|
|
||
| Type something: ____________________________________________________________ | ||
|
|
||
| Goodbye master! May the force be with you! | ||
|
|
||
| ____________________________________________________________ | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| todo go the gym | ||
| deadline submit assignment /by 12 | ||
| bye |
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.
could be changed to sayCommand as there is only 1 command