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

[Lim Yuh Ching] iP #79

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3174bce
Level 0. Rename, Greet, Exit
limyuhching Sep 5, 2023
3015c0c
Level 1. Echo
limyuhching Sep 5, 2023
f21bf13
Renamed Duke. Added greetings.
limyuhching Sep 5, 2023
46b895f
Renamed list as tasks. Added isDone flag and markAsDone, markAsUndone…
limyuhching Sep 5, 2023
bbc2eff
Add ToDos, Events, Deadlines
limyuhching Sep 6, 2023
aa3631e
Make changes to various variable name
limyuhching Sep 13, 2023
2e8d61b
Add Exceptions
limyuhching Sep 29, 2023
4f314bf
Revert "Add Exceptions"
limyuhching Sep 29, 2023
226c229
Handled exceptions
limyuhching Sep 29, 2023
111b4d1
Add support for deleting tasks from the list
limyuhching Sep 29, 2023
798021e
Add DataManager to save tasks to a text file
limyuhching Oct 3, 2023
4bc7648
Merge branch 'branch-Level-6' into branch-Level-7
limyuhching Oct 3, 2023
ce88d16
Merge branch 'branch-Level-6'
limyuhching Oct 3, 2023
b8c1b0a
Merge branch 'branch-Level-7'
limyuhching Oct 3, 2023
7beac69
Divide code into smaller objects
limyuhching Oct 4, 2023
02762e4
Create find command to match keyword with task
limyuhching Oct 4, 2023
9df7185
Add Javadoc to most of the class
limyuhching Oct 4, 2023
ffa52f1
Merge pull request #1 from limyuhching/branch-A-JavaDoc
limyuhching Oct 4, 2023
7dd4b48
Merge branch 'master' of https://github.com/limyuhching/ip
limyuhching Oct 4, 2023
e1a286f
Update README.md
limyuhching Oct 4, 2023
119b4c9
Update README.md
limyuhching Oct 4, 2023
8b84635
Merge branch 'master' of https://github.com/limyuhching/ip
limyuhching Oct 4, 2023
0a66c63
Minor UI changes
limyuhching Oct 4, 2023
9cfe06e
Minor UI changes
limyuhching Oct 4, 2023
96b8727
Handle exception when argument is missing
limyuhching Oct 4, 2023
7edd3e7
Update README.md
limyuhching Oct 7, 2023
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
85 changes: 69 additions & 16 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,82 @@
# User Guide

# Wenny Task Manager User Guide
Wenny is your friendly task manager that helps you keep track of your endless numbers of to do tasks, deadlines and events.
## Features
Notes about the command format:
1. Words in UPPER_CASE are the parameters to be supplied by the user.
e.g. in todo DESCRIPTION, DESCRIPTION is a parameter which can be used as `todo Homework`.

2. Extraneous parameters for commands that do not take in parameters (such as list and bye) will be ignored.
e.g. if the command specifies `list 123`, it will be interpreted as list.

## List current tasks `list`

List all current tasks.

Format: `list`

## Exit the program `bye`

Exit the program.

Format: `bye`

## Add a to-do task `todo`

Add to-do task into the list.

Format: `list DESCRIPTION`

Example:
- `todo complete week 7 tasks`
- `todo sleep`


## Add a deadline task `deadline`
Add a task with a deadline.

Format: `deadline DESCRIPTION /by DEADLINE`

Example:
- `deadline complete week 8 tasks /by 12 Oct`.


## Add an event task `event`
Add an event into the task list.

Format: `event DESCRIPTION /from START_TIME /to END_TIME`.

Example:
- `event IA interview /from 7 Oct 2pm /to 7 Oct 4pm`.

## Mark a task as done `mark`
Mark a task on the task list as done.

### Feature-ABC
Format: `mark TASK_NUMBER`.

Description of the feature.
Example:
- `mark 1`

### Feature-XYZ
## Mark a task as undone `unmark`
Mark a task on the task list as undone.

Description of the feature.
Format: `unmark TASK_NUMBER`.

## Usage
Example:
- `unmark 1`.

### `Keyword` - Describe action

Describe the action and its outcome.
## Delete a task `delete`
Delete a task from the task list.

Example of usage:
Format: `delete TASK_NUMBER`.

`keyword (optional arguments)`
Example:
- `delete 1`.

Expected outcome:
## Find the tasks that matches a certain keyword `find`
Find the tasks that matches a certain keyword .

Description of the outcome.
Format: `find KEYWORD`.

```
expected output
```
Example:
- `find John`.
119 changes: 119 additions & 0 deletions src/main/java/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import java.util.ArrayList;

/**
* Execute commands from the user.
*/
public class Command {
private String command;
private String arg;
private boolean isExit;

/**
* Constructor of a Command
*
* @param command Command to be executed
* @param arg Arguments of the given command
*/
public Command(String command, String arg) {
this.command = command;
this.arg = arg;
this.isExit = false;
}

public void setExit(boolean exit) {
isExit = exit;
}

public boolean isExit() {
return isExit;
}

/**
* Execute the command given by the user
* Each command is handled by its corresponding method in {@code TaskList}. If there
* is any changes to the list of tasks, it will be saved into the file through {@code Storage}.
* Relevant information will be shown to the user through corresponding methods in {@code Ui}.
* A custom exceptions will be thrown if an invalid command is received or an invalid argument of
* the respective command.
*
* @param taskList TaskList object that contains a list of Tasks
* @param ui User interface object that handles the printing of information
* @param storage Storage object that saves the updated list into filepath
* @throws DukeException Custom Exception with customer error message
*/
public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeException{
switch(this.command) {
case "bye":
setExit(true);
ui.showByeMessage();
break;
case "list":
ui.showTasks(taskList);
break;
case "mark":
try {
taskList.markTask(this.arg, true);
storage.save(taskList);
ui.showMark(taskList, this.arg, true);
} catch (DukeException e) {
ui.showError(e);
}
break;
case "unmark":
try {
taskList.markTask(this.arg, false);
storage.save(taskList);
ui.showMark(taskList, this.arg, false);
} catch (DukeException e) {
ui.showError(e);
}
break;
case "todo":
try {
taskList.addTodo(this.arg);
storage.save(taskList);
ui.showAddTask(taskList);
} catch (DukeException e) {
ui.showError(e);
}
break;
case "deadline":
try {
taskList.addDeadline(this.arg);
storage.save(taskList);
ui.showAddTask(taskList);
} catch (DukeException e) {
ui.showError(e);
}
break;
case "event":
try {
taskList.addEvent(this.arg);
storage.save(taskList);
ui.showAddTask(taskList);
} catch (DukeException e) {
ui.showError(e);
}
break;
case "delete":
try {
Task removedTask = taskList.deleteTask(this.arg);
storage.save(taskList);
ui.showDeleteTask(taskList, removedTask);
} catch (DukeException e) {
ui.showError(e);
}
break;
case "find":
try {
ArrayList<Task> matchingTasks = taskList.find(this.arg);
ui.showFind(matchingTasks);
} catch (DukeException e) {
ui.showError(e);
}
break;
default: // Unknown command exception
throw new DukeException("Invalid input, please try again");
}
}
}
31 changes: 31 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public class Deadline extends Task {
String by;
public Deadline(String description, String by) {
super(description);
this.by = by;
}
public String getBy() {
return by;
}
public void setBy(String by) {
this.by = by;
}

/**
* Returns the format of the task to be printed out to user
* @return String representation of the task
*/
@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}

/**
* Returns the format of the task to be saved into a file
* @return String representation of the task
*/
@Override
public String toSave() {
return "D | " + super.toSave() + " | " + by;
}
}
64 changes: 58 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,62 @@
import java.util.ArrayList;
import java.util.Scanner;

/**
* This is the main program of Duke.
* Duke is a chatbot for user track tasks such as todos, deadlines and events.
* User can add tasks, mark tasks as done, delete tasks or find tasks based on a keyword.
* These tasks are automatically saved in a file in ./data/data.txt whenever an operation
* on the TaskList is made. This file will be loaded on future start up of the chatbot
*
*/
public class Duke {

private Storage storage;
private TaskList taskList;
private Ui ui;

/**
* Constructor of Duke. Initialise User interface, Storage and TaskList instances.
* @param filePath Path to the file where tasks are to be loaded from and saved to.
*/
public Duke(String filePath) {
ui = new Ui();
storage = new Storage(filePath);
ui.showLoadingFile();
try {
taskList = new TaskList(storage.load());
ui.showFileLoaded();
} catch (DukeException e) {
ui.showError(e);
taskList = new TaskList();
}
}

/**
* To start up the chatbot.
* A greetings will be printed on the command line interface and the chatbot will
* await instructions from the user. The chatbot will run until an exit command is received.
* Any exception during the operation will produce an error message to notify the user
*/
public void run() {
Parser parser = new Parser();
ui.showStartMessage();
boolean isExit = false;
while (!isExit) {
try {
String fullCommand = ui.readCommand();
Command c = parser.parse(fullCommand);
c.execute(taskList, ui, storage);
isExit = c.isExit();
} catch (DukeException e) {
ui.showError(e);
}
}
System.exit(0);
}

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
new Duke("./data/data.txt").run();
}

}
19 changes: 19 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Custom Exception for Duke
*/
public class DukeException extends Exception{
String errorMessage;
public DukeException(String errorMessage) {
this.errorMessage = errorMessage;
}

/**
* Format error message for printing to command line interface.
* @return Return the error message of the specific exception in String format.
*/
@Override
public String toString() {
return errorMessage;
}

}
45 changes: 45 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
public class Event extends Task {
String from;
String to;

public Event(String description, String from, String to) {
super(description);
setFrom(from);
setTo(to);
}

public String getFrom() {
return from;
}

public void setFrom(String from) {
this.from = from;
}

public String getTo() {
return to;
}

public void setTo(String to) {
this.to = to;
}

/**
* Returns the format of the task to be printed out to user
* @return String representation of the task
*/
@Override
public String toString() {
return "[E]" + super.toString() + " (from: " + from + ", to: " + to + ")";
}

/**
* Returns the format of the task to be saved into a file
* @return String representation of the task
*/
@Override
public String toSave() {
return "E | " + super.toSave() + " | " + from + " | " + to;
}
}

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: Duke

Loading