diff --git a/src/main/java/BigBoy.java b/src/main/java/BigBoy.java new file mode 100644 index 000000000..2ea9de81e --- /dev/null +++ b/src/main/java/BigBoy.java @@ -0,0 +1,10 @@ +public class BigBoy { + 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/Clarawr.java b/src/main/java/Clarawr.java new file mode 100644 index 000000000..7678705f5 --- /dev/null +++ b/src/main/java/Clarawr.java @@ -0,0 +1,97 @@ +import java.util.Scanner; +import java.util.ArrayList; + +public class Clarawr { + static ArrayList tasks = new ArrayList<>(); + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.println("Hello! I'm Clarawr\n" + + "What can I do for you?"); + + String instruction = scanner.nextLine(); + + while (!instruction.equalsIgnoreCase("bye")) { + try { + if (instruction.equalsIgnoreCase("list")) { + if (tasks.isEmpty()) { + System.out.println("No tasks in your list."); + } else { + 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)); + } + } + } else if (instruction.startsWith("todo")) { + String description = instruction.substring(4).trim(); + if (description.isEmpty()) { + throw new ClarawrException("The description of a todo task cannot be empty."); + } + tasks.add(new Todo(description)); + System.out.println("Got it, I've added this task: "); + System.out.println(" " + tasks.get(tasks.size() - 1)); + System.out.println("Now you have " + tasks.size() + " tasks in the list."); + } else if (instruction.startsWith("deadline")) { + String[] parts = instruction.substring(8).split(" /by "); + if (parts.length < 2 || parts[0].isEmpty() || parts[1].isEmpty()) { + throw new ClarawrException("The description and deadline of a task cannot be empty."); + } + tasks.add(new Deadline(parts[0], parts[1])); + System.out.println("Got it, I've added this task: "); + System.out.println(" " + tasks.get(tasks.size() - 1)); + System.out.println("Now you have " + tasks.size() + " tasks in the list."); + } else if (instruction.startsWith("event")) { + String[] parts = instruction.substring(5).split(" /from "); + if (parts.length < 2) { + throw new ClarawrException("The description and timing of an event cannot be empty."); + } + String[] times = parts[1].split(" /to "); + if (times.length < 2 || parts[0].isEmpty() || times[0].isEmpty() || times[1].isEmpty()) { + throw new ClarawrException("The description and both event times cannot be empty."); + } + tasks.add(new Event(parts[0], times[0], times[1])); + System.out.println("Got it, I've added this task: "); + System.out.println(" " + tasks.get(tasks.size() - 1)); + System.out.println("Now you have " + tasks.size() + " tasks in the list."); + } else if (instruction.startsWith("mark ")) { + int index = Integer.parseInt(instruction.split(" ")[1]) - 1; + if (index >= 0 && index < tasks.size()) { + tasks.get(index).markAsDone(); + System.out.println("Nice! I've marked this task as done:"); + System.out.println(" " + tasks.get(index)); + } else { + System.out.println("Invalid task number! Please try again."); + } + } else if (instruction.startsWith("unmark ")) { + int index = Integer.parseInt(instruction.split(" ")[1]) - 1; + if (index >= 0 && index < tasks.size()) { + tasks.get(index).markUndone(); + System.out.println("OK, I've marked this task as not done yet:"); + System.out.println(" " + tasks.get(index)); + } else { + System.out.println("Invalid task number! Please try again."); + } + } else if (instruction.startsWith("delete ") || instruction.startsWith("remove ")) { + int index = Integer.parseInt(instruction.split(" ")[1]) - 1; + if (index >= 0 && index < tasks.size()) { + Task taskToDelete = tasks.remove(index); + System.out.println("Noted. I've removed this task: "); + System.out.println(" " + taskToDelete); + System.out.println("Now you have " + tasks.size() + " tasks in the list."); + } else { + System.out.println("Invalid task number! Please try again."); + } + } else { + System.out.println("Sorry I do not understand your instruction :("); + } + } catch (ClarawrException e) { + System.out.println(e.getMessage()); + } + instruction = scanner.nextLine(); + } + + System.out.println("Bye. Hope to see you again soon!"); + scanner.close(); + } +} diff --git a/src/main/java/ClarawrException.java b/src/main/java/ClarawrException.java new file mode 100644 index 000000000..0a94b1bcd --- /dev/null +++ b/src/main/java/ClarawrException.java @@ -0,0 +1,6 @@ +public class ClarawrException extends Exception { + + public ClarawrException(String message) { + super(message); + } +} diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..1840c63be --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,14 @@ +public 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 + ")"; + } +} diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..6c6656d87 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,16 @@ +public 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 + ")"; + } +} diff --git a/src/main/java/Level_1/Clarawr.java b/src/main/java/Level_1/Clarawr.java new file mode 100644 index 000000000..846b3da4c --- /dev/null +++ b/src/main/java/Level_1/Clarawr.java @@ -0,0 +1,20 @@ +package Level_1; +import java.util.Scanner; + +public class Clarawr { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("Hello! I'm Clarawr\n" + + "What can I do for you?"); + + String instruction = scanner.nextLine(); + + while (!instruction.equalsIgnoreCase("bye")) { // Check for "bye" (case-insensitive) + System.out.println(instruction); // Repeat the input + instruction = scanner.nextLine(); // Read the next input + } + + System.out.println("Bye. Hope to see you again soon!"); + scanner.close(); // Close the scanner + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..6efaf3ab8 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,25 @@ +public class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public String getStatusIcon() { + return (isDone ? "X" : " "); // mark done task with X + } + + public void markAsDone() { + this.isDone = true; + } + + public void markUndone() { + this.isDone = false; + } + + public String toString() { + return "[" + getStatusIcon() + "] " + description; + } +} diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..6ab1af9d9 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,11 @@ +public class Todo extends Task { + + public Todo (String description) { + super(description); + } + + @Override + public String toString() { + return " [T]" + super.toString(); + } +} diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 657e74f6e..cdccccbf8 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,7 +1,50 @@ -Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| - +Hello! I'm Clarawr +What can I do for you? +Got it, I've added this task: + [T][ ] revise CS2106 +Now you have 1 tasks in the list. +Got it, I've added this task: + [D][ ] CS2103 (by: Fri 4pm) +Now you have 2 tasks in the list. +Got it, I've added this task: + [E][ ] internship interview (from: Mon 4pm to: Mon 5pm) +Now you have 3 tasks in the list. +Here are the tasks in your list: +1. [T][ ] revise CS2106 +2. [D][ ] CS2103 (by: Fri 4pm) +3. [E][ ] internship interview (from: Mon 4pm to: Mon 5pm) +Got it, I've added this task: + [T][ ] dinner with parents +Now you have 4 tasks in the list. +Here are the tasks in your list: +1. [T][ ] revise CS2106 +2. [D][ ] CS2103 (by: Fri 4pm) +3. [E][ ] internship interview (from: Mon 4pm to: Mon 5pm) +4. [T][ ] dinner with parents +Nice! I've marked this task as done: + [T][X] dinner with parents +Nice! I've marked this task as done: + [E][X] internship interview (from: Mon 4pm to: Mon 5pm) +Here are the tasks in your list: +1. [T][ ] revise CS2106 +2. [D][ ] CS2103 (by: Fri 4pm) +3. [E][X] internship interview (from: Mon 4pm to: Mon 5pm) +4. [T][X] dinner with parents +Invalid task number! Please try again. +Nice! I've marked this task as done: + [T][X] revise CS2106 +Nice! I've marked this task as done: + [D][X] CS2103 (by: Fri 4pm) +Here are the tasks in your list: +1. [T][X] revise CS2106 +2. [D][X] CS2103 (by: Fri 4pm) +3. [E][X] internship interview (from: Mon 4pm to: Mon 5pm) +4. [T][X] dinner with parents +OK, I've marked this task as not done yet: + [D][ ] CS2103 (by: Fri 4pm) +Here are the tasks in your list: +1. [T][X] revise CS2106 +2. [D][ ] CS2103 (by: Fri 4pm) +3. [E][X] internship interview (from: Mon 4pm to: Mon 5pm) +4. [T][X] dinner with parents +Bye. Hope to see you again soon! diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index e69de29bb..1ea858eb8 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -0,0 +1,16 @@ +todo revise CS2106 +deadline CS2103 /by Fri 4pm +event internship interview /from Mon 4pm /to Mon 5pm +list +todo dinner with parents +list +mark 4 +mark 3 +list +mark 5 +mark 1 +mark 2 +list +unmark 2 +list +bye diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 087374464..37e7b526a 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -4,18 +4,26 @@ REM create bin directory if it doesn't exist if not exist ..\bin mkdir ..\bin REM delete output from previous run -if exist ACTUAL.TXT del ACTUAL.TXT + REM compile the code into the bin folder javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\*.java IF ERRORLEVEL 1 ( echo ********** BUILD FAILURE ********** exit /b 1 +) ELSE ( + echo Build OK! ) -REM no error here, errorlevel == 0 REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT -java -classpath ..\bin Duke < input.txt > ACTUAL.TXT +java -classpath ..\bin Clarawr < input.txt > ACTUAL.TXT + +REM compare the output to the expected output, ignoring white space differences +FC /L /W ACTUAL.TXT EXPECTED.TXT -REM compare the output to the expected output -FC ACTUAL.TXT EXPECTED.TXT +REM Check if FC found a difference +IF ERRORLEVEL 1 ( + echo Something is wrong! Files do not match. +) ELSE ( + echo Yes! All the files are the same. Test passed! :D +)