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

Mor Ben Ami #66

Open
wants to merge 27 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
55 changes: 39 additions & 16 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,52 @@
# User Guide

## Features

### Feature-ABC
Duke is a task tracker for all the user’s tasks,
the application allows the user to see and update all of his tasks divided into three categories - events, to-dos, and deadlines.
For each task, there is adescriptionn and a mark if the task was done or not.
Also, for events and deadlines there is a date description.
The user can update the task lists with different runs, the task listsavese the list each time the userexistst the application.

Description of the feature.

### Feature-XYZ
## Features

Description of the feature.
* help - all the features available
* mark/unmark - mark a task as done or not
* delete - delete a task from the list
* add a task - todo/deadline/event
* find all the tasks with certain words
* list all the tasks currently in the duke application

## Usage

### `Keyword` - Describe action

Describe the action and its outcome.
input one of the features keywords and additional needed information regarding the keyword.

### `Keyword`
* 'help'
Example of usage:

`keyword (optional arguments)`
help
* 'list'
Example of usage:
list
* 'mark' {index of task number to mark as done}
Example of usage:
mark 1
* 'unmark' {index of task number to mark as done}
Example of usage:
unmark 2
* 'delete' {index of task number to delete}
Example of usage:
delete 1
* 'todo' {task description}
Example of usage:
todo plan the weekend
* 'event' {task description} '/at' {date_desciption}
Example of usage:
event F1 /at Singapore
* 'deadline' {task description} '/at' {date_desciption}
deadline CS assignment /by tomorrow
* 'find' {words to search for in the tasks}
find CS

Expected outcome:

Description of the outcome.

```
expected output
```
a text file with all the current tasks in the list
2 changes: 2 additions & 0 deletions duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
T | 1 | be with alon
E | 0 | eat will alon | afternoon
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.Duke

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

public class Duke {
protected static TaskList dukeList = new TaskList();
protected static Storage storage;
public static final String markDone = "mark";
public static final String delete = "delete";
public static final String bye = "bye";
public static final String find = "find";
public static final String list = "list";
public static final String help = "help";
public static final String space = " ";
public static final String unmarkDone = "unmark";
public static final String filename = "/duke.txt";
public static final String emptyString = "";

/**
* Start and runs the duke application,
* checks if the duke file exist if not creates one,
* parsers input from the user and update duke accordingly
* @throws DukeException
*/
public static void run() throws DukeException {
try {
storage = new Storage();
storage.openOrCreateFile();
storage.uploadDataToList();
} catch (DukeException e){
Message.printSystemError();
}
Message.printLogo();
Message.printGreeting();
Ui.input();
}

/**
* calls the run function and starts the duke application
* @param args
*/
public static void main(String[] args) {
try {
run();
} catch (DukeException e) {
Message.printUnknownError();
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/duke/Duke.java.rej
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
diff a/src/main/java/duke/Duke.java b/src/main/java/duke/Duke.java (rejected hunks)
@@ -73,6 +73,8 @@
dukeList.unmarkItemDone(checkInteger(wordsInput));
} else if (wordsInput[0].equals(markDone)) {
dukeList.markItemDone(checkInteger(wordsInput));
+ } else if (wordsInput[0].equals(delete)) {
+ dukeList.deleteTask(checkInteger(wordsInput));
} else {
dukeList.addTask(input);
}
3 changes: 3 additions & 0 deletions src/main/java/duke/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package duke;
public class DukeException extends Exception{
}
118 changes: 118 additions & 0 deletions src/main/java/duke/Message.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package duke;

import duke.task.Task;

public class Message extends Duke {
public static final String helloMessage = "Hello I'm Duke\nwhat can I do for you?\nenter help for input options";
public static final String line = "-----------------------------------------------------------";
public static final String errorLine = "!---------------------------------------------------------!";
public static final String helloFromMessage = "Hello from\n";
public static final String amountOfTasksInList = "Now you have %d tasks in the list.\n";
public static final String fileErrorMessage = "Error using list text, check file";
public static final String invalidInputMessage = "Invalid input, enter again in a correct format";
public static final String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
public static final String beginningDeleteMessage = "Noted. I've removed this task: ";
public static final String unknownErrorMessage = "Sorry, an unknown error occurred ";
public static final String helpMessage = "The following option are available:\n" +
"find {keyword}\nlist\nmark/unmark {index in duke list}\ntodo {description)\n" +
"event {description} /at {time_description}\ndeadline {description} /by {time_description}\n" +
"delete {index in duke list}";
public static final String byeMessage = "Bye. Hope to see you soon";

/**
* prints greeting to the user
*/
public static void printGreeting() {
printHorizontalLine();
System.out.println(helloMessage);
printHorizontalLine();
}

/**
* prints exit message to the user
*/

public static void printingExit() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming this function to printExit rather than printingExit

printHorizontalLine();
System.out.println(byeMessage);
printHorizontalLine();
}


/**
* prints horizontal line to the user
*/

public static void printHorizontalLine() {
System.out.println(line);
}

/**
* print horizontal error line message to the user
*/
public static void printHorizontalErrorLine() {
System.out.println(errorLine);
}

/**
* prints an error message to the user -
* "Invalid input, enter again in a correct format"
*/
public static void printError() {
printHorizontalErrorLine();
System.out.println(invalidInputMessage);
printHorizontalErrorLine();
}


/**
* prints an error the user when there is an
* error with the text file
*/

public static void printSystemError() {
printHorizontalErrorLine();
System.out.println(fileErrorMessage);
printHorizontalErrorLine();
}

/**
* prints the duke logo to the user
*/
public static void printLogo() {
System.out.println(helloFromMessage + logo);
}

/**
* prints an error to the user
* that an unknown error has happened
*/

public static void printUnknownError() {
printHorizontalErrorLine();
System.out.println(unknownErrorMessage);
printHorizontalErrorLine();
}


public static void printHelp() {
System.out.println(helpMessage);
}

/**
* prints to the user that the input task has been deleted
*
* @param taskToDelete
*/
public static void printTaskDeleted(Task taskToDelete) {
System.out.println(beginningDeleteMessage);
System.out.println(taskToDelete);
System.out.printf(amountOfTasksInList, dukeList.getListSize());
}


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

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

public class Storage extends Duke {
public static final String event = "E";
public static final String one = "1";
public static final String zero = "0";
public static final String todo = "T";
public static final String deadline = "D";
public static final String divider = " | ";
public static final String dividerSplit = " \\| ";

private static File file;
public Storage() throws DukeException {
String home = System.getProperty("user.home");
file = new File(home +filename);
openOrCreateFile();
}

/**
* checks if a duke file exists,
* if not, creates one and opens the file
* @throws DukeException
*/
public void openOrCreateFile() throws DukeException {

try {
file.createNewFile();
} catch (IOException e) {
throw new DukeException();
}
}


/**
* uploads list from
* @throws DukeException
*/
public void uploadDataToList() throws DukeException {
try {
Scanner reader = new Scanner(file);
while (reader.hasNextLine()) {
String data = reader.nextLine();
translateLineFromFile(data);
}
} catch (FileNotFoundException e) {
throw new DukeException();
}
}

/**
* marks isDone depending on the task in the file
* @param isDone
* @throws DukeException
*/
private static void markIfDone(String isDone) throws DukeException {
if (isDone.equals(one)) {
dukeList.markItemDone(dukeList.getListSize());
} else if (!isDone.equals(zero)) {
throw new DukeException();
}

}
/**
* updates line by line from file to dukelist
* @param line
* @throws DukeException
*/
public static void translateLineFromFile(String line) throws DukeException {
String[] words = line.split(dividerSplit);
switch (words[0]) {
case todo: {
TaskList.AddTodo(words[2]);
break;
}
case event: {
TaskList.AddEvent(words[2], words[3]);
break;
}
case deadline: {
TaskList.AddDeadline(words[2], words[3]);
break;
}
default: {
throw new DukeException();
}
}
markIfDone(words[1]);
}

/**
* saves from dukelist to file
* @throws DukeException
*/
public static void saveListToFile() throws DukeException {
String home = System.getProperty("user.home");
try {
FileWriter fw = new FileWriter(home+filename);
for (int i = 0; i < dukeList.getListSize(); i++) {
fw.write(dukeList.getTaskFromList(i).getFileFormat() + System.lineSeparator());
}
fw.close();
} catch (IOException e) {
throw new DukeException();
}
}
}
Loading