Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Manifest-Version: 1.0

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.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.duke.java` file, right-click it, and choose `Run duke.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
73 changes: 61 additions & 12 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,77 @@

## Features

### Feature-ABC
### Feature 1: Add Tasks

Description of the feature.
There are 3 types of tasks: **Todo, Event, and Deadline**.

### Feature-XYZ
- Create a Todo item by entering `todo DESCRIPTION`

- e.g. todo Write User Guide

- Create an Event item by entering `event DESCRIPTION /at EVENTDATE`

- e.g. event CS2113 Tutorial /at 04032022

- Create a Deadline item by entering `deadline DESCRIPTION /by DUEDATETIME`

- e.g. Submit IP /by 04032022 0000

Description of the feature.
### Feature 2: List all Tasks

## Usage
Print a list of all tasks and their statuses.

`list`

### Feature 3: Mark/Unmark Tasks

Mark tasks as completed as you complete them!

### `Keyword` - Describe action
- `mark INDEX`
- e.g. `mark 1`
- e.g. `unmark 2`

Describe the action and its outcome.

Example of usage:
### Feature 4: Delete Tasks

`keyword (optional arguments)`
Remove a task that shouldn't be there!

Expected outcome:
`delete INDEX`

Description of the outcome.
### Feature 5: List all Tasks

Print a list of all tasks and their statuses.

`list`

## Usage

`todo Write User Guide`
`event CS2113 Tutorial /at 04032022`
`Submit IP /by 04032022 0000`

```Expected Outcome
____________________________________________________________
Here are the tasks in your list:
1. [T][ ] Write User Guide
2. [E][ ] CS2113 Tutorial (at: 03 Mar 2022)
3. [D][ ] Submit IP (by: 04 Mar 2022 00:00)
____________________________________________________________
```

`mark 2`
```
expected output
____________________________________________________________
Nice! I've marked this task as done:
[E][X] CS2113 Tutorial (at: 03 Mar 2022)
____________________________________________________________
```

`delete 2`
```
Noted. I've removed this task:
[E][X] CS2113 Tutorial (at: 03 Mar 2022)
Now you have 2 tasks in the list
____________________________________________________________
```

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-slate
Binary file added ip.zip
Binary file not shown.
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

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

public class Duke {

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

public Duke() {
storage = new Storage("list.txt");
tasks = new TaskList(storage.convertFileToList());
ui = new Ui();
}

public void run() {
ui.showWelcome();
boolean isExit = false;
while (!isExit) {
try {
ui.showLine();
String command = ui.getUserInput();
Command newCommand = Parser.parse(command);
newCommand.execute(tasks, ui, storage);
isExit = newCommand.getIsExit();
} catch (DukeException e) {
ui.showError(e.getMessage());
} finally {
ui.showLine();
}
}
}

public static void main(String[] args) {
Duke duke = new Duke();
duke.run();
}
}
7 changes: 7 additions & 0 deletions src/main/java/duke/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package duke;

public class DukeException extends Exception {
public DukeException(String message) {
super(message);
}
}
83 changes: 83 additions & 0 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package duke;

import duke.command.AddCommand;
import duke.command.Command;
import duke.command.DeleteCommand;
import duke.command.ExitCommand;
import duke.command.FindCommand;
import duke.command.ListCommand;
import duke.command.MarkCommand;
import duke.task.Deadline;
import duke.task.Event;
import duke.task.Todo;

public class Parser {

public static Command parse(String command) throws DukeException {

String[] initialParse = command.split(" ");
int taskIndexString = 1;
String commandType = initialParse[0];
String description;
String processedString[];
int taskIndex;

switch (commandType) {
case "list":
return new ListCommand();
case "todo":
if (initialParse.length < 2) {
throw new DukeException("The description of a todo cannot be empty.");
}
description = command.split("todo")[1].trim();
return new AddCommand(new Todo(description));
case "deadline":
processedString = command.split("/by");
return new AddCommand(processDeadline(processedString));
case "event":
processedString = command.split("/at");
return new AddCommand(processEvent(processedString));
case "mark":
taskIndex = Integer.parseInt(initialParse[taskIndexString]) - 1;
return new MarkCommand(taskIndex, true);
case "unmark":
taskIndex = Integer.parseInt(initialParse[taskIndexString]) - 1;
return new MarkCommand(taskIndex, false);
case "delete":
taskIndex = Integer.parseInt(initialParse[taskIndexString]) - 1;
return new DeleteCommand(taskIndex);
case "find":
String searchTerm = initialParse[taskIndexString].trim();
return new FindCommand(searchTerm);
case "bye":
return new ExitCommand();
default:
throw new DukeException("Invalid command given");
}
}

private static String processTime(String[] processedString, String separator) {
final int TIMEINDEX = 1;
String time = processedString[TIMEINDEX].trim();
return time;
}

private static String processDescription(String[] processedString, String separator) {
final int PRETIMEINDEX = 0;
final int DESCRIPTIONINDEX = 1;
String description = processedString[PRETIMEINDEX].split(separator)[DESCRIPTIONINDEX].trim();
return description;
}

private static Event processEvent(String[] processedString) {
String at = processTime(processedString, "/at");
String task = processDescription(processedString, "event");
return new Event(task, at);
}

private static Deadline processDeadline(String[] processedString) {
String by = processTime(processedString, "/by");
String task = processDescription(processedString, "deadline");
return new Deadline(task, by);
}
}
100 changes: 100 additions & 0 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package duke;

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

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

/**
* Represents the controller to parse and write to a save file for tasks
*/
public class Storage {
private String filePath;


public Storage(String filePath) {
this.filePath = filePath;
}

public void convertListToFile(ArrayList<Task> list) {
String text = "";
for (int i = 0; i < list.size(); i++) {
Task currentTask = list.get(i);
text = text + currentTask.toString() + System.lineSeparator();
}
try {
FileWriter fw = new FileWriter(filePath);
fw.write(text);
fw.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}

public ArrayList<Task> convertFileToList() {
ArrayList<Task> list = new ArrayList<>();
File f = new File(filePath);
try {
Scanner s = new Scanner(f);
while (s.hasNext()) {
String currentLine = s.nextLine();
String[] arrayElements = currentLine.split("\\|");
String taskType = arrayElements[0].trim();
Task newTask;
switch (taskType) {
case "T":
newTask = convertTodo(arrayElements);
list.add(newTask);
break;
case "D":
newTask = convertDeadline(arrayElements);
list.add(newTask);
break;
case "E":
newTask = convertEvent(arrayElements);
list.add(newTask);
break;
default:
break;
}
}
return list;
} catch (FileNotFoundException e) {
return list;
}
}

private String getDescription(String[] arrayElements) {
int descriptionIndex = 2;
return arrayElements[descriptionIndex].trim();
}

private boolean getIsDone(String[] arrayElements) {
int booleanIndex = 1;
return arrayElements[booleanIndex].trim().equals("1");
}

private String getTime(String[] arrayElements) {
int timeIndex = 3;
return arrayElements[timeIndex].trim();
}

private Todo convertTodo(String[] arrayElements) {
return new Todo(getDescription(arrayElements), getIsDone(arrayElements));
}

private Deadline convertDeadline(String[] arrayElements) {
return new Deadline(getDescription(arrayElements), getIsDone(arrayElements), getTime(arrayElements));
}

private Event convertEvent(String[] arrayElements) {
return new Event(getDescription(arrayElements), getIsDone(arrayElements), getTime(arrayElements));
}
}
Loading