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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ bin/

/text-ui-test/ACTUAL.TXT
text-ui-test/EXPECTED-UNIX.TXT

wen-storage.txt
93 changes: 67 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,67 @@
# 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.

## Setting up in Intellij

Prerequisites: JDK 17, update Intellij to the most recent version.

1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first)
1. Open the project into Intellij as follows:
1. Click `Open`.
1. Select the project directory, and click `OK`.
1. If there are any further prompts, accept the defaults.
1. Configure the project to use **JDK 17** (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.
1. 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:
```
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|
```

**Warning:** Keep the `src\main\java` folder as the root folder for Java files (i.e., don't rename those folders or move Java files to another folder outside of this folder path), as this is the default location some tools (e.g., Gradle) expect to find Java files.
# Wen: Your assistant chatbot!

This is Wen, your personal assistant for school-related tasks. Keep track of all your scheduling needs here!

## User Guide

### `todo`
Create a new to-do list item.
#### Example
```sh
todo Get some milk
```

### `deadline`
Create a new deadline.
#### Parameters
- `/by` - The deadline to complete this task by.
#### Example
```sh
deadline Complete CS2113 weekly quiz /by 12pm
```

### `event`
Create a new event.
#### Parameters
- `/from` - The start time of the event.
- `/to` - The end time of the event.
#### Example
```sh
deadline Join group meeting /from 5pm /to 8pm
```

### `list`
Displays all of your tasks.
#### Example
```sh
list
```

### `find`
Find a task with the search query in the description.
#### Parameters
The word you want to search for
#### Example
```sh
find CS2113
```

### `mark` & `unmark`
Mark one of your tasks as done.
#### Parameters
The index of the task; you can find the task index by using `list` or `find`
#### Example
```sh
mark 5
unmark 3
```

### `delete`
Deletes one of your tasks
#### Parameters
The index of the task; you can find the task index by using `list` or `find`
#### Example
```sh
delete 4
```

20 changes: 20 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public class Deadline extends Task {

protected String by;

public Deadline(String description, String by) {
super(description);
this.by = by;
}

public Deadline(String description, String by, boolean done) {
super(description);
this.by = by;
this.isDone = done;
}

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
}
}
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

23 changes: 23 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class Event extends Task {

protected String from;
protected String by;

public Event(String description, String from, String by) {
super(description);
this.from = from;
this.by = by;
}

public Event(String description, String from, String by, boolean done) {
super(description);
this.from = from;
this.by = by;
this.isDone = done;
}

@Override
public String toString() {
return "[E]" + super.toString() + " (from: " + from + " to: " + by + ")";
}
}
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: Wen

52 changes: 52 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import java.util.HashMap;
import java.util.Map;

public class Parser {
private final String commandName;
private final Map<String, String> commandArgs;
private final String commandMainArg;


Parser(String input) {

commandName = input.split(" ", 2)[0];
String commandArgsString = input.split(" ", 2).length > 1 ? input.split(" ", 2)[1] : "";

commandArgs = new HashMap<>();

String[] commandParts = commandArgsString.split("/");
if (commandParts.length > 1) {
for (int i = 1; i < commandParts.length; i++) {
String argName = commandParts[i].split(" ")[0].trim();
String argValue = commandParts[i].split(" ").length > 1 ? commandParts[i].split(" ", 2)[1].trim() : "";
commandArgs.put(argName, argValue);
}
}
commandMainArg = commandParts[0].trim().isEmpty() ? null : commandParts[0].trim();

}

public boolean equals(String name) {
return commandName.equals(name);
}

public String getName() {
return commandName;
}

public String getArg(){
return commandMainArg;
}

public String getArg(String arg) {
return commandArgs.get(arg);
}

public boolean hasArg() {
return commandMainArg != null;
}
public boolean hasArg(String arg) {
return commandArgs.containsKey(arg);
}

}
90 changes: 90 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* A task where users can mark as done/undone, with different specific types
*/
public class Task {
protected String description;
protected boolean isDone;

/**
* Create a new task
* @param description basic description
*/
public Task(String description) {
this.description = description;
this.isDone = false;
}

/**
* Parse the task from a string, usually for reading saved tasks.
* @param description The string to parse the task from
* @return a new task object, one of three types (Deadline, Event, Todo)
*/
public Task fromString(String description) {
char taskType = description.charAt(1);
boolean taskDone = description.charAt(4) == 'X';

switch (taskType) {
case 'D':
String deadlineDesc = description.substring(7);
String deadline = "";
int deadlineIndex = description.indexOf(" (by: ", 1);
if (deadlineIndex != -1) {
deadlineDesc = description.substring(7, deadlineIndex);
deadline = description.substring(deadlineIndex + 6, description.length() - 1);
}
return new Deadline(deadlineDesc, deadline, taskDone);

case 'E':
String eventDesc = description.substring(7);
String from = "";
String to = "";

int fromIndex = description.indexOf(" (from: ", 1);
int toIndex = description.indexOf(" to: ", 1);
if (fromIndex != -1 && toIndex != -1) {
eventDesc = description.substring(7, fromIndex);
from = description.substring(fromIndex + 8, toIndex);
to = description.substring(toIndex + 5, description.length() - 1);
}

return new Event(eventDesc, from, to, taskDone);

case 'T': // todo
default: // just in case ??
return new Todo(description.substring(7), taskDone);
}
}

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

public void print() {
System.out.print("[" + (isDone ? "X" : " ") + "] ");
System.out.println(description);
}

/**
* Get the task description
* @return String form of task description
*/
public String getDescription() {
return description;
}

/**
* Gets a simplified representation of the task
* @return A string form of the task, including its done state
*/
public String toString() {
return "[" + (isDone ? "X" : " ") + "] " + description;
}

/**
* Set the task to be done or not
* @param done New state of task to be set
*/
public void setDone(boolean done){
isDone = done;
}
}
Loading