From 579fe7bc93b99d4c52145d8d7a23b42bd5f5ea44 Mon Sep 17 00:00:00 2001 From: gx-huang Date: Tue, 21 Jan 2020 21:41:21 +0800 Subject: [PATCH] Level-4: ToDo, Event, Deadline --- src/main/java/Deadlines.java | 14 ++++++++++++++ src/main/java/Duke.java | 31 +++++++++++++++++++++---------- src/main/java/Events.java | 14 ++++++++++++++ src/main/java/Task.java | 1 + src/main/java/ToDos.java | 12 ++++++++++++ src/main/java/UserText.java | 5 +++-- 6 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 src/main/java/Deadlines.java create mode 100644 src/main/java/Events.java create mode 100644 src/main/java/ToDos.java diff --git a/src/main/java/Deadlines.java b/src/main/java/Deadlines.java new file mode 100644 index 0000000000..6762401f65 --- /dev/null +++ b/src/main/java/Deadlines.java @@ -0,0 +1,14 @@ +public class Deadlines extends Task{ + protected String by; + + public Deadlines(String description, String by) { + super(description); + this.by = by; + System.out.println(this); + } + + @Override + public String toString() { + return "[D]" + super.toString() + "(by:" + by + ")"; + } +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index c594ea8dee..eb42d42532 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -18,21 +18,32 @@ public static void main(String[] args) { while(isListening) { String command = input.nextLine(); + String[] command_broken = command.split(" ",2); - if (command.equalsIgnoreCase("bye")) { - System.out.println("Bye. Hope to see you again soon!"); + String action = command_broken[0]; + + if (action.equalsIgnoreCase("bye")) { + System.out.println("Bye. Hope to see you again!"); isListening = false; - } else if (command.equalsIgnoreCase("list")) { + + } else if (action.equalsIgnoreCase("list")) { tasks.printInputs(); - } else if (command.length()>3 - && command.substring(0,4).equalsIgnoreCase("done")) { - String s[] = command.split(" "); - int taskNo = Integer.parseInt(s[1]); + + } else if (action.equalsIgnoreCase("done")) { + String context = command_broken[1]; + int taskNo = Integer.parseInt(context); tasks.markDone(taskNo); - } else { - System.out.println(command); - tasks.addInput(new Task(command)); + } else if (action.equalsIgnoreCase(("deadline"))){ + String context = command_broken[1]; + String[] context_broken = context.split("/by",2); + tasks.addInput(new Deadlines(context_broken[0], context_broken[1])); + } else if (action.equalsIgnoreCase(("todo"))){ + tasks.addInput(new ToDos(command_broken[1])); + } else if (action.equalsIgnoreCase(("event"))){ + String context = command_broken[1]; + String[] context_broken = context.split("/at",2); + tasks.addInput(new Events(context_broken[0], context_broken[1])); } } } diff --git a/src/main/java/Events.java b/src/main/java/Events.java new file mode 100644 index 0000000000..ec0be60884 --- /dev/null +++ b/src/main/java/Events.java @@ -0,0 +1,14 @@ +public class Events extends Task{ + protected String by; + + public Events(String description, String by) { + super(description); + this.by = by; + System.out.println(this); + } + + @Override + public String toString() { + return "[E]" + super.toString() + "(at:" + by + ")"; + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java index 938a9a448f..c6d8652b1f 100644 --- a/src/main/java/Task.java +++ b/src/main/java/Task.java @@ -3,6 +3,7 @@ public class Task { protected boolean isDone; public Task(String description) { + System.out.println("Got it, I've added this task"); this.description = description; this.isDone = false; } diff --git a/src/main/java/ToDos.java b/src/main/java/ToDos.java new file mode 100644 index 0000000000..7f4d8d3730 --- /dev/null +++ b/src/main/java/ToDos.java @@ -0,0 +1,12 @@ +public class ToDos extends Task { + + public ToDos(String description) { + super(description); + System.out.println(this); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +} diff --git a/src/main/java/UserText.java b/src/main/java/UserText.java index c2a0301b2b..9b457c6f7c 100644 --- a/src/main/java/UserText.java +++ b/src/main/java/UserText.java @@ -8,13 +8,14 @@ public UserText() { userInput = new ArrayList<>(); } - public List addInput(Task s) { + public void addInput(Task s) { this.userInput.add(s); - return this.userInput; + System.out.println("Now you have " + userInput.size() + " tasks in the list."); } public void printInputs() { int count = 1; + System.out.println("Here is your list"); for (Task s : userInput) { System.out.println(count + ". " + s); count++;