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

[TrungBui32] iP #112

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
T | 0 | sleep
E | 0 | go to school | monday | tuesday
109 changes: 96 additions & 13 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,113 @@
# Duke User Guide

// Update the title above to match the actual product name
# Poirot User Guide

// Product screenshot goes here
Poirot is a powerful command-line task management application designed to help you organize your to-dos, deadlines, and events efficiently.

// Product intro goes here
## Adding a To-Do

Add tasks without any specific deadline or time, allowing you to track general tasks.

Example: `todo Buy groceries`

This command adds a new to-do task to your list.

```
____________________________________________________________
Got it. I've added this task:
[T][ ] Buy groceries
Now you have 1 tasks in the list.
____________________________________________________________
```

## Adding deadlines

// Describe the action and its outcome.
Add tasks with specific due dates and times to keep track of important deadlines.

Example: `deadline Submit report /by 2023-12-31 2359`

This command adds a new deadline task to your list.

```
____________________________________________________________
Got it. I've added this task:
[D][ ] Submit report (by: Dec 31 2023, 11:59 PM)
Now you have 1 tasks in the list.
____________________________________________________________
```

## Adding events

Create events with start and end times to manage your schedule effectively.

Example: `event Team meeting /from 2023-11-15 1400 /to 2023-11-15 1500`

This command adds a new event to your task list.

```
____________________________________________________________
Got it. I've added this task:
[E][ ] Team meeting (from: Nov 15 2023, 02:00 PM to: Nov 15 2023, 03:00 PM)
Now you have 2 tasks in the list.
____________________________________________________________
```

## Listing tasks

// Give examples of usage
View all your current tasks in one place.

Example: `keyword (optional arguments)`
Example: `list`

// A description of the expected outcome goes here
This command displays all tasks currently in your list.

```
expected output
____________________________________________________________
1.[D][ ] Submit report (by: Dec 31 2023, 11:59 PM)
2.[E][ ] Team meeting (from: Nov 15 2023, 02:00 PM to: Nov 15 2023, 03:00 PM)
____________________________________________________________
```

## Feature ABC
## Marking tasks as done

// Feature details
Keep track of your progress by marking completed tasks.

Example: `mark 1`

## Feature XYZ
This command marks the first task in your list as done.

```
____________________________________________________________
Nice! I've marked this task as done:

[X] Submit report
____________________________________________________________
```

## Finding tasks

Quickly locate tasks related to specific keywords.

Example: `find report`

This command searches for tasks containing the word "report".

```
Here are the matching tasks in your list:
1. [D][X] Submit report (by: Dec 31 2023, 11:59 PM)
```

## Deleting tasks

Remove tasks that are no longer needed.

Example: `delete 2`

This command deletes the second task in your list.

```
____________________________________________________________
Noted. I've removed this task:
[E][ ] Team meeting (from: Nov 15 2023, 02:00 PM to: Nov 15 2023, 03:00 PM)
Now you have 1 tasks in the list.
____________________________________________________________
```

// Feature details
Binary file added src/main/java/AddDeadlineCommand.class
Binary file not shown.
43 changes: 43 additions & 0 deletions src/main/java/AddDeadlineCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

/**
* Command to add a deadline task.
*/
public class AddDeadlineCommand extends Command {
private String description;
private String by;
private static final DateTimeFormatter INPUT_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm");

/**
* Constructs an AddDeadlineCommand with the specified input.
*
* @param input The user input containing the task description and deadline.
*/
public AddDeadlineCommand(String input) {
String[] parts = input.split("/by");
this.description = parts[0].trim().substring(9).trim();
this.by = parts[1].trim();
}

/**
* Executes the command to add the deadline task to the task list.
*
* @param tasks The task list to which the task will be added.
* @param ui The user interface for displaying messages to the user.
* @param storage The storage for saving tasks to a file.
*/
@Override
public void execute(TaskList tasks, Ui ui, Storage storage) {
try {
LocalDateTime.parse(by, INPUT_FORMAT); // Validate the date format
Task newTask = new Deadline(description, by);
tasks.add(newTask);
ui.showAddedTask(newTask, tasks.getTaskCount());
storage.saveTasksToFile(tasks.getTasks(), tasks.getTaskCount());
} catch (DateTimeParseException e) {
ui.showError("Invalid date format. Please use yyyy-MM-dd HHmm format.");
}
}
}
Binary file added src/main/java/AddEventCommand.class
Binary file not shown.
39 changes: 39 additions & 0 deletions src/main/java/AddEventCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Represents a command to add a new event to the task list.
* This command creates a new Event task with a description, start time, and end time.
*/
public class AddEventCommand extends Command {
private String description;
private String from;
private String to;

/**
* Constructs a new AddEventCommand with the specified event details.
*
* @param description The description of the event.
* @param from The start time/date of the event.
* @param to The end time/date of the event.
*/
public AddEventCommand(String description, String from, String to) {
this.description = description;
this.from = from;
this.to = to;
}

/**
* Executes the command to add a new event to the task list.
* This method creates a new Event, adds it to the task list, updates the UI,
* and saves the updated task list to storage.
*
* @param tasks The TaskList to which the new event will be added.
* @param ui The Ui object used to display output to the user.
* @param storage The Storage object used to save the updated task list.
*/
@Override
public void execute(TaskList tasks, Ui ui, Storage storage) {
Task newTask = new Event(description, from, to);
tasks.add(newTask);
ui.showAddedTask(newTask, tasks.getTaskCount());
storage.saveTasksToFile(tasks.getTasks(), tasks.getTaskCount());
}
}
Binary file added src/main/java/AddTodoCommand.class
Binary file not shown.
30 changes: 30 additions & 0 deletions src/main/java/AddTodoCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Command to add a todo task.
*/
public class AddTodoCommand extends Command {
private String description;

/**
* Constructs an AddTodoCommand with the specified description.
*
* @param description The description of the todo task.
*/
public AddTodoCommand(String description) {
this.description = description;
}

/**
* Executes the command to add the todo task to the task list.
*
* @param tasks The task list to which the task will be added.
* @param ui The user interface for displaying messages to the user.
* @param storage The storage for saving tasks to a file.
*/
@Override
public void execute(TaskList tasks, Ui ui, Storage storage) {
Task newTask = new Todo(description);
tasks.add(newTask);
ui.showAddedTask(newTask, tasks.getTaskCount());
storage.saveTasksToFile(tasks.getTasks(), tasks.getTaskCount());
}
}
Binary file added src/main/java/Command.class
Binary file not shown.
27 changes: 27 additions & 0 deletions src/main/java/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Represents an abstract command in the task management system.
* This class serves as a base for all concrete command implementations.
*/
public abstract class Command {
/**
* Executes the command.
* This method should be implemented by all concrete command classes to define
* their specific behavior.
*
* @param tasks The TaskList on which the command operates.
* @param ui The Ui object used to interact with the user.
* @param storage The Storage object used to save and load tasks.
* @throws PoirotException If an error occurs during command execution.
*/
public abstract void execute(TaskList tasks, Ui ui, Storage storage) throws PoirotException;

/**
* Checks if this command should exit the program.
* By default, commands do not exit the program.
*
* @return true if the program should exit after this command, false otherwise.
*/
public boolean isExit() {
return false;
}
}
Binary file added src/main/java/Deadline.class
Binary file not shown.
43 changes: 43 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
* Represents a deadline task in the task management system.
* A deadline task is a task that needs to be completed by a specific date and time.
*/
public class Deadline extends Task {
private LocalDateTime by;
private static final DateTimeFormatter INPUT_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm");
private static final DateTimeFormatter OUTPUT_FORMAT = DateTimeFormatter.ofPattern("MMM d yyyy, hh:mm a");

/**
* Constructs a new Deadline task with the given description and deadline.
*
* @param description The description of the deadline task.
* @param by The deadline date and time in the format "yyyy-MM-dd HHmm".
*/
public Deadline(String description, String by) {
super(description);
this.by = LocalDateTime.parse(by, INPUT_FORMAT);
}

/**
* Returns a string representation of the deadline task.
*
* @return A formatted string representing the deadline task, including its status, description, and deadline.
*/
@Override
public String toString() {
return "[D][" + getStatusIcon() + "] " + description + " (by: " + by.format(OUTPUT_FORMAT) + ")";
}

/**
* Returns a string representation of the deadline task for file storage.
*
* @return A formatted string representing the deadline task for saving to a file.
*/
@Override
public String toFileString() {
return "D | " + (isDone ? "1" : "0") + " | " + description + " | " + by.format(INPUT_FORMAT);
}
}
Binary file added src/main/java/DeleteCommand.class
Binary file not shown.
34 changes: 34 additions & 0 deletions src/main/java/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Command to delete a task from the task list.
*/
public class DeleteCommand extends Command {
private int index;

/**
* Constructs a DeleteCommand with the specified index.
*
* @param index The index of the task to delete.
*/
public DeleteCommand(int index) {
this.index = index;
}

/**
* Executes the command to delete the specified task from the task list.
*
* @param tasks The task list from which the task will be deleted.
* @param ui The user interface for displaying messages to the user.
* @param storage The storage for saving tasks to a file.
* @throws PoirotException If the index is out of bounds.
*/
@Override
public void execute(TaskList tasks, Ui ui, Storage storage) throws PoirotException {
if (index < 1 || index > tasks.getTaskCount()) {
throw new PoirotException("Task number is out of bounds!");
}
Task taskToDelete = tasks.getTask(index - 1);
tasks.delete(index - 1);
ui.showDeletedTask(taskToDelete, tasks.getTaskCount());
storage.saveTasksToFile(tasks.getTasks(), tasks.getTaskCount());
}
}
Binary file added src/main/java/Duke.class
Binary file not shown.
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

Binary file added src/main/java/Event.class
Binary file not shown.
Loading