diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index 5d313334c..93e160441 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,3 +1,5 @@ +import java.util.Scanner; + public class Duke { public static void main(String[] args) { String logo = " ____ _ \n" @@ -6,5 +8,129 @@ public static void main(String[] args) { + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); + System.out.println("Hello! I'm Duke"); + System.out.println("What can I do for you?"); + + Scanner scanner = new Scanner(System.in); + Task[] tasks = new Task[100]; + int taskCount = 0; + String input; + + while (true) { + input = scanner.nextLine(); + if (input.equals("bye")) { + System.out.println("Bye. Hope to see you again soon!"); + break; + } else if (input.equals("list")) { + System.out.println("Here are the tasks in your list:"); + for (int i = 0; i < taskCount; i++) { + System.out.println((i + 1) + "." + tasks[i]); + } + } else if (input.startsWith("mark ")) { + int taskIndex = Integer.parseInt(input.split(" ")[1]) - 1; + tasks[taskIndex].markAsDone(); + System.out.println("Nice! I've marked this task as done:"); + System.out.println(" " + tasks[taskIndex]); + } else if (input.startsWith("unmark ")) { + int taskIndex = Integer.parseInt(input.split(" ")[1]) - 1; + tasks[taskIndex].markAsNotDone(); + System.out.println("OK, I've marked this task as not done yet:"); + System.out.println(" " + tasks[taskIndex]); + } else if (input.startsWith("todo ")) { + String description = input.substring(5); + tasks[taskCount] = new ToDo(description); + taskCount++; + System.out.println("Got it. I've added this task:"); + System.out.println(" " + tasks[taskCount - 1]); + System.out.println("Now you have " + taskCount + " tasks in the list."); + } else if (input.startsWith("deadline ")) { + String[] parts = input.substring(9).split(" /by "); + tasks[taskCount] = new Deadline(parts[0], parts[1]); + taskCount++; + System.out.println("Got it. I've added this task:"); + System.out.println(" " + tasks[taskCount - 1]); + System.out.println("Now you have " + taskCount + " tasks in the list."); + } else if (input.startsWith("event ")) { + String[] parts = input.substring(6).split(" /from | /to "); + tasks[taskCount] = new Event(parts[0], parts[1], parts[2]); + taskCount++; + System.out.println("Got it. I've added this task:"); + System.out.println(" " + tasks[taskCount - 1]); + System.out.println("Now you have " + taskCount + " tasks in the list."); + } else { + System.out.println("I'm sorry, I don't understand that command."); + } + } + + scanner.close(); + } +} + +class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public void markAsDone() { + this.isDone = true; + } + + public void markAsNotDone() { + this.isDone = false; + } + + public String getStatusIcon() { + return (isDone ? "X" : " "); + } + + @Override + public String toString() { + return "[" + getStatusIcon() + "] " + description; + } +} + +class ToDo extends Task { + + public ToDo(String description) { + super(description); + } + + @Override + public String toString() { + return "[T]" + super.toString(); + } +} + +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: " + by + ")"; + } +} + +class Event extends Task { + protected String from; + protected String to; + + public Event(String description, String from, String to) { + super(description); + this.from = from; + this.to = to; + } + + @Override + public String toString() { + return "[E]" + super.toString() + " (from: " + from + " to: " + to + ")"; } }