diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334cc..0000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java new file mode 100644 index 0000000000..7f43369d16 --- /dev/null +++ b/src/main/java/duke/Duke.java @@ -0,0 +1,81 @@ +import java.util.ArrayList; +import java.util.Scanner; + +public class Duke { + public static void main(String[] args) { + String line; + ArrayList tasks = new ArrayList<>(); + Scanner sc = new Scanner(System.in); + printHorizontalLine(); + System.out.println(" Hello! I'm Duke"); + System.out.println(" What can I do for you?"); + printHorizontalLine(); + line = sc.nextLine(); + while (!line.equals("bye")) { + try { + if (line.equals("list")) { + printHorizontalLine(); + System.out.println(" Here are the tasks in your list:"); + for (int i = 0; i < tasks.size(); i++) { + System.out.println(" " + (i + 1) + ":" + tasks.get(i)); + } + printHorizontalLine(); + } else if (line.startsWith("done")) { + printHorizontalLine(); + int taskNumberCompleted = Integer.parseInt(line.replaceAll("\\D+", "")) - 1; + tasks.get(taskNumberCompleted).completeTask(); + System.out.println(" Nice! I've marked this task as done:"); + System.out.println(" " + ":" + tasks.get(taskNumberCompleted)); + printHorizontalLine(); + System.out.println(); + } else if (line.startsWith("todo")) { + printHorizontalLine(); + System.out.println(" Got it. I've added this task:"); + tasks.add(new ToDo(line)); + System.out.println(" " + new ToDo(line)); + System.out.println(" Now you have " + tasks.size() + " tasks in the list."); + printHorizontalLine(); + } else if (line.startsWith("deadline")) { + printHorizontalLine(); + System.out.println(" Got it. I've added this task:"); + tasks.add(new Deadline(line)); + System.out.println(" " + new Deadline(line)); + System.out.println(" Now you have " + tasks.size() + " tasks in the list."); + printHorizontalLine(); + } else if (line.startsWith("event")) { + printHorizontalLine(); + System.out.println(" Got it. I've added this task:"); + tasks.add(new Event(line)); + System.out.println(" " + new Event(line)); + System.out.println(" Now you have " + tasks.size() + " tasks in the list."); + printHorizontalLine(); + } else if (line.isEmpty()) { + printHorizontalLine(); + System.out.println(" ☹ OOPS!!! The description of a task cannot be empty."); + printHorizontalLine(); + } else { + printHorizontalLine(); + System.out.println(" ☹ OOPS!!! I'm sorry, but I don't know what that means :-("); + printHorizontalLine(); + System.out.println(); + } + } catch (StringIndexOutOfBoundsException e) { + printHorizontalLine(); + System.out.println("The task you input has missing fields!"); + printHorizontalLine(); + } catch (Exception e) { + printHorizontalLine(); + System.out.println("Something went wrong!"); + printHorizontalLine(); + } + line = sc.nextLine(); + } + printHorizontalLine(); + System.out.println(" Bye. Hope to see you again soon!"); + printHorizontalLine(); + } + + private static void printHorizontalLine() { + System.out.println(" ____________________________________________________________"); + } +} diff --git a/src/main/java/duke/tasks/Deadline.java b/src/main/java/duke/tasks/Deadline.java new file mode 100644 index 0000000000..d057d4ec9f --- /dev/null +++ b/src/main/java/duke/tasks/Deadline.java @@ -0,0 +1,23 @@ +package tasks; + +public class Deadline extends Task{ + protected String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + public String getBy() { + return by; + } + + public void setBy(String by) { + this.by = by; + } + + @Override + public String toString() { + return "[D]" + super.toString() + String.format(" (by: %s)",this.getBy()); + } +} diff --git a/src/main/java/duke/tasks/Event.java b/src/main/java/duke/tasks/Event.java new file mode 100644 index 0000000000..802ac48675 --- /dev/null +++ b/src/main/java/duke/tasks/Event.java @@ -0,0 +1,23 @@ +package tasks; + +public class Event extends Task{ + protected String period; + + public Event(String description, String period) { + super(description); + this.period = period; + } + + public String getPeriod() { + return period; + } + + public void setPeriod(String period) { + this.period = period; + } + + @Override + public String toString() { + return "[E]" + super.toString() + String.format(" (at: %s)",this.getPeriod()); + } +} diff --git a/src/main/java/duke/tasks/Task.java b/src/main/java/duke/tasks/Task.java new file mode 100644 index 0000000000..39435c8712 --- /dev/null +++ b/src/main/java/duke/tasks/Task.java @@ -0,0 +1,74 @@ +package tasks; + +import Commands; + +import java.util.ArrayList; + +public class Task { + protected String description; + protected boolean isDone; + protected static int numTotalTasks = 0; + + protected Task(String description) { + this.description = description; + this.isDone = false; + numTotalTasks++; + } + + public String getStatusIcon() { + return (isDone ? "\u2713" : "\u2718"); //return tick or X symbols + } + + public void setDone() { + isDone = true; + } + + public String getDescription() { + return description; + } + + public static int getNumTotalTasks() { + return numTotalTasks; + } + + @Override + public String toString(){ + return "[" + this.getStatusIcon() + "]" + this.getDescription(); + } + + public static boolean parseTask(String taskInString, ArrayList tasks) { + char type = taskInString.charAt(1); + char status = taskInString.charAt(4); + taskInString = taskInString.substring(6); + Task buffer; + String[] splitCommands; + String description; + String time; + + switch (type) { + case 'T': + buffer = new Todo(taskInString); + break; + case 'E': + splitCommands = taskInString.split("\\(at: "); + description = splitCommands[0].strip(); + time = splitCommands[1].substring(0, splitCommands[1].length()-1).strip(); + buffer = new Event(description, time); + break; + case 'D': + splitCommands = taskInString.split("\\(by: "); + description = splitCommands[0].strip(); + time = splitCommands[1].substring(0, splitCommands[1].length()-1).strip(); + buffer = new Deadline(splitCommands[0], splitCommands[1]); + break; + default: + System.out.println("Error: Wrong input file syntax."); + return false; + } + if (status == '\u2713') { + buffer.setDone(); + } + tasks.add(buffer); + return true; + } +} \ No newline at end of file diff --git a/src/main/java/duke/tasks/Todo.java b/src/main/java/duke/tasks/Todo.java new file mode 100644 index 0000000000..f1c09ce94b --- /dev/null +++ b/src/main/java/duke/tasks/Todo.java @@ -0,0 +1,12 @@ +package tasks; + +public class Todo extends Task { + public Todo(String description) { + super(description); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +}