Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8bf8991
add increment level 0
silinche Aug 20, 2021
5876d3a
added increment 1
silinche Aug 25, 2021
02672d8
added increment 2
silinche Aug 25, 2021
d75ba2c
added increment 3
silinche Aug 25, 2021
c77d04f
fix minor bug for increment 3
silinche Aug 25, 2021
308eacf
update on A-CodingStandard
silinche Aug 25, 2021
97a6781
Increment 4
silinche Sep 1, 2021
64e85b9
fixed bugs for level-4
silinche Sep 1, 2021
48ce882
fixed minor bugs for increment level 4
silinche Sep 1, 2021
653a21d
commit text ui testing
silinche Sep 8, 2021
7f61f2d
create more functions to comply with code quality standards
silinche Sep 15, 2021
dfcf04b
added dealing with errors
silinche Sep 15, 2021
ccd2556
Merge branch 'branch-Level-5'
silinche Sep 15, 2021
b4c1c68
added packaging
silinche Sep 15, 2021
7f4ad3f
added level 6 deletion function
silinche Sep 16, 2021
06d40a3
added the save to file feature
silinche Sep 17, 2021
d308886
Merge branch 'branch-Level-6'
silinche Sep 17, 2021
2c8103d
Merge branch 'branch-Level-7'
silinche Sep 17, 2021
2a89619
created Storage class to achieve more oop
silinche Sep 28, 2021
d41de47
added ui class to achieve more oop
silinche Sep 28, 2021
3e52e94
added more classes to achieve more oop
silinche Sep 28, 2021
8320297
added the find feature (level 9)
silinche Sep 29, 2021
fd35808
added javadoc
silinche Oct 1, 2021
c492a3b
Merge pull request #1 from silinche/branch-Level-9
silinche Oct 1, 2021
e61603d
Merge branch 'master' into branch-A-JavaDoc
silinche Oct 1, 2021
1e115d9
Merge pull request #2 from silinche/branch-A-JavaDoc
silinche Oct 1, 2021
2faad66
Merge branch 'master' of https://github.com/silinche/ip
silinche Oct 1, 2021
bb57228
Added user guide
silinche Oct 1, 2021
ebba67b
Set theme jekyll-theme-cayman
silinche Oct 1, 2021
999995d
fixed issues with saving in files
silinche Oct 1, 2021
4168e98
Merge branch 'master' of https://github.com/silinche/ip
silinche Oct 1, 2021
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/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Duke project template
# duke.command.Duke project template

This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it.

Expand All @@ -13,7 +13,7 @@ Prerequisites: JDK 11, update Intellij to the most recent version.
1. If there are any further prompts, accept the defaults.
1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).<br>
In the same dialog, set the **Project language level** field to the `SDK default` option.
3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output:
3. After that, locate the `src/main/java/duke.command.Duke.java` file, right-click it, and choose `Run duke.command.Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output:
```
Hello from
____ _
Expand Down
128 changes: 118 additions & 10 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,136 @@

## Features

### Feature-ABC
### Listing
List out all tasks in the tasklist.

Description of the feature.
### Add/Delete tasks
Add different type of tasks into the tasklist.
Delete a task anytime.

### Feature-XYZ
### Find
Find a task using keywords.

Description of the feature.
### Mark done
Mark a task as done.

### Auto-saving
Tasks in the tasklist are saved automatically when program exits, ready to be loaded next time.

## Usage

### `Keyword` - Describe action
### `list`
List out all tasks in the tasklist.

Example of usage:

`list`

Expected outcome:

```
1.[T][X] do wct
2.[E][ ] finish inquiry(at: 6pm)
```

### `done`
Mark a task as done.

Example of usage:

`done 2`

Expected outcome:

```
Nice! I've marked this task as done:
[X] finish inquiry
```

### `todo`
Add a "todo" type task.

Example of usage:

`todo do cs2113 ip`

Expected outcome:

```
Got it. I've added this task:
[T][ ] do cs2113 ip
Now you have 3 tasks in the list
```

### `deadline`
Add a "deadline" type task.

Example of usage:

`deadline cs2113 ip /by tonight`

Describe the action and its outcome.
Expected outcome:

```
Got it. I've added this task:
[D][ ] cs2113 ip(by: tonight)
Now you have 5 tasks in the list
```

Example of usage:
### `event`
Add a "event" type task.

`keyword (optional arguments)`
Example of usage:

`event go to party /at tonight`

Expected outcome:

Description of the outcome.
```
Got it. I've added this task:
[E][ ] go to party(at: tonight)
Now you have 6 tasks in the list
```

### `find`
Find a task in the tasklist that contains the keyword.

Example of usage:

`find cs2113`

Expected outcome:

```
Here are the matching tasks in your list:
1.[T][ ] do cs2113 ip
2.[D][ ] cs2113 ip(by: tonight)
```
expected output

### `delete`
Delete a task in the task list using the index.

Example of usage:

`delete 1`

Expected outcome:

```
Noted. I've removed this task:
[T][X] do wct
Now you have 4 tasks in the list
```

### `bye`
Terminates the program, saves all changes.

Example of usage:

`bye`

Expected outcome:

```
Bye. Hope to see you again soon!
```
1 change: 1 addition & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-cayman
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: duke.command.Duke

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

public class Duke {
private static Parser parser = new Parser();
private static Ui ui = new Ui();
private static TaskList taskList = new TaskList();
private static Storage s = new Storage();

public static void running() {
s.loadFromFile(taskList);
String line;
Scanner in = new Scanner(System.in);
while (true) {
line = in.nextLine();

if (line.equals("list")) {
taskList.listOut();
} else if (line.startsWith("find")) {
taskList.find(line);
} else if (line.startsWith("done")) {
taskList.markDone(line);
} else if (line.startsWith("delete")) {
int index = parser.getIndexForDelete(line);
taskList.deleteTask(index);
} else if (line.startsWith("todo")) {
taskList.addTodo(line);
} else if (line.startsWith("deadline")) {
taskList.addDeadline(line);
} else if (line.startsWith("event")) {
taskList.addEvent(line);
} else if (line.equals("bye")) {
s.saveToFile("data/data.txt", taskList);
return;
} else {
System.out.println("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
}
}
}

public static void main(String[] args) {
ui.sayHi();
running();
ui.sayBye();
}
}
45 changes: 45 additions & 0 deletions src/main/java/duke/command/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package duke.command;

public class Parser {
public static Integer getIndexForDelete(String line) {
return Integer.parseInt(line.substring(7)) - 1;
}

public static Integer getIndexForDone(String line) {
return Integer.parseInt(line.substring(5)) - 1;
}

/**
* Returns the index of the word "/by" in the array of strings generated from the input line.
* @param line The whole line of input from the command line.
* @return Index position of the the word "/by"
*/
public static Integer getIndexForDeadline(String line) {
String[] words = line.split(" ");
int index = 0;
for (int i = 0; i < words.length; i++) {
if (words[i].equals("/by")) {
index = i;
break;
}
}
return index;
}

/**
* Returns the index of the word "/at" in the array of strings generated from the input line.
* @param line The whole line of input from the command line.
* @return Index position of the the word "/at"
*/
public static Integer getIndexForEvent(String line) {
String[] words = line.split(" ");
int index = 0;
for (int i = 0; i < words.length; i++) {
if (words[i].equals("/at")) {
index = i;
break;
}
}
return index;
}
}
108 changes: 108 additions & 0 deletions src/main/java/duke/command/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package duke.command;

import duke.task.Deadline;
import duke.task.Event;
import duke.task.Task;
import duke.task.ToDo;

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

/**
* Represents a storage space for a <code>TaskList</code> object.
*/
public class Storage {
protected File directory;
protected File file;

public Storage() {

directory = new File("data");
if (!directory.exists()) {
directory.mkdirs();
}
//create txt file if file does not exist
file = new File("data/data.txt");
if(!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
}

/**
* Checks the text file set earlier for storage,
* loads the tasks into the input <code>TaskList</code> object.
*
* @param taskList The list of tasks initialized without any content yet.
* @throws IOException If an error occurs from reading or writing to the text file.
*/
public void loadFromFile(TaskList taskList) {
int taskNumber = 0;
try {
File f = new File("data/data.txt");
if (!f.createNewFile()) {
Scanner s = new Scanner(f);
while (s.hasNext()) {
String task = s.nextLine();
String[] words = task.split(" \\| ");
switch (words[0]) {
case "T":
taskList.tasks[taskNumber] = new ToDo(Integer.parseInt(words[1]), words[2]);
taskNumber++;
break;
case "D":
taskList.tasks[taskNumber] = new Deadline(Integer.parseInt(words[1]), words[2], words[3]);
taskNumber++;
break;
case "E":
taskList.tasks[taskNumber] = new Event(Integer.parseInt(words[1]), words[2], words[3]);
taskNumber++;
break;
}
}
}
taskList.taskNumber = taskNumber;
return;
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
return;
}
}

/**
* Saves the current tasks in a <code>TaskList</code> object
* into a text file when the program terminates.
*
* @param filePath Path of the text file used to store the list of tasks.
* @param taskList The list of tasks.
* @throws IOException If an error occurs from reading or writing to the text file.
*/
public static void saveToFile(String filePath, TaskList taskList) {
try {
FileWriter fw = new FileWriter(filePath);
for (int i = 0; i < taskList.taskNumber; i++) {
switch (taskList.tasks[i].getType()) {
case "todo":
fw.write("T" + " | " + taskList.tasks[i].getStatusNumber() + " | " + taskList.tasks[i].getDescription() + System.lineSeparator());
break;
case "deadline":
fw.write("D" + " | " + taskList.tasks[i].getStatusNumber() + " | " + taskList.tasks[i].getDescription() + " | " + taskList.tasks[i].getTime() + System.lineSeparator());
break;
case "event":
fw.write("E" + " | " + taskList.tasks[i].getStatusNumber() + " | " + taskList.tasks[i].getDescription() + " | " + taskList.tasks[i].getTime() + System.lineSeparator());
break;
}
}
fw.close();
} catch (IOException e) {
System.out.println("Something went wrong: " + e.getMessage());
}
}

}
Loading