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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ bin/

/text-ui-test/ACTUAL.txt
text-ui-test/EXPECTED-UNIX.TXT
src/main/java/IllegalShapeException.java
src/main/java/Main.java
src/main/java/temp.java
41 changes: 20 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
# Duke project template
# Smart XiaoAi TongXue

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.
This is a task management Java project. It's named after the Smart XiaoAi TongXue. Given below are instructions on how to use it.

## Setting up in Intellij
## list
list all tasks in the task list
## todo {task description}
add Todo task
## deadline {task description} /by {time}
add Deadline
## Event {task description} /at {time}
add Event
## mark {index}
mark task
## unmark {index}
unmark task
## delete {index}
delete task from list
## find {text}
find matching tasks containing the {text}
## bye
exit the program

Prerequisites: JDK 11, 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 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:
```
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|
```
43 changes: 28 additions & 15 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
# User Guide
Smart XiaoAI is a task management app use via a Command Line Interface(CLI).

## Features
----
The file path: task-file

### Feature-ABC
----

Description of the feature.

### Feature-XYZ
## Features

Description of the feature.
### Feature- list all task

## Usage
'list'
list all tasks

### `Keyword` - Describe action
### Feature- Add a todo task
'todo {description}'

Describe the action and its outcome.
### Feature- Add a deadline task
'deadline {description} /by {time}'

Example of usage:
### Feature- Add a event task
'event {description} /at {time}'

`keyword (optional arguments)`
### Feature- Mark a task as done
'mark {index}'

Expected outcome:
### Feature- Unmark a task
'unmark {index}'

Description of the outcome.
### Feature- Unmark a task
'unmark {index}'

```
expected output
```
### Feature- remove a task
'delete {index}'

### Feature- Find matching tasks
'find {text}'

### Feature- Exit program
'bye'
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: controller.Duke

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

import controller.Storage;
import controller.TaskList;
import controller.UI;
import exception.DukeException;
import exception.InvalidCommandException;
import exception.NoDescriptionException;
import exception.NoTimeException;
import task.Task;
import task.Todo;

public class AddCommand extends Command {
String input;
String action;

public AddCommand(String action, String input) {
super();
this.input = input;
this.action =action;
}

/**
* Add specific task into task list according to the input
* Show task count
* Save the task list data into file
* @param tasks task list
* @param ui user interface
* @param storage storage.
*/

public void execute(TaskList tasks, UI ui, Storage storage) throws DukeException {
String description = "";
String time = "";
String[] info = new String[2];
switch (action){
case "todo":
description = input.replace("todo", "").trim();
if(description == null || input.isEmpty()){
throw new NoDescriptionException();
}
tasks.addNewTodo(description);
break;
case "event":
info = getInfo("event");
description = info[0];
time = info[1];
tasks.addNewEvent(description,time);
break;
case "deadline":
info = getInfo("deadline");
description = info[0];
time = info[1];
tasks.addNewDeadline(description,time);
break;
default:
throw new InvalidCommandException();
}
ui.showAdd();
ui.showTask(tasks.getNewAdd());
ui.showTaskCount(tasks.getCount());
storage.save(tasks.getTaskList());
}

private String[] getInfo(String action) throws DukeException {
int descriptionIdx = input.indexOf(" ");
if(descriptionIdx == -1){
throw new NoDescriptionException();
}
int timeIdx = 0;
if(action.equals("event")) {
timeIdx = input.indexOf("/at");
}else if(action.equals("deadline")){
timeIdx = input.indexOf("/by");
}
if(timeIdx == -1){
throw new NoTimeException();
}
String description = input.substring(descriptionIdx+1, timeIdx).trim();
String time = input.substring(timeIdx+4).trim();
String[] res = new String[2];
res[0] = description;
res[1] = time;
return res;
}
public boolean isExit(){
return false;
}

}
12 changes: 12 additions & 0 deletions src/main/java/command/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package command;

import controller.Storage;
import controller.TaskList;
import controller.UI;
import exception.DukeException;
import exception.NoDescriptionException;

public abstract class Command {
public abstract void execute(TaskList tasks, UI ui, Storage storage) throws NoDescriptionException, DukeException;
public abstract boolean isExit();
}
42 changes: 42 additions & 0 deletions src/main/java/command/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package command;

import controller.Helper;
import controller.Storage;
import controller.TaskList;
import controller.UI;
import exception.DukeException;

public class DeleteCommand extends Command{
private static final String INDENT = " ";
String command;
public DeleteCommand(String command) {
this.command=command;
}

/**
* Remove task from task list according to the input
* Show task count
* Save the task list data into file
* @param tasks task list
* @param ui user interface
* @param storage storage.
*/

public void execute(TaskList tasks, UI ui, Storage storage) throws DukeException {
String idxInString = command.replace("delete","").trim();
Helper.checkIndex(idxInString,tasks);
int idx = Integer.parseInt(idxInString)-1;
ui.showDelete();
ui.showTask(tasks.removeTaskByIdx(idx));
ui.showList();
for(int i = 0; i<tasks.getCount(); i++){
System.out.println(INDENT+(i+1) + "." + tasks.getTaskByIdx(i));
}
ui.showTaskCount(tasks.getCount());
storage.save(tasks.getTaskList());
}

public boolean isExit(){
return false;
}
}
22 changes: 22 additions & 0 deletions src/main/java/command/ExitCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package command;

import controller.Storage;
import controller.TaskList;
import controller.UI;

public class ExitCommand extends Command{
/**
* Show Bye message.
* Save the task list data into file.
* @param tasks task list.
* @param ui user interface.
* @param storage storage.
*/
public void execute(TaskList tasks, UI ui, Storage storage){
ui.showBye();
storage.save(tasks.getTaskList());
}
public boolean isExit(){
return true;
}
}
41 changes: 41 additions & 0 deletions src/main/java/command/FindCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package command;

import controller.Storage;
import controller.TaskList;
import controller.UI;
import task.Task;

import javax.naming.directory.InitialDirContext;
import java.util.ArrayList;

public class FindCommand extends Command{
private static final String INDENT = " ";
private String text;
public FindCommand(String fullCommand) {
int textIdx = 1 + fullCommand.indexOf(" ");
text = fullCommand.substring(textIdx);
}
public void execute(TaskList tasks, UI ui, Storage storage){
ArrayList<Task> targetList = new ArrayList<>();
for(Task task : tasks.getTaskList()){
if(task.toString().contains(text)){
targetList.add(task);
}
}

if(targetList.size() ==0){
ui.showNotFound();
return;
}
ui.showFound();
int i = 1;
for(Task task : targetList){
System.out.println(INDENT + (i++)+ "." + task.toString());
}
}

public boolean isExit(){
return false;
}

}
30 changes: 30 additions & 0 deletions src/main/java/command/ListCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package command;


import controller.Storage;
import controller.TaskList;
import controller.UI;

public class ListCommand extends Command {
private static final String INDENT = " ";

/**
* Print out all task in the task list.
* @param taskList task list.
* @param ui user interface.
* @param storage storage.
*/
public void execute(TaskList taskList, UI ui, Storage storage){
if(taskList.getCount() == 0){
ui.showEmptyList();
return;
}
ui.showList();
for(int i = 0; i<taskList.getCount(); i++){
System.out.println(INDENT+(i+1) + "." + taskList.getTaskByIdx(i));
}
}
public boolean isExit(){
return false;
}
}
Loading