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

[Jia Juin] iP #50

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
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 data/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
T | 1 | borrow book
E | 0 | project meeting|Mon 2-4pm
173 changes: 163 additions & 10 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,173 @@
# User Guide
# User Guide for Application SHEENA

## Features

### Feature 1
Description of feature.
### 1. Add a todo task

## Usage
Users are able to add one specific task every time they type "todo" command
A capital letter "T" will shown when you successfully added the task.
A tick or cross will shown besides the capital letter "E" to indicate whether the task is done by the user.

### `Keyword` - Describe action
"todo" - to indicate the system that this is a todo task
"description" - describe the task

Describe action and its outcome.

Example of usage:
Format: todo description

`keyword (optional arguments)`
Eg: todo Love Sheena.

Expected outcome:
IMPORTANT: User must provide a description.

`outcome`
Outcome:
[T].[tick / cross] todo Love Sheena


### 2. Add an Event task

Users are able to add one specific event task every time they type "event" command
We will use /at to differentiate the time
A capital letter "E" will shown when you successfully added the event.
A tick or cross will shown besides the capital letter "E" to indicate whether the event is done by the user.


"event" - to indicate the system that this is a todo task
"/at" - to indicate the system that the time is behind the /at
"description" - describe the event
"time" - describe the details for time (at: Mon 2-4pm)

Format: event (description) /at (time)

Eg: event Love Coco /at Mon 2-4pm

IMPORTANT: User must provide a description and time.

Outcome:
[E][tick / cross] event Love Coco (at: Mon 2-4pm)



### 3. Add a Deadline task

Users are able to add one specific deadline task every time they type "event" command
We will use /by to differentiate the day
A capital letter "D" will shown when you successfully added the deadline.
A tick or cross will shown besides the capital letter "E" to indicate whether the task is done by the user.


"event" - to indicate the system that this is a todo task
"/by" - to indicate the system that the day is behind the /by
"description" - describe the event
"day" - describe the details for day (Eg: Sunday)

Format: event (description) /by (day)

Eg: deadline I love you Sheena /by Sunday

IMPORTANT: User must provide a description and day.

Outcome:
[D][tick / cross] event I love you Sheena (by: Sunday)


### 4. List Down the task List

Users are able to retrieve the task that they had saved.

"list" - to list down the task.

Format: list

Eg: list

Outcome:

Sheena: Yay! Now you have these ~
----------------------------
Sheena: Well, you have these items in your list:

1. [T][✓]buy food
2. [T][✓]miss Sheena
3. [T][✘]love Sheena forever
4. [T][✘]I love you Coco
----------------------------
Sheena: Yay! 4 tasks listed!


### 5. Delete A Task.

Users are able to delete one specific event task every time they type "delete" command


"delete" - to indicate the system that this is a delete function
"taskNumber" - indicate the index number for the specific task (eg: 5)

Format: delete taskNumber

Eg: delete 5

IMPORTANT: User must provide a description and time.

Outcome:

Sheena: YAY! You deleted task: [T][✘]buy books !

Now you have (taskNumber-1) tasks in your list ~


### 6. Find a task

Users are able to add one specific event task every time they type "find" command


"find" - to indicate the system that this is a todo task
"description" - describe the thing you want to find

Format: find (description)

Eg: find Sheena

IMPORTANT: User must provide a description and time.

Outcome:
Sheena: Yay! Here are the matching tasks in your list:

----------------------------
Sheena: Well, you have these items in your list:

1. [T][✓]miss Sheena
2. [T][✘]love Sheena forever
----------------------------
Sheena: Yay! 2 tasks listed!


### 7. Clear the list

Users are able to clear the task list


"clear" - to indicate the system that user is clearing the task

Format: clear

Eg: clear

Outcome:
Sheena: So sad but yeah the list has been cleared..


### 8. Exit the program

Users are able to exit program. The task will be saved in a text file (eg: duke.txt)


"bye" - to indicate the system that user is going to exit the program

Format: bye

Eg: bye

Outcome:

Sheena: Let me save down everything ^^

Sheena: I will miss you! Hope to see you again soon!
4 changes: 4 additions & 0 deletions duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
T | 1 | buy food
T | 1 | miss Sheena
T | 0 | love Sheena forever
T | 0 | I love you Coco
82 changes: 75 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,78 @@
import duke.command.Command;
import duke.command.CommandOption;
import duke.command.CommandBye;
import duke.taskList.TaskList;
import duke.parser.Parser;
import duke.storage.Storage;
import duke.storage.Storage.StorageFilePathException;
import duke.Ui.TextUi;

/**
* The main program should keep it short
* Exits when command "bye" stated
*
*/
public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);

private TextUi ui;
public Storage storage;
private TaskList list;

public static void main(String... launchArgs) {
new Duke().runTheProgram(launchArgs);
}

public void runTheProgram(String[] launchArgs) {
start(launchArgs);
runCommand();
exit();
}

private void start(String[] launchArgs) {
try {
this.ui = new TextUi();
this.storage = initializeStorage(launchArgs);
this.list = storage.load();
ui.welcomeMessage(storage.getPath());
ui.storedList();
} catch (Storage.StorageOperationException | StorageFilePathException e) {
ui.failed();
throw new RuntimeException(e);
}
}

private void exit(){
ui.goodbye();
System.exit(0);
}

/** run the program until the user type "bye" */
private void runCommand(){
Command command;
do {
String userCommand = ui.getUserCommand();
command = new Parser().parseCommand(userCommand);
CommandOption result = executeCommand(command);
ui.printResult(result);
} while (!CommandBye.isExit(command));
}

private CommandOption executeCommand(Command command) {
try {
command.setData(list);
storage.save(list);
return command.execute();
} catch (Exception e) {
ui.PresentMessages(e.getMessage());
throw new RuntimeException(e);
}

}

private Storage initializeStorage(String[] launchArgs) throws StorageFilePathException {
boolean isStorageFileSpecified = launchArgs.length > 0;
return !isStorageFileSpecified ? new Storage() : new Storage(launchArgs[0]);
}


}
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

71 changes: 71 additions & 0 deletions src/main/java/duke/Ui/TextUi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package duke.Ui;
import duke.command.CommandOption;
import duke.taskList.TaskList;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class TextUi {

private final Scanner in;
private final PrintStream out;

public TextUi() {
this(System.in, System.out);
}

public TextUi(InputStream in, PrintStream out) {
this.in = new Scanner(in);
this.out = out;
}

public String getUserCommand() {
out.print("Sheena: Please enter your command ~ \n");
String Input = in.nextLine();
PresentMessages("Sheena: Yay! This is your input (" + Input + ") !");
return Input;
}

public void welcomeMessage(String storageFile) {
String Info = String.format(USING_STORAGE, storageFile);
PresentMessages(WELCOME, Info);
}

public void goodbye() {
PresentMessages(GOODBYE);
}

public void failed() {
PresentMessages(FAILED);
}

/**
* Shows message(s) to the user
*/
public void PresentMessages(String... message) {
for (String a : message) {
out.println(a);
}
}

public void printResult(CommandOption result) {
PresentMessages(result.feedback);
}


public void storedList() {
if (TaskList.size() <= 0) {
System.out.println("\nSheena: Hmm nothing here.\nSheena: It's okay! Let me create a new one!");
} else {
System.out.println("---------------------------------------------------------");
System.out.println("Sheena: Yay! I successfully retreat your previous list!");
TaskList.storedTaskList();
System.out.println("---------------------------------------------------------");
}
}

public static final String GOODBYE = "Sheena: I will miss you! Hope to see you again soon!";
public static final String FAILED = "Sheena: Erm can't run now. Gonna Exit first.";
public static final String WELCOME = "Hello! I'm Sheena ^^ \nWhat can I do for you ?";
public static final String USING_STORAGE = "Sheena: using storage file ( %1$s )";
}
42 changes: 42 additions & 0 deletions src/main/java/duke/command/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package duke.command;

import duke.taskList.TaskList;
import duke.task.Task;
import java.util.ArrayList;

public class Command {
private String nameOfCommand;
private String Argument;
protected TaskList taskList;


public static final String MESSAGE_TASKS_LISTED_OVERVIEW = "Sheena: Yay! %1$d tasks listed!";

public static String getMessageForTaskListShownSummary(ArrayList<Task> tasksDisplayed) {
return String.format(MESSAGE_TASKS_LISTED_OVERVIEW, tasksDisplayed.size());
}

public CommandOption execute() {
throw new UnsupportedOperationException("This method must be implemented by child classes");
}

public void setData(TaskList taskList) {
this.taskList = taskList;
}

public String getCommandName() {
return nameOfCommand;
}

public void setCommandName(String commandName) {
nameOfCommand = commandName;
}

public String getArgs() {
return Argument;
}

public void setArgs(String args) {
Argument = args;
}
}
Loading