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

[Caleb Chan] iP #191

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
c5b2f77
Rename chatbot to Nano and add greeting and exit message
calebcjl Jan 19, 2023
8cb1426
Add echo user input feature and exit condition
calebcjl Jan 25, 2023
5690fae
Change echo feature to store user input in a list
calebcjl Jan 26, 2023
daafab5
Add task class and feature to mark tasks
calebcjl Jan 31, 2023
d9c167a
Tweak to coding standard and display number of completed tasks in list
calebcjl Jan 31, 2023
b3d9e39
Refactor code to improve quality
calebcjl Feb 1, 2023
57b1f39
Improve code based on peer reviews
calebcjl Feb 4, 2023
a8bd85d
Add new classes to represent different types of Task
calebcjl Feb 4, 2023
4c0bc00
Add exceptions to detect incorrect input
calebcjl Feb 8, 2023
0dd2ccb
Organise classes into packages
calebcjl Feb 8, 2023
0072420
Add /help command to list out all possible commands
calebcjl Feb 8, 2023
5ff0543
Merge branch 'branch-A-Package'
calebcjl Feb 8, 2023
3e3cce1
Merge branch 'branch-Level-5'
calebcjl Feb 8, 2023
2db7774
Create new package for Nano exceptions
calebcjl Feb 8, 2023
d7f2d9e
Use ArrayList to store tasks instead of fixed array
calebcjl Feb 16, 2023
8d667e9
Add delete feature
calebcjl Feb 16, 2023
8cf3a5d
Add feature to save and retrieve user task list data
calebcjl Mar 3, 2023
d4c1c33
Merge branch 'branch-Level-6'
calebcjl Mar 3, 2023
da6e71f
Merge branch 'branch-Level-7'
calebcjl Mar 3, 2023
b3afe13
Refactor code to include new classes and packages for more OOP
calebcjl Mar 3, 2023
f44d88a
Add feature to find and list tasks containing a keyword
calebcjl Mar 3, 2023
2a52cb3
Merge pull request #1 from calebcjl/branch-Level-9
calebcjl Mar 3, 2023
4939e2c
Merge branch 'master' of https://github.com/calebcjl/ip
calebcjl Mar 3, 2023
d7094b0
Add JavaDoc comments to code
calebcjl Mar 3, 2023
f9280aa
Add user guide for Nano
calebcjl Mar 3, 2023
0d5f844
Update the correct README for user guide
calebcjl Mar 6, 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
114 changes: 98 additions & 16 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,111 @@
# User Guide
# Nano User Guide

## Features
Nano is the chatbot for individual project for CS2113, AY22/23 Semester 2.

### Feature-ABC
Nano is named after the nano machine from the fantasy wuxia novel Nano Machine!

Description of the feature.
## Table of Contents

### Feature-XYZ
- [Nano User Guide](#nano-user-guide)
- [Features](#features)
- [Task Creation](#task-creation)
- [Task Management](#task-management)
- [Commands](#commands)
- [add - Add new task](#add---add-new-task)
- [list - Display your Task List](#list---display-your-task-list)
- [mark - Tag task as done](#mark---tag-task-as-done)
- [unmark - Tag task as undone](#unmark---tag-task-as-undone)
- [delete - Delete a Task](#delete---delete-a-task)
- [find - Query for a task](#find---look-for-a-task)
- [exit - Nano goes to sleep](#exit---nano-goes-to-sleep)

Description of the feature.
## Features

## Usage
Nano has a variety of features for you to manage your tasks efficiently via CLI.

### `Keyword` - Describe action
### Task Creation

Describe the action and its outcome.
Keep track of your tasks in a list.

Example of usage:
Nano can manage up to three types of tasks:
1. Todo - regular todo tasks
2. Deadline - tasks that with a deadline
3. Event - tasks that have a start and end time

`keyword (optional arguments)`
### Task Management

Expected outcome:
Nano can help you mark, unmark, list, find, and save your tasks easily!

Description of the outcome.
- Nano marks your tasks to indicated that you have completed it.
- Nano can list out all your current tasks and its details.
- Nano allows you to look for specific tasks using a keyword.
- Nano can save your task list.

## Commands

### add - Add new task

Add a new task(Todo, Deadline, Event). Nano will automatically detect the type of task for you.

Syntax:

``/add <task_name>``

``/add <task_name> by/<due_date>``

``/add <task_name> from/<start_time> to/<end_time>``

### list - Display your task list

Nano will show you your list of tasks.
The list contains all the task details as well

Syntax:

``/list``

### mark - Tag task as done
Nano marks a task in the task list as done

Syntax:
``/mark <task_name>``


### unmark - Tag task as undone

Nano marks a task in the task list as not done.

Syntax:
``/unmark <task_name>``


### delete - Delete a Task

Nano deletes a task from your task list.

Syntax:
``delete <task_name>``

### find - Look for a task

Nano will look for the tasks containing a keyword and display them to you.

Syntax:

``/find <keyword>``

### help - Displays all commands

Nano reminds you of all his features and their syntax

Syntax:
``/help``

### exit - Nano goes to sleep

Nano enters into sleeping mode.

Syntax:

``/exit``

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

This file was deleted.

44 changes: 44 additions & 0 deletions src/main/java/nano/Nano.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package nano;

import nano.data.TaskList;
import nano.data.exception.NanoCommandException;
import nano.parser.Parser;
import nano.storage.Storage;
import nano.ui.Ui;

import java.io.IOException;

public class Nano {

private static Storage storage;
private static Ui ui;
private static TaskList tasks;

public Nano(String filePath) {
//chatbot startup
ui = new Ui();
storage = new Storage(filePath);
tasks = new TaskList(storage);
}

/**
*
*/
public void run() {
while (true) {
String userInput = ui.getUserInput();
try {
Parser.executeCommand(userInput, tasks);
storage.saveTaskFile(tasks.getTaskList());
} catch (NanoCommandException commandException) {
Ui.displayUnknownCommandMessage();
} catch (IOException e) {
System.out.println("Error saving file.");
}
}
}

public static void main(String[] args) {
new Nano("data/tasks.txt").run();
}
}
186 changes: 186 additions & 0 deletions src/main/java/nano/data/TaskList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
package nano.data;

import nano.ui.Ui;
import nano.storage.Storage;
import nano.data.task.Deadline;
import nano.data.task.Event;
import nano.data.task.Task;
import nano.data.task.Todo;

import java.util.ArrayList;

public class TaskList {
private static final int TASK_NAME_INDEX = 0;
private static final int TASK_TYPE_INDEX = 1;
private static final int TASK_START_DATE_INDEX = 2;
private static final int TASK_DUE_DATE_INDEX = 2;
private static final int TASK_END_DATE_INDEX = 3;
private static final int TASK_INDEX_ERROR = -1;
private final ArrayList<Task> tasks;

public TaskList() {
tasks = new ArrayList<>();
}

public TaskList(Storage storage) {
tasks = new ArrayList<>();
storage.getUserData(tasks);

}

/**
* Delete task from task list.
*
* @param taskName Name of task to delete.
*/
public void deleteTask(String taskName) {
int taskIndex = getTaskIndex(taskName);
if (taskIndex == TASK_INDEX_ERROR) {
Ui.displayTaskNotFoundMessage();
return;
}

tasks.remove(taskIndex);
Task.deleteTask();
System.out.println("Deleted " + taskName);
}

/**
* Set task as uncompleted.
*
* @param taskName Name of task to unmark.
*/
public void unmarkTask(String taskName) {
int taskIndex = getTaskIndex(taskName);
if (taskIndex == TASK_INDEX_ERROR) {
Ui.displayTaskNotFoundMessage();
return;
}

if (tasks.get(taskIndex).isCompleted()) {
tasks.get(taskIndex).setUndone();
Ui.displayUnmarkTaskMessage(taskName);
} else {
Ui.displayTaskAlreadyUndoneMessage(taskName);
}
}

/**
* Set task as completed.
*
* @param taskName Name of task to mark.
*/
public void markTask(String taskName) {
int taskIndex = getTaskIndex(taskName);
if (taskIndex == TASK_INDEX_ERROR) {
Ui.displayTaskNotFoundMessage();
return;
}

if (!tasks.get(taskIndex).isCompleted()) {
tasks.get(taskIndex).setDone();
Ui.displayMarkTaskMessage(taskName);
} else {
Ui.displayTaskAlreadyDoneMessage(taskName);
}
}

/**
* Returns index of task in task list.
*
* @param taskName Name of task.
* @return Index of task.
*/
private int getTaskIndex(String taskName) {
for (Task task : tasks) {
if (task.getTaskName().equals(taskName)) {
return tasks.indexOf(task);
}
}
return TASK_INDEX_ERROR;
}

/**
* Adds task to task list.
*
* @param taskDetails Details of task added
*/
public void addTask(String[] taskDetails) {
if (isInList(taskDetails[TASK_NAME_INDEX])) {
System.out.println(taskDetails[TASK_NAME_INDEX] + " is already in the list!");
return;
}

Task newTask;
switch (taskDetails[TASK_TYPE_INDEX]) {
case "deadline":
newTask = new Deadline(taskDetails[TASK_NAME_INDEX], taskDetails[TASK_DUE_DATE_INDEX]);
break;
case "event":
newTask = new Event(taskDetails[TASK_NAME_INDEX], taskDetails[TASK_START_DATE_INDEX],
taskDetails[TASK_END_DATE_INDEX]);
break;
default:
newTask = new Todo(taskDetails[TASK_NAME_INDEX]);
break;
}
tasks.add(newTask);
System.out.println("Added " + taskDetails[TASK_NAME_INDEX]);
}

/**
* Check if task is found in task list.
*
* @param taskName Name of task.
* @return true if task is in task list. Returns false otherwise.
*/
public boolean isInList(String taskName) {
for (Task task : tasks) {
if (task.getTaskName().equals(taskName)) {
return true;
}
}
return false;
}

/**
* Get lists of task
*
* @return Task list.
*/
public ArrayList<Task> getTaskList() {
return tasks;
}

/**
* Finds and displays all tasks containing a keyword.
*
* @param keyword Keyword used in search.
*/
public void findTasks(String keyword) {

if (isInvalidKeyword(keyword)) {
Ui.displayKeywordError();
return;
}

keyword = keyword.trim();
ArrayList<Task> searchList = new ArrayList<>();
for (Task task : tasks) {
if (task.getTaskName().contains(keyword)) {
searchList.add(task);
}
}

Ui.displayFindTaskMessage(searchList.size(), keyword);
Ui.displayTaskList(searchList);
}

private static boolean isInvalidKeyword(String keyword) {
if (keyword == null) {
return true;
}

return keyword.trim().length() == 0;
}
}
4 changes: 4 additions & 0 deletions src/main/java/nano/data/exception/NanoCommandException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package nano.data.exception;

public class NanoCommandException extends Exception {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package nano.data.exception;

public class NanoInputFormatException extends Exception{
}
15 changes: 15 additions & 0 deletions src/main/java/nano/data/task/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package nano.data.task;

public class Deadline extends Task{
private static final String TASK_TYPE_TAG = "[D]";
private String dueDate;
public Deadline(String name, String dueDate) {
super(name);
this.dueDate = dueDate;
}


public String toString() {
return TASK_TYPE_TAG + super.toString() + " (by: " + dueDate + ")";
}
}
Loading