Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hyojin Jung] ip #283

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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).<br>
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
____ _
Expand Down
61 changes: 45 additions & 16 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -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` | <task description> | Adds a todo task to the list. |
| `deadline` | <task description> /by <due date> | Adds a deadline task to the list. |
| `event` | <task description> /from <start> /to <end> | Adds an event task to the list. |
| `delete` | <index> | Deletes the task at the specified index. |
| `find` | <keyword> | 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
2 changes: 2 additions & 0 deletions src/main/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Manifest-Version: 1.0
Main-Class: Hailey
14 changes: 14 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -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 + ")";
}
}

10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

5 changes: 5 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class DukeException extends Exception {
public DukeException(String message) {
super(message);
}
}
15 changes: 15 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -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 + ")";
}
}
92 changes: 92 additions & 0 deletions src/main/java/Hailey.java
Original file line number Diff line number Diff line change
@@ -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 <description> /by <due date>");
} 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 <description> /from <start time> /to <end time>");
} 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 <description> /from <start time> /to <end time>");
} 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();
}
}
3 changes: 3 additions & 0 deletions src/main/java/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: Hailey

5 changes: 5 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Parser {
public static Command parse(String fullCommand) throws DukeException {
// Your parsing logic here
}
}
60 changes: 60 additions & 0 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
@@ -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<Task> load() throws DukeException {
List<Task> 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<Task> 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());
}
}
}
23 changes: 23 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -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();
}
Loading