diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 0000000000..34b3433ef1 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,13 @@ +public class Deadline extends Task { + protected String by; + + public Deadline(String desc, String by) { + super(desc); + this.by = by; + } + + @Override + public String toString(){ + return "[D]" + super.getTask() + " (by: " + by + ")"; + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 594315ae8f..c4d6f1cce4 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -14,6 +14,8 @@ public static void main(String[] args) { System.out.println(startMessage); Scanner sc = new Scanner(System.in); ArrayList list = new ArrayList(); + String taskName; + Task task; while(sc.hasNext()){ String userCmd = sc.next(); if(userCmd.equals("bye")){ @@ -29,10 +31,28 @@ public static void main(String[] args) { System.out.print(lineSpace); break; case "todo": - String taskName = sc.nextLine(); + taskName = sc.nextLine(); taskName = taskName.trim(); - list.add(new Task(taskName)); - System.out.println(lineSpace + "added: " + taskName + "\n" + lineSpace); + task = new Task(taskName); + list.add(task); + System.out.println(lineSpace + "Got it. I've added this task:\n" + task + + "\nNow you have " + list.size() + " tasks in the list.\n" + lineSpace); + break; + case "deadline": + taskName = sc.nextLine(); + String[] userWords = taskName.trim().split("/by"); + task = new Deadline(userWords[0].trim(), userWords[1].trim()); + list.add(task); + System.out.println(lineSpace + "Got it. I've added this task:\n" + task + + "\nNow you have " + list.size() + " tasks in the list.\n" + lineSpace); + break; + case "event": + taskName = sc.nextLine(); + userWords = taskName.trim().split("/at"); + task = new Event(userWords[0].trim(), userWords[1].trim()); + list.add(task); + System.out.println(lineSpace + "Got it. I've added this task:\n" + task + + "\nNow you have " + list.size() + " tasks in the list.\n" + lineSpace); break; case "done": int taskNo = sc.nextInt(); diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 0000000000..35f38bc5cc --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,14 @@ +public class Event extends Task { + + protected String at; + + public Event(String desc, String at) { + super(desc); + this.at = at; + } + + @Override + public String toString(){ + return "[E]" + super.getTask() + " (at: " + at + ")"; + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 4d4b4e53f1..b96e7d5caa 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -22,6 +22,6 @@ public String getTask(){ @Override public String toString(){ - return getTask(); + return "[T]" + getTask(); } }