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

[Gerald Koh Kheng Guan] iP #192

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
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
de8ed4d
Achieved Level 0
geraldkoh4 Jan 24, 2023
5d5cc71
Minor Change in spelling
geraldkoh4 Jan 25, 2023
bc93fd2
Finished Level 1
geraldkoh4 Jan 25, 2023
7d21da9
Finished Level-2
geraldkoh4 Jan 25, 2023
6d10d3f
Finished Level-3
geraldkoh4 Jan 25, 2023
444b5c0
Finished level-4 and edited level 0, 1, 2 and 3
geraldkoh4 Jan 31, 2023
f7d165c
Minor format changes
geraldkoh4 Jan 31, 2023
25dffa2
Finished Level 5
geraldkoh4 Feb 7, 2023
609c4a9
Merge branch 'branch-Level-5'
geraldkoh4 Feb 12, 2023
544ba64
Minor changes to main, added DukeSession and fixed minor bugs
geraldkoh4 Feb 12, 2023
8902eae
Level-6 done, with some minor changes to arraylist and actioncounter …
geraldkoh4 Feb 12, 2023
69d4b63
Merge branch 'branch-Level-6'
geraldkoh4 Feb 12, 2023
959c5a4
Finished Level-7, fixed some bugs for Level-6 as well
geraldkoh4 Feb 12, 2023
13f7505
Merge branch 'branch-Level-7'
geraldkoh4 Feb 12, 2023
8a06c04
No idea what this does. Im trying to keep everything up to date.
geraldkoh4 Feb 12, 2023
e0c6dc9
Finished Level-9
geraldkoh4 Mar 1, 2023
391f7bf
Merge branch 'branch-Level-9'
geraldkoh4 Mar 1, 2023
77ef37e
Implemented JavaDoc and other Ui debugging and formatted strings.
geraldkoh4 Mar 2, 2023
6ba8f86
Merge pull request #1 from geraldkoh4/branch-A-JavaDoc
geraldkoh4 Mar 2, 2023
f423633
Update README.md
geraldkoh4 Mar 2, 2023
bf20902
Merge pull request #2 from geraldkoh4/A-UserGuide
geraldkoh4 Mar 2, 2023
cbc2097
Final and Minor formatting changes. Hope everything is working well!
geraldkoh4 Mar 3, 2023
c9f98f4
Update README.md
geraldkoh4 Mar 3, 2023
7831692
Minor Bug fixes
geraldkoh4 Mar 3, 2023
6df56ee
Update README.md
geraldkoh4 Mar 3, 2023
f4792f0
Update README.md
geraldkoh4 Mar 3, 2023
a7d571e
Update README.md
geraldkoh4 Mar 3, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ bin/

/text-ui-test/ACTUAL.TXT
text-ui-test/EXPECTED-UNIX.TXT
data/savedList.txt
155 changes: 142 additions & 13 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,158 @@
# User Guide

## Features
## `Introduction`

### Feature-ABC
This is Duke, a chatbot. He is here to assist you in compiling a task list that you can reference to.

Description of the feature.
## `Download`

### Feature-XYZ
1) Make sure that your computer supports Java 11 or above.
2) Download this [jar file](https://github.com/geraldkoh4/ip/releases/download/A-Release/Duke.jar).
3) Copy the file path.
4) Go into your console and enter `"java -jar {file path}"`.

Description of the feature.
## `Features`

## Usage
1) Add a Task
2) List all Tasks
3) Mark/Unmark a Task
4) Find a Task
5) Delete a Task
6) Exit

### `Keyword` - Describe action
### 1.1) Add a Task (To Do)

Describe the action and its outcome.
Add a "To Do" Task to the list.

Example of usage:
**`Format`**: todo {description}

`keyword (optional arguments)`
*Sample Input Command*: **`todo Fly a Kite`**

Expected outcome:
*Output*:
```
Got it. I've added this task:
[T][ ] Fly a Kite
Now you have 1 tasks in the list.
```

### 1.2) Add a Task (Deadline)

Add a "Deadline" Task to the list.

**`Format`**: deadline {description} /by {time/date}

*Sample Input Command*: **`deadline Finish My Homework /by Today`**

*Output*:
```
Got it. I've added this task:
[D][ ] Finish My Homework (by: Today)
Now you have 2 tasks in the list.
```

### 1.3) Add a Task (Event)

Add a "Event" Task to the list.

**`Format`**: event {description} /from {time/date} /to {time/date}

*Sample Input Command*: **`event Play Video Games /from Today 12pm /to Today Night`**

*Output*:
```
Got it. I've added this task:
[E][ ] Play Video Games (from: Today 12pm to: Today Night)
Now you have 3 tasks in the list.
```

### 2) List all Tasks

Lists every Task you currently have in your list.

**`Format`**: list

*Output*:
```
1) [T][ ] Fly a Kite
2) [D][ ] Finish My Homework (by: Today)
3) [E][ ] Play Video Games (from: Today 12pm to: Today Night)
```

### 3) Mark/Unmark a Task

Mark or unmark a Task to note if you have completed the Task through the tasknumber.

**`Format`**: mark {tasknumber}

*Sample Input Command*: **`mark 1`**

*Output*:
```
Done!
[T][X] Fly a Kite
```

### 4) Find a Task

Find a task through a search criteria.

**`Format`**: find {search criteria}

*Sample Input Command*: **`find Play`**

*Output*:
```
3) [E][ ] Play Video Games (from: Today 12pm to: Today Night)
Done!
```

### 5) Delete a Task

Delete a task that you no longer need through the tasknumber.

**`Format`**: delete {tasknumber}

*Sample Input Command*: **`delete 1`**

*Output*:
```
Got it. I've removed this task
[T][X] Fly a Kite
Now you have 2 tasks in the list.
```

### 6) Exit

Exit from the program.

**`Format`**: bye

*Output*:
```
That's all from me! Goodbye!
```

Description of the outcome.
# Note

## Test - Echo

Echo is a command that you can use to test if the chatbot is responding!

**`Format`**: echo {description}

*Sample Input Command*: **`echo 1`**

*Output*:
```
expected output
1
```

## Flags

Do not use the character '/'. It is solely reserved for flags.
Example of the flags include:
Deadline by flag: "/by "
Event from flag: "/from "
Event to flag: "/to "

Thank you!
24 changes: 18 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import parser.DukeSession;
import utility.Ui;

/**
* Represents the Main of the entire project, a chatbot named DUKE.
* It is made simple to understand the flow of the whole project.
*/
public class Duke {

/**
* Calls the session to start and initialises the session.
*
* @param args Contains any information the user inputs when running the process in the terminal.
*/
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
DukeSession dukeSession = new DukeSession();
Ui.printGreetings();
dukeSession.setUpArrayList();
dukeSession.execute();
}
}

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

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

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

import tasks.Task;
import tasks.Todo;
import tasks.Event;
import tasks.Deadline;
import utility.Ui;

/**
* Represents the Storage class, where it is used to deal with file and storage matters.
* It sets up the locally stored file first.
* It will check for the file in the default save path. If it does not exist, it will create the file and directory.
* If the local copy exists, it will load it and be incorporated into this session (DukeSession).
* After the user exits, it will also save the file to the default save path.
*/
public class Storage {
private static final String DEFAULT_SAVE_PATH = "data/savedList.txt";
private static final String DEFAULT_DIRECTORY_NAME = "data";
private static final String FILE_CORRUPTED_MESSAGE = "File has been corrupted";
private static final String ERROR_MESSAGE = "Something went wrong: ";
private static final String DEFAULT_TODO_SYMBOL = "t";
private static final String DEFAULT_DEADLINE_SYMBOL = "d";
private static final String DEFAULT_EVENT_SYMBOL = "e";
private static final String DEFAULT_MARKED_TASK_SYMBOL = "X";

private static File directoryAndFileChecker() throws IOException {
File f = new File(DEFAULT_SAVE_PATH);
File directory = new File(DEFAULT_DIRECTORY_NAME);
try {
if (!directory.exists()) {
directory.mkdir();
}
if (!f.exists()) {
f.createNewFile();
}
} catch (IOException e) {
System.out.println(ERROR_MESSAGE + e.getMessage());
}
return f;
}

/**
* It will call the method directoryAndFileChecker to ensure that all file and directory conflicts are resolved.
* After that, it reads the file and parses the data it loaded.
* Other setup methods are called to load different tasks and ensure that this session is same as the saved
* local text file.
*
* @param actions This contains the arraylist of Tasks.
*/
public static void setUpFile(ArrayList<Task> actions) {
try {
File f = directoryAndFileChecker();
String line;
String[] decisions;
Scanner in = new Scanner(f);
while (in.hasNext()) {
line = in.nextLine();
decisions = line.split(Ui.DEFAULT_FLAG_SEPARATOR);
switch (decisions[0]) {
case DEFAULT_TODO_SYMBOL:
setUpToDo(decisions, actions);
break;
case DEFAULT_DEADLINE_SYMBOL:
setUpDeadline(decisions, actions);
break;
case DEFAULT_EVENT_SYMBOL:
setUpEvent(decisions, actions);
break;
default:
Ui.print(FILE_CORRUPTED_MESSAGE);
}
}
} catch (IOException e) {
System.out.println(ERROR_MESSAGE + e.getMessage());
}
}

/**
* Saves any recorded information of this current DukeSession.
* The arraylist in DukeSession is saved into a default save path in a text file.
*
* @param actions This contains the arraylist of Tasks.
*/
public static void saveFile(ArrayList<Task> actions) {
try {
FileWriter fw = new FileWriter(DEFAULT_SAVE_PATH);
for (Task i : actions) {
fw.write(i.getSaveCommand() + System.lineSeparator());
}
fw.close();
} catch (IOException e) {
System.out.println(ERROR_MESSAGE + e.getMessage());
}
}

private static void setUpToDo(String[] decisions, ArrayList<Task> actions) {
Task toBeAdded = new Todo(decisions[2]);
if (decisions[1].equals(DEFAULT_MARKED_TASK_SYMBOL)) {
toBeAdded.mark();
}
actions.add(toBeAdded);
}

private static void setUpDeadline(String[] decisions, ArrayList<Task> actions) {
Task toBeAdded = new Deadline(decisions[2], decisions[3]);
if (decisions[1].equals(DEFAULT_MARKED_TASK_SYMBOL)) {
toBeAdded.mark();
}
actions.add(toBeAdded);
}

private static void setUpEvent(String[] decisions, ArrayList<Task> actions) {
Task toBeAdded = new Event(decisions[2], decisions[3], decisions[4]);
if (decisions[1].equals(DEFAULT_MARKED_TASK_SYMBOL)) {
toBeAdded.mark();
}
actions.add(toBeAdded);
}
}
Loading