diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 0000000000..011d8bcede --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,14 @@ +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]" + super.toString() + " (" + by + ")"; + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334cc..a33f8e318a 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,78 @@ +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Scanner; +import static java.lang.Integer.parseInt; + public class Duke { - public static void main(String[] args) { + public static void main(String[] args) throws DukeException { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); + + String line = " -----------------------------------------------------------------\n"; + String tab = " "; + String greet = line + + tab + "Hello! I'm Duke\n" + + tab + "What can I do for you?\n" + + line; + System.out.println(greet); + + ArrayList list = new ArrayList(); + Scanner input = new Scanner(System.in); + + while (!input.hasNext("bye")) { + String next = input.nextLine(); + if (next.contains("done")) { + String[] sub = next.split(" "); + list.get(parseInt(sub[1])).markAsDone(); + System.out.println(line + tab + "Nice! I've marked this task as done: \n" + + tab + list.get(parseInt(sub[1])) + "\n" + line); + } else if (next.contains("list")) { + System.out.print(line + tab + "Here are the tasks in your list: \n"); + for (int i = 0; i < list.size(); i++) { + System.out.println(tab + list.get(i)); + } + System.out.print(line); + } else if (next.contains("todo")) { + Task toDo = new ToDo(next.replace("todo", "")); + list.add(toDo); + System.out.println(line + tab + "Got it. I've added this task:"); + System.out.println(tab + toDo); + System.out.println(tab + "Now you have " + list.size() + " tasks in the list.\n" + line); + } else if (next.contains("deadline")) { + String deadline = next.split("/")[1]; + String description = next.split("/")[0].replace("deadline ", ""); + Task dlTask = new Deadline(description, deadline); + list.add(dlTask); + System.out.println(line + tab + "Got it. I've added this task:"); + System.out.println(tab + dlTask); + System.out.println(tab + "Now you have " + list.size() + " tasks in the list.\n" + line); + } else if (next.contains("event")) { + String time = next.split("/")[1]; + String description = next.split("/")[0].replace("event ", ""); + Task eventTask = new Event(description, time); + list.add(eventTask); + System.out.println(line + tab + "Got it. I've added this task:"); + System.out.println(tab + eventTask); + System.out.println(tab + "Now you have " + list.size() + " tasks in the list.\n" + line); + } else if (next.contains("delete")){ + int index = Integer.parseInt(next.replace("delete" , "").trim()); + Task deleted = list.remove( index - 1); + System.out.println(line + tab + "Noted. I've removed this task: "); + System.out.println(tab + deleted); + System.out.println(tab + "Now you have " + list.size() + " tasks in the list.\n" + line); + } else { +// Task t = new Task(next); +// System.out.println(line + " added: " + t.getDescription() + "\n" + line); +// list.add(t); + throw new DukeException(" ____________________________________________________________\n" + + " ☹ OOPS!!! I'm sorry, but I don't know what that means :-(\n" + + " ____________________________________________________________\n"); + } + } + System.out.println(line + " Bye. Hope to see you again soon!\n" + line); } -} +} \ No newline at end of file diff --git a/src/main/java/DukeException.java b/src/main/java/DukeException.java new file mode 100644 index 0000000000..8c0692258b --- /dev/null +++ b/src/main/java/DukeException.java @@ -0,0 +1,5 @@ +public class DukeException extends Exception { + public DukeException (String exception) { + super(exception); + } +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 0000000000..ec8036ae61 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,14 @@ +public class Event extends Task { + + protected String time; + + public Event(String description, String time) { + super(description); + this.time = time; + } + + @Override + public String toString() { + return "[E]" + super.toString() + " (" + time + ")"; + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 0000000000..845449ff06 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,31 @@ +public class Task { + private String description; + private boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public String getStatusIcon() { + if (isDone) { + return "\u2713"; + } else { + return "\u2718"; + } + } + + public String getDescription() { + return description; + } + + public String markAsDone() { + isDone = true; + return getStatusIcon(); + } + + @Override + public String toString() { + return "[" + getStatusIcon() + "] " + description; + } +} diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java new file mode 100644 index 0000000000..38788ba661 --- /dev/null +++ b/src/main/java/ToDo.java @@ -0,0 +1,11 @@ +public class ToDo extends Task { + + public ToDo(String description) { + super(description); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +}