-
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 19 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
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package duke; | ||
|
|
||
| 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 |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| package duke; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class Duke { | ||
|
|
||
| private static int byeFlag = 0; | ||
| private static int positionCheck = 0; | ||
| private static int SIZE = 100; | ||
|
||
| private static String EMPTY = "There is no data in your list master!"; | ||
| private static String EXCEEDED = "Oh dear me! We have exceeded my system's maximum capacity!"; | ||
| private static String UNSPECIFIED_DONE = "Oh no master, I am not quite sure which task you would like me to mark as done!"; | ||
| private static String INVALID = "Please type in a valid number master! Type \"list\" to check the index number of your list data"; | ||
| public static String DEADLINE_ERROR = ("Sorry Master! I don't think you have properly keyed in the parameters.\n" + | ||
| "Please enter \"deadline\", followed by the task, followed by \"/by\", \n" + | ||
| "and lastly followed by the due date to specify the deadline Master!"); | ||
| public static String EVENT_ERROR = ("Sorry Master! I don't think you have properly keyed in the parameters. \n" + | ||
| "Please enter \"event\", followed by the event, followed by \"/at\", and \n" + | ||
| "lastly followed by the event duration to specify the timing of the event Master!"); | ||
| public static String TODO_ERROR = ("Sorry Master! I don't think you have properly keyed in the parameters.\n" + | ||
| " Please enter \"todo\", followed by the task you wish to add to your \n" + | ||
| "duke.Todo list Master!"); | ||
| public static String UNSPECIFIED_TASK = ("Sorry Master! Despite the fact that I am fluent in over six million forms\n" + | ||
| " of communication, I am unable to comprehend your request. Please specify\n" + | ||
| " the type of task that you wish to add Master!"); | ||
|
||
|
|
||
| private static Task[] commands = new Task[SIZE]; | ||
|
|
||
| // sendCommand() is a method used to allow the user to send his/her commands to C3PO | ||
|
||
| private static void sendCommand() { | ||
| String line; | ||
| Scanner in = new Scanner(System.in); | ||
| while (byeFlag != 1) { | ||
| try { | ||
| System.out.println("____________________________________________________________\n"); | ||
| System.out.print("Type something: "); | ||
| line = in.nextLine(); | ||
| System.out.println("____________________________________________________________\n"); | ||
| checkCommand(line); | ||
| } catch (DukeException e) { | ||
|
|
||
| } | ||
|
||
| } | ||
| } | ||
|
|
||
| // checkCommand() is a method that allows us to determine when the user says bye. | ||
| private static void checkCommand(String line) throws DukeException { | ||
| String[] input = line.split(" "); | ||
| if (line.equals("bye")) { | ||
| byeFlag = 1; | ||
| } else if (line.equals("list")) { | ||
| if (positionCheck == 0) { | ||
| throw new DukeException(EMPTY); | ||
| } else { | ||
| printList(); | ||
| } | ||
| } else if (line.equals("done")) { | ||
| throw new DukeException(UNSPECIFIED_DONE); | ||
| } else if (input[0].equals("done")) { | ||
| if (positionCheck<=0) { | ||
|
||
| throw new DukeException(EMPTY); | ||
| } else if ((Integer.parseInt(input[1]) > positionCheck ) || (Integer.parseInt(input[1]) <= 0)) { | ||
|
||
| throw new DukeException(INVALID); | ||
| } else { | ||
| markDone(Integer.parseInt(input[1])-1); | ||
|
||
| } | ||
| } else if (positionCheck >= SIZE) { | ||
| throw new DukeException(EXCEEDED); | ||
| } 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 addDeadline(String[] input, int length) throws DukeException { | ||
| 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; | ||
| } | ||
| } | ||
| throw new DukeException(DEADLINE_ERROR); | ||
| } | ||
|
|
||
| public static void addEvent(String[] input, int length) throws DukeException{ | ||
|
||
| 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; | ||
| } | ||
| } | ||
| throw new DukeException(EVENT_ERROR); | ||
| } | ||
|
|
||
| public static void addTodo (String[] input, int length) throws DukeException{ | ||
|
||
| if (length == 1) { | ||
| throw new DukeException(TODO_ERROR); | ||
| } 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) throws DukeException { | ||
| 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 { | ||
| throw new DukeException(UNSPECIFIED_TASK); | ||
| } | ||
| } | ||
|
|
||
| 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) throws DukeException { | ||
| greetUser(); | ||
| sendCommand(); | ||
| sayBye(); | ||
| } | ||
| } | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package duke; | ||
|
|
||
| public class DukeException extends Exception { | ||
| public DukeException(String errorMessage){ | ||
| super(errorMessage); | ||
| System.out.println(errorMessage); | ||
| } | ||
| } | ||
|
Comment on lines
+3
to
+16
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. Great use of super, with this overwriting of error messages are done easily |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package duke; | ||
|
|
||
| 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,23 @@ | ||
| package duke; | ||
|
|
||
| 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,13 @@ | ||
| package duke; | ||
|
|
||
| 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.
Great to see that you organise your types (e.g., classes) into a package for easier management!