diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 0000000000..0a0ef60ec3 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,11 @@ +public class Deadline extends Task { + public Deadline(String description, String deadline) { + super(description); + this.deadline=deadline; + } + + @Override + public String toString() { + return "[D]" + super.toString() + "(" + this.deadline + ")"; + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334cc..751425944a 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,10 +1,122 @@ +import java.util.Scanner; + + public class Duke { + public static int listCount = 0; + public static Task[] list = new Task[100]; + + public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} + //Generates a greeting + greet(); + request(); + } + + public static void bidGoodbye(){ + System.out.println("Bye. Hope to see you again soon!"); + } + + public static void printList(){ + int i; + for (i = 0; i < listCount; i++) { + System.out.println(listCount + "." + list[i]); + } + } + + public static void markDone(String word){ + int num = Integer.parseInt(word); + list[num - 1].isDone = true; + System.out.println("Nice! I've marked this task as done:"); + System.out.println("[✓] " + list[num - 1].description); + System.out.println("Now you have " + listCount + " tasks in the list"); + } + + public static void todo(String line){ + try { + list[listCount] = new ToDo(line); + System.out.println("Got it. I've added this task:"); + System.out.println(list[listCount]); + System.out.println("Now you have " + listCount + " tasks in the list"); + listCount++; + }catch(ArrayIndexOutOfBoundsException e){ + System.out.println("____________________________________________________________\n" + + "0x00002639 OOPS!!! The description of a todo cannot be empty."); + System.out.println("____________________________________________________________\n"); + } + } + + public static void Event(String line){ + try{ + int index = line.indexOf('/'); + list[listCount] = new Event(line.substring(0, index - 1), line.substring(index + 1)); + System.out.println("Got it. I've added this task:"); + System.out.println(list[listCount]); + System.out.println("Now you have " + listCount + " tasks in the list"); + listCount++; + }catch(ArrayIndexOutOfBoundsException e){ + System.out.println("____________________________________________________________\n" + + "☹ OOPS!!! The description of an event cannot be empty."); + System.out.println("____________________________________________________________\n"); + } + } + + public static void Deadline(String line){ + try { + int index = line.indexOf('/'); + list[listCount] = new Deadline(line.substring(0, index - 1), line.substring(index + 1)); + System.out.println("Got it. I've added this task:"); + System.out.println(list[listCount]); + System.out.println("Now you checkBoundsBeginEnd(have " + listCount + " tasks in the list"); + listCount++; + }catch(ArrayIndexOutOfBoundsException e){ + System.out.println("____________________________________________________________\n" + + "☹ OOPS!!! The description of a deadline cannot be empty."); + System.out.println("____________________________________________________________\n"); + } + } + + + public static void greet(){ + System.out.println("Hello! I'm Duke"); + System.out.println("What can I do for you?"); + } + + public static void request() { + Scanner in = new Scanner(System.in); + String line; + while (true) { + line = in.nextLine(); + String [] words = line.split(" "); + switch (words[0]) { + case "bye": + bidGoodbye(); + break; + case "list": + printList(); + break; + case "done": + markDone(line.substring(5)); + break; + case "todo": + todo(line.substring(5)); + break; + case "event": + Event(line.substring(6)); + break; + case "deadline": + Deadline(line.substring(9)); + break; + //case "delete": + + default: + System.out.println("Command not supported"); + break; + } + } + } + + + + + +} \ No newline at end of file diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 0000000000..5be2875002 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,11 @@ +public class Event extends Task { + public Event(String description, String deadline) { + super(description); + this.deadline=deadline; + } + + @Override + public String toString() { + return "[E]" + super.toString()+ "(" + this.deadline + ")"; + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 0000000000..eb7add96c7 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,23 @@ +public class Task { + protected String description; + protected boolean isDone; + protected String deadline; + protected int listCount; + + + public Task(String description) { + this.description = description; + this.isDone = false; + this.listCount = 0; + this.deadline = " none"; + } + public String statusicon(){ + return (this.isDone?"[✓]":"[✗]"); + } + @Override + public String toString(){ + return statusicon() + description; + } + + +} \ No newline at end of file diff --git a/src/main/java/ToDo.java b/src/main/java/ToDo.java new file mode 100644 index 0000000000..023c97b369 --- /dev/null +++ b/src/main/java/ToDo.java @@ -0,0 +1,10 @@ +public class ToDo extends Task{ + public ToDo(String description) { + super(description); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +}