diff --git a/README.md b/README.md index 8715d4d91..b299c9619 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Duke project template +# Hailey project template This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. @@ -13,7 +13,7 @@ Prerequisites: JDK 11, update Intellij to the most recent version. 1. If there are any further prompts, accept the defaults. 1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).
In the same dialog, set the **Project language level** field to the `SDK default` option. -3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: +3. After that, locate the `src/main/java/Hailey.java` file, right-click it, and choose `Run Hailey.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: ``` Hello from ____ _ diff --git a/docs/README.md b/docs/README.md index 8077118eb..5d31c5723 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,29 +1,58 @@ -# User Guide +# Hailey User Guide -## Features +Hailey is a command-line chatbot application designed to help you manage your tasks efficiently. -### Feature-ABC +## Getting Started -Description of the feature. +1. Make sure you have Java installed on your computer. +2. Clone or download the Hailey repository to your local machine. +3. Open a terminal in the directory where you saved the Hailey files. +4. Compile the Java files using the following command: + ``` + javac *.java + ``` +5. Run the application using the following command: + ``` + java Hailey + ``` -### Feature-XYZ +## Quick Reference -Description of the feature. +| Command | Parameters | Explanation | +|------------|------------------------------------|----------------------------------------| +| `list` | None | Displays the list of tasks. | +| `todo` | | Adds a todo task to the list. | +| `deadline` | /by | Adds a deadline task to the list. | +| `event` | /from /to | Adds an event task to the list. | +| `delete` | | Deletes the task at the specified index. | +| `find` | | Searches for tasks containing the specified keyword. | +| `bye` | None | Exits the application. | -## Usage +## Features + +### Add Tasks + +Hailey allows you to add different types of tasks: +- Todo tasks +- Deadline tasks +- Event tasks + +### List Tasks -### `Keyword` - Describe action +You can view all your tasks by typing `list`. Hailey will display the tasks along with their descriptions and statuses. -Describe the action and its outcome. +### Delete Tasks -Example of usage: +To remove a task from your list, use the `delete` command followed by the index of the task you wish to delete. -`keyword (optional arguments)` +### Find Tasks -Expected outcome: +If you need to find a specific task, use the `find` command followed by a keyword. Hailey will display all tasks containing the keyword. -Description of the outcome. +### Exiting Hailey + +To exit Hailey, simply type `bye`. Hailey will bid you farewell and close the application. + +## Usage -``` -expected output -``` +### Adding a Todo Task \ No newline at end of file diff --git a/src/main/MANIFEST.MF b/src/main/MANIFEST.MF new file mode 100644 index 000000000..d9670b91e --- /dev/null +++ b/src/main/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 +Main-Class: Hailey diff --git a/src/main/java/Deadline.java b/src/main/java/Deadline.java new file mode 100644 index 000000000..56c1f1627 --- /dev/null +++ b/src/main/java/Deadline.java @@ -0,0 +1,14 @@ +public class Deadline extends Task { + private String by; + + public Deadline(String description, String by) { + super(description); + this.by = by; + } + + @Override + public String toString() { + return "[D][" + getStatusIcon() + "] " + description + " (by: " + by + ")"; + } +} + diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334c..000000000 --- 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/DukeException.java b/src/main/java/DukeException.java new file mode 100644 index 000000000..d2789a1f8 --- /dev/null +++ b/src/main/java/DukeException.java @@ -0,0 +1,5 @@ +public class DukeException extends Exception { + public DukeException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/main/java/Event.java b/src/main/java/Event.java new file mode 100644 index 000000000..dbe8f8467 --- /dev/null +++ b/src/main/java/Event.java @@ -0,0 +1,15 @@ +public class Event extends Task { + private String from; + private String to; + + public Event(String description, String from, String to) { + super(description); + this.from = from; + this.to = to; + } + + @Override + public String toString() { + return "[E][" + getStatusIcon() + "] " + description + " (from: " + from + " to: " + to + ")"; + } +} diff --git a/src/main/java/Hailey.java b/src/main/java/Hailey.java new file mode 100644 index 000000000..4b0ef744b --- /dev/null +++ b/src/main/java/Hailey.java @@ -0,0 +1,92 @@ +import java.util.Scanner; + +public class Hailey { + private TaskManager taskManager; + + public Hailey() { + this.taskManager = new TaskManager("./data/tasks.txt"); + } + + public void run() { + Scanner scanner = new Scanner(System.in); + + printWelcomeMessage(); + + while (true) { + String userInput = scanner.nextLine().trim(); + printLine(); + + if (userInput.equalsIgnoreCase("bye")) { + printGoodbyeMessage(); + break; + } else if (userInput.equalsIgnoreCase("list")) { + taskManager.printTasks(); + } else if (userInput.startsWith("todo")) { + taskManager.addTodoTask(userInput.substring("todo".length()).trim()); + } else if (userInput.startsWith("deadline")) { + // Parse deadline command and add deadline task + String[] parts = userInput.split("/by", 2); + if (parts.length != 2) { + printErrorMessage("Invalid deadline format. Please use: deadline /by "); + } else { + String description = parts[0].substring("deadline".length()).trim(); + String by = parts[1].trim(); + taskManager.addDeadlineTask(description, by); + } + } else if (userInput.startsWith("event")) { + // Parse event command and add event task + String[] parts = userInput.split("/from", 2); + if (parts.length != 2) { + printErrorMessage("Invalid event format. Please use: event /from /to "); + } else { + String description = parts[0].substring("event".length()).trim(); + String[] timeParts = parts[1].split("/to", 2); + if (timeParts.length != 2) { + printErrorMessage("Invalid event format. Please use: event /from /to "); + } else { + String from = timeParts[0].trim(); + String to = timeParts[1].trim(); + taskManager.addEventTask(description, from, to); + } + } + } else if (userInput.startsWith("delete")) { + // Parse delete command and delete task + String indexStr = userInput.substring("delete".length()).trim(); + try { + int index = Integer.parseInt(indexStr); + taskManager.deleteTask(index - 1); // Adjust index to 0-based + } catch (NumberFormatException e) { + printErrorMessage("Invalid index for delete command. Please enter a valid task number."); + } + } else { + printErrorMessage("I'm sorry, but I don't know what that means :-("); + } + } + + scanner.close(); + } + + private void printWelcomeMessage() { + System.out.println("Hello! I'm Hailey"); + System.out.println("What can I do for you?"); + printLine(); + } + + private void printLine() { + System.out.println("____________________________________________________________"); + } + + private void printGoodbyeMessage() { + System.out.println("Bye. Hope to see you again soon!"); + printLine(); + } + + private void printErrorMessage(String message) { + System.out.println("OOPS!!! " + message); + printLine(); + } + + public static void main(String[] args) { + new Hailey().run(); + } +} \ No newline at end of file diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 000000000..80f38673f --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Hailey + diff --git a/src/main/java/Parser.java b/src/main/java/Parser.java new file mode 100644 index 000000000..2cca951e8 --- /dev/null +++ b/src/main/java/Parser.java @@ -0,0 +1,5 @@ +public class Parser { + public static Command parse(String fullCommand) throws DukeException { + // Your parsing logic here + } +} diff --git a/src/main/java/Storage.java b/src/main/java/Storage.java new file mode 100644 index 000000000..cfd8f09ce --- /dev/null +++ b/src/main/java/Storage.java @@ -0,0 +1,60 @@ +import java.io.*; +import java.util.ArrayList; +import java.util.List; + +public class Storage { + private final String filePath; + + public Storage(String filePath) { + this.filePath = filePath; + } + + public List load() throws DukeException { + List tasks = new ArrayList<>(); + try { + File file = new File(filePath); + if (!file.exists()) { + return tasks; + } + + BufferedReader reader = new BufferedReader(new FileReader(file)); + String line; + while ((line = reader.readLine()) != null) { + String[] parts = line.split(" \\| "); + String type = parts[0]; + boolean isDone = parts[1].equals("1"); + String description = parts[2]; + switch (type) { + case "T": + tasks.add(new TodoTask(description, isDone)); + break; + case "D": + String by = parts[3]; + tasks.add(new DeadlineTask(description, by, isDone)); + break; + case "E": + String from = parts[3]; + String to = parts[4]; + tasks.add(new EventTask(description, from, to, isDone)); + break; + } + } + reader.close(); + } catch (IOException e) { + throw new DukeException("Error loading tasks: " + e.getMessage()); + } + return tasks; + } + + public void save(List tasks) throws DukeException { + try { + PrintWriter writer = new PrintWriter(filePath); + for (Task task : tasks) { + writer.println(task.toFileString()); + } + writer.close(); + } catch (FileNotFoundException e) { + throw new DukeException("Error saving tasks: " + e.getMessage()); + } + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..2c945f693 --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,23 @@ +public abstract class Task { + protected String description; + protected boolean isDone; + + public Task(String description) { + this.description = description; + this.isDone = false; + } + + public void markAsDone() { + isDone = true; + } + + public String getDescription() { + return description; + } + + public String getStatusIcon() { + return (isDone ? "X" : " "); + } + + public abstract String toString(); +} \ No newline at end of file diff --git a/src/main/java/TaskManager.java b/src/main/java/TaskManager.java new file mode 100644 index 000000000..9f3d76ca1 --- /dev/null +++ b/src/main/java/TaskManager.java @@ -0,0 +1,89 @@ +import java.util.ArrayList; +import java.util.List; +import java.io.*; + +public class TaskManager { + private final List tasks; + private final String filePath; + + public TaskManager(String filePath) { + this.filePath = filePath; + tasks = new ArrayList<>(); + loadTasks(); + } + + public void addTodoTask(String description) { + tasks.add(new TodoTask(description)); + saveTasksToFile(); + } + + public void addDeadlineTask(String description, String by) { + tasks.add(new DeadlineTask(description, by)); + saveTasksToFile(); + } + + public void addEventTask(String description, String from, String to) { + tasks.add(new EventTask(description, from, to)); + saveTasksToFile(); + } + + public void deleteTask(int index) { + if (index >= 0 && index < tasks.size()) { + tasks.remove(index); + saveTasksToFile(); + } + } + + public void printTasks() { + for (int i = 0; i < tasks.size(); i++) { + System.out.println((i + 1) + ". " + tasks.get(i)); + } + } + + private void loadTasks() { + try { + File file = new File(filePath); + if (!file.exists()) { + return; + } + + BufferedReader reader = new BufferedReader(new FileReader(file)); + String line; + while ((line = reader.readLine()) != null) { + String[] parts = line.split(" \\| "); + String type = parts[0]; + boolean isDone = parts[1].equals("1"); + String description = parts[2]; + switch (type) { + case "T": + tasks.add(new TodoTask(description, isDone)); + break; + case "D": + String by = parts[3]; + tasks.add(new DeadlineTask(description, by, isDone)); + break; + case "E": + String from = parts[3]; + String to = parts[4]; + tasks.add(new EventTask(description, from, to, isDone)); + break; + } + } + reader.close(); + } catch (IOException e) { + System.out.println("Error loading tasks: " + e.getMessage()); + } + } + + private void saveTasksToFile() { + try { + PrintWriter writer = new PrintWriter(filePath); + for (Task task : tasks) { + writer.println(task.toFileString()); + } + writer.close(); + } catch (FileNotFoundException e) { + System.out.println("Error saving tasks: " + e.getMessage()); + } + } +} diff --git a/src/main/java/Todo.java b/src/main/java/Todo.java new file mode 100644 index 000000000..abb0a4dd7 --- /dev/null +++ b/src/main/java/Todo.java @@ -0,0 +1,10 @@ +public class Todo extends Task { + public Todo(String description) { + super(description); + } + + @Override + public String toString() { + return "[T][" + getStatusIcon() + "] " + description; + } +} \ No newline at end of file diff --git a/src/main/java/Ui.java b/src/main/java/Ui.java new file mode 100644 index 000000000..5d1d3fd0f --- /dev/null +++ b/src/main/java/Ui.java @@ -0,0 +1,24 @@ +public class Ui { + public void showWelcome() { + System.out.println("Hello! I'm Hailey"); + System.out.println("What can I do for you?"); + printLine(); + } + + public void showLine() { + System.out.println("____________________________________________________________"); + } + + public void showError(String message) { + System.out.println("OOPS!!! " + message); + printLine(); + } + + public void showLoadingError() { + System.out.println("Error loading tasks. Starting with an empty task list."); + } + + private void printLine() { + System.out.println("____________________________________________________________"); + } +} \ No newline at end of file diff --git a/text-ui-test/runtest.bat b/text-ui-test/runtest.bat index 087374464..b8a99cad4 100644 --- a/text-ui-test/runtest.bat +++ b/text-ui-test/runtest.bat @@ -15,7 +15,7 @@ IF ERRORLEVEL 1 ( 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 Hailey < input.txt > ACTUAL.TXT REM compare the output to the expected output FC ACTUAL.TXT EXPECTED.TXT