Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5e12ead
Added Level 0 Greet
cheshire-doge Feb 2, 2022
b80b828
Added Level 1. Greet, Echo, Exit
cheshire-doge Feb 3, 2022
5d36d39
Added Level 2. Add, List
cheshire-doge Feb 3, 2022
6008445
Added Level 3. Mark as Done
cheshire-doge Feb 3, 2022
5fc1f21
Added Level 4. ToDos, Events, Deadlines
cheshire-doge Feb 3, 2022
cbe6141
Added Level 5. Handle Errors
cheshire-doge Feb 10, 2022
31969f4
Added more exception cases
cheshire-doge Feb 13, 2022
7e77253
Divided classes into packages
cheshire-doge Feb 17, 2022
839374b
Changed task list to ArrayList<Task>
cheshire-doge Feb 18, 2022
ad89ac0
Added Level 6: Delete
cheshire-doge Feb 18, 2022
a3b43cc
Added Level 7: Save
cheshire-doge Feb 25, 2022
da8379e
Merge branch 'branch-Level-7'
cheshire-doge Feb 25, 2022
1c78539
Added more OOP
cheshire-doge Mar 1, 2022
5572363
Added Level 9 - Find
cheshire-doge Mar 1, 2022
8da9e30
Added Level 8 - Dates and Times
cheshire-doge Mar 3, 2022
d26c136
Updated master branch
cheshire-doge Mar 3, 2022
12f2b10
Merge branch 'branch-Level-8'
cheshire-doge Mar 3, 2022
6223ce7
Merge branch 'master' into branch-Level-9
cheshire-doge Mar 3, 2022
a7f8ae9
Resolved conflicts
cheshire-doge Mar 3, 2022
5f7b0fc
Removed unused java files
cheshire-doge Mar 4, 2022
6dbe246
Added JavaDocs for all Classes and methods
cheshire-doge Mar 4, 2022
dcf4abc
Merge pull request #1 from cheshire-doge/branch-A-JavaDoc
cheshire-doge Mar 4, 2022
1322532
Added User Guide
cheshire-doge Mar 4, 2022
3c2c3b1
Edits to text-ui-test
cheshire-doge Mar 4, 2022
280fb24
Edits to README
cheshire-doge Mar 4, 2022
f55cc7b
Updated README ip.jar link
cheshire-doge Mar 4, 2022
2e5b0a1
Changes to Find command
cheshire-doge Mar 4, 2022
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 @@
1|T|0|read book
2|D|1|return book|2022-06-06|1700
88 changes: 76 additions & 12 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,93 @@
# User Guide
Duke is a chat-bot that manages your tasks. It is accessed via a Command Line Interface (CLI).

## Features
##Quick start
1. Ensure that you have **Java 11** installed on your system.
2. Download the latest [ip.jar](https://github.com/cheshire-doge/ip/releases/tag/A-Release)
3. Open a **Command Line** and change your directory to the folder containing **ip.jar**
4. Enter `java -jar ip.jar` to start Duke
5. Refer to **Usage** below or enter `commands` into the Command Line to view commands.

### Feature-ABC
## Features

Description of the feature.
### Storing of Tasks `ToDo`, `Deadline`, `Event`

### Feature-XYZ
**ToDos** are tasks that do not have a date they have to be accomplished by.

Description of the feature.
**Deadlines** are tasks that have a deadline they have to be accomplished by.

**Events** are tasks that run for a period of time, with a starting time and ending time.

### Mark/Unmark Tasks

Mark or Unmark tasks to remind you if you have completed them.

### Find Tasks

Search for tasks using specific keywords.

### Other Features!

**Delete**, **Check Date**, **List**

## Usage

### `Keyword` - Describe action
### `todo` - Creates a ToDo

Example:

`todo DESCRIPTION` - Adds a ToDo with DESCRIPTION onto the task list

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

Describe the action and its outcome.
### `deadline` - Creates a Deadline

Example of usage:
`deadline DESCRIPTION /by DD/MM/YYYY time` - Adds a deadline with DESCRIPTION and deadline

`keyword (optional arguments)`
```
deadline iP /by 03/03/2022 2359
____________________________________________________________
Got it. I've added this task:
[D][ ] iP (by: Mar 3 2022 2359)
Now you have 6 tasks in the list.
```

Expected outcome:
### `event` - Creates an Event

Description of the outcome.
`event DESCRIPTION /at DD/MM/YYYY time /to DD/MM/YYYY time` - Adds an event with DESCRIPTION, start time and end time.

```
expected output
event Project Meeting /at 05/03/2022 2000 /to 05/03/2022 2200
____________________________________________________________
Got it. I've added this task:
[E][ ] Project Meeting (at: Mar 5 2022 2000 to Mar 5 2022 2200)
Now you have 3 tasks in the list.
```

### `list` - Lists out all tasks

`list` - All tasks will be listed down

### `mark`/`unmark` `NUMBER` - marks/unmarks task NUMBER in the list

`mark 3` - Task 3 in the list would be marked

### `find KEYWORD` - searches the list based on KEYWORD

`find project` - Lists down every Task in the list containing `project`

### `check date DD/MM/YYYY` - checks the list if any task is due or happens on that day
`check date 04/03/2021` - Checks if any task happens or is due on 04/03/2021

### `delete NUMBER` - deletes task NUMBER in the list
`delete 1` - Deletes the first task on the list

### `bye` - closes the bot

### `commands` - lists down all commands
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

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: main.java.duke.Duke

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

import java.util.Scanner;
import java.io.IOException;
import java.util.ArrayList;
import main.java.duke.ui.Ui;
import main.java.duke.parser.Parser;
import main.java.duke.command.Command;
import main.java.duke.task.Task;
import main.java.duke.exception.DukeException;
import main.java.duke.storage.Storage;

/**
* Main class for Duke that runs the bot. The bot takes in user inputs, and has various commands
* that would perform various tasks
*/

public class Duke {

private static Scanner sc = new Scanner(System.in);
public static ArrayList<Task> tasks = new ArrayList<Task>();
public static int taskCounter = 0;
private final Parser parser = new Parser();

/**
* Main method used to run the bot. It calls the load() method from the Storage class to
* load data saved from previous uses, will ask for user inputs, will call the writeToFile()
* method from Storage to update the latest information.
*/
private void run() {
try {
Storage.load();
} catch (IOException e) {
System.out.println("ERROR IN LOADING FILE");
} catch (DukeException e) {
System.out.println(e.getMessage());
return;
}
Ui.printIntro();
String input = "";
while (!input.equals("bye")) {
try {
input = sc.nextLine();
Command command = parser.parse(input);
command.execute();
} catch (DukeException e) {
Ui.printError(e);
}
}

}

/**
* Main method for Duke.
*
* @param args NIL.
*/
public static void main(String[] args) {
new Duke().run();
}
}
25 changes: 25 additions & 0 deletions src/main/java/duke/command/ByeCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main.java.duke.command;

import java.io.IOException;
import main.java.duke.ui.Ui;
import main.java.duke.storage.Storage;

/**
* Class for ByeCommand. It is created when the user wants to close Duke.
*/

public class ByeCommand extends Command {

/**
* Method to carry out the command. It initiates the writing of the task list into
* the txt file, and prints a goodbye message before closing Duke.
*/
public void execute() {
try {
Storage.writeToFile();
} catch (IOException e) {
System.out.println("ERROR IN WRITING FILE");
}
Ui.printBye();
}
}
40 changes: 40 additions & 0 deletions src/main/java/duke/command/CheckDateCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main.java.duke.command;

import main.java.duke.exception.DukeException;
import main.java.duke.ui.Ui;
import java.time.LocalDate;

/**
* Class for the CheckDateCommand. It is created when the user wants to check if a date
* has any task.
*/

public class CheckDateCommand extends Command {

private final String date;

/**
* Constructor for CheckDateCommand.
*
* @param date String date that is being checked in the format DD/MM/YYYY
*/
public CheckDateCommand(String date) {
this.date = date;
}

/**
* Method to carry out the command. Calls a Ui method to show tasks on the date.
*
* @throws DukeException If user input is invalid.
*/
public void execute() throws DukeException {
if (isValidDate(convertDate(this.date))) {
LocalDate localDate = LocalDate.parse(convertDate(this.date));
Ui.printCheckDate(localDate);

} else {
throw new DukeException("Oh no! You have typed an invalid date!\n" +
"The format for date is DD/MM/YYYY !, e.g. 15/02/2022");
}
}
}
120 changes: 120 additions & 0 deletions src/main/java/duke/command/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package main.java.duke.command;

import main.java.duke.Duke;
import main.java.duke.exception.DukeException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

/**
* Abstract class for all Commands. Contains basic methods for different commands.
*/

public abstract class Command {

/**
* Method to check if a String is a number.
*
* @param string String that is being checked.
* @return Boolean value whether the String is a number.
*/
protected boolean isNum(String string) {
try {
Integer.parseInt(string);
} catch (NumberFormatException e) {
return false;
}
return true;
}

/**
* Method to convert a date from DD/MM/YYYY to YYYY-MM-DD.
*
* @param date String date in DD/MM/YYYY time format.
* @return String date in YYYY-MM-DD format.
* @throws DukeException If input date format is invalid.
*/
protected String convertDate(String date) throws DukeException {
String[] dateTimeArray = date.split(" ");
String[] dateArray = dateTimeArray[0].split("/");
if (dateArray.length != 3) {
throw new DukeException("Oh no! Your date format is invalid!\n" +
"The format for date is DD/MM/YYYY !, e.g. 15/02/2022");
} else if (!isNum(dateArray[0]) || !isNum(dateArray[1]) || !isNum(dateArray[2])) {
throw new DukeException("Oh no! Your date format is invalid!\n" +
"The format for date is DD/MM/YYYY !, e.g. 15/02/2022");
}
String dayString = String.format("%02d", Integer.parseInt(dateArray[0]));
String monthString = String.format("%02d", Integer.parseInt(dateArray[1]));
String yearString;
String localDateString;
if (dateArray[2].length() == 2) {
yearString = "20" + dateArray[2];
} else if (dateArray[2].length() == 4) {
yearString = dateArray[2];
} else {
throw new DukeException("Oh no! You have typed an invalid date!\n" +
"The format for date is DD/MM/YYYY !, e.g. 15/02/2022");
}

localDateString = yearString + "-" + monthString + "-" + dayString;
if (isValidDate(localDateString)) {
return localDateString;
} else {
throw new DukeException("Oh no! You have typed an invalid date!\n" +
"The format for date is DD/MM/YYYY !, e.g. 15/02/2022");
}
}

/**
* Checks if date in YYYY-MM-DD is a valid date.
*
* @param date String date in YYYY-MM-DD format.
* @return Boolean value whether date is a valid date.
*/
protected boolean isValidDate(String date) {
try {
LocalDate.parse(date);
} catch (DateTimeParseException e) {
return false;
}
return true;
}

/**
* Method that checks if time input is valid.
*
* @param date String date in DD/MM/YYYY time format.
* @return String time in 24-hour format.
* @throws DukeException If time is invalid.
*/
protected String convertTime(String date) throws DukeException {
String[] dateTimeArray = date.split(" ");
String time;
if (dateTimeArray.length < 2) {
throw new DukeException("Oh no! You did not key in a time");
} else {
time = dateTimeArray[1];
if (isNum(time)) {
if (Integer.parseInt(time) < 2400 && Integer.parseInt(time) >= 0 &&
Integer.parseInt(time) % 100 < 60) {
return time;
} else {
throw new DukeException("Oh no! The time you entered is invalid!\n" +
"The format for time is in 24-hour format! e.g. 1800");
}
} else {
throw new DukeException("Oh no! The time you entered is invalid!\n" +
"The format for time is in 24-hour format! e.g. 1800");
}
}
}

/**
* Abstract method that all commands have.
*
* @throws DukeException If command cannot be executed due to invalid inputs.
*/
public abstract void execute() throws DukeException;

}
Loading