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

[MichelleLiang0116] iP #200

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d2e1652
Level 0
tingyuliang0116 Jan 20, 2023
875214d
Level 0
tingyuliang0116 Jan 20, 2023
546d365
Level-1 Bye
tingyuliang0116 Jan 25, 2023
e5c4d7f
Level-1 Bye
tingyuliang0116 Jan 25, 2023
eaba19d
Level-1 List
tingyuliang0116 Jan 26, 2023
1097c11
Level-3 MarkAsDone
tingyuliang0116 Jan 26, 2023
2c0ac37
A-CodingStandard
tingyuliang0116 Jan 26, 2023
5e67ea1
Level-4
tingyuliang0116 Feb 1, 2023
0a7d6b0
Level-4
tingyuliang0116 Feb 1, 2023
0bd338f
Level-4
tingyuliang0116 Feb 1, 2023
dcbf7d7
Level-4
tingyuliang0116 Feb 1, 2023
fb2bb85
A-CodingStandard
tingyuliang0116 Feb 1, 2023
37ae4e7
A-CodingStandard
tingyuliang0116 Feb 1, 2023
341d75e
Level-4
tingyuliang0116 Feb 2, 2023
98769f2
A-CodingStandard
tingyuliang0116 Feb 2, 2023
166dbe5
A-CodingStandard
tingyuliang0116 Feb 2, 2023
90bb07f
Level-5
tingyuliang0116 Feb 2, 2023
e81c15c
Merge branch 'master' into branch-Level-5
tingyuliang0116 Feb 8, 2023
189960a
A-Exceptions
tingyuliang0116 Feb 10, 2023
53ca173
A-CodingStandard
tingyuliang0116 Feb 10, 2023
113e069
Level-6
tingyuliang0116 Feb 15, 2023
9922c6d
A-Collections
tingyuliang0116 Feb 15, 2023
3ab622a
Level-7
tingyuliang0116 Feb 15, 2023
379a9f8
A-Jar
tingyuliang0116 Feb 15, 2023
89744ec
A-MoreOOP
tingyuliang0116 Mar 1, 2023
aaf4920
Level-9
tingyuliang0116 Mar 2, 2023
8e2ca77
A-JavaDoc
tingyuliang0116 Mar 2, 2023
52f15f5
Merge pull request #2 from MichelleLiang0116/A-JavaDoc
MichelleLiang0116 Mar 2, 2023
892e5de
Level-9 change
tingyuliang0116 Mar 2, 2023
ffc90fd
Level-9 change
tingyuliang0116 Mar 2, 2023
2691a37
A-UserGuide
tingyuliang0116 Mar 2, 2023
aed8f4a
A-UserGuide
tingyuliang0116 Mar 2, 2023
8a238be
Change some function format
tingyuliang0116 Mar 2, 2023
649fcf5
Merge pull request #3 from MichelleLiang0116/A-JavaDoc
MichelleLiang0116 Mar 3, 2023
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
98 changes: 91 additions & 7 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

## Features

### Feature-ABC
### Feature-Duke

Description of the feature.

### Feature-XYZ

Description of the feature.
Duke is a app helps manage tasks and deadlines, optimized for use via a
Command Line Interface (CLI)

## Usage

### `Keyword` - Describe action
### `list` - Describe action

Describe the action and its outcome.

Expand All @@ -27,3 +24,90 @@ Description of the outcome.
```
expected output
```

### `bye` - Describe action

Describe the action and its outcome.

Example of usage:

`keyword (optional arguments)`

Expected outcome:

Description of the outcome.

```
expected output
```
### `find` - Give users a way to find a task by searching for a keyword.

Example of usage:

`find book`

Expected outcome:

```
Here are the matching tasks in your list:
1.[T][X] read book
2.[D][X] return book (by: June 6th)
```

### `todo` - tasks without any date/time attached to it

Example of usage:

`todo borrow book`

Expected outcome:

```
Got it. I've added this task:
[T][ ] borrow book
Now you have 5 tasks in the list.

```

### `event` - tasks that start at a specific date/time and ends at a specific date/time

Example of usage:

`event project meeting /from Mon 2pm /to 4pm`

Expected outcome:

```
Got it. I've added this task:
[E][ ] project meeting (from: Mon 2pm to: 4pm)
Now you have 7 tasks in the list.
```

### `deadline` - tasks that need to be done before a specific date/time

Example of usage:

`deadline return book /by Sunday`

Expected outcome:


```
Got it. I've added this task:
[D][ ] return book (by: Sunday)
Now you have 6 tasks in the list.
```

### `delete` - delete task

Example of usage:

`delete 3`

Expected outcome:

```
Noted. I've removed this task:
[E][ ] project meeting (from: Aug 6th 2pm to: 4pm)
Now you have 4 tasks in the list.
```
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 {

Choose a reason for hiding this comment

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

Inheritance to split task types is well done.

private final String by;

/**
* @param description description of the task
* @param by the deadline of the task
*/
public Deadline(String description, String by) {
super(description);
this.by = by;
}

/**
* @return convert to formatted string
*/
@Override
public String toString() {
return "[D]" + super.toString() + " (by:" + by + ")";
}
}
39 changes: 32 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
import java.io.IOException;

public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
private final Storage storage;
private final TaskList tasks;
private final UI ui;
private final Parser parser = new Parser();

/**
* Create the Duke Object
* @param filePath an String giving the base location of the file
*/
public Duke(String filePath) throws IOException {
ui = new UI();
storage = new Storage(filePath);
this.tasks = new TaskList(storage.load());
}

/**
* Start to run the Duke application
*/
public void run() throws IOException{
ui.showWelcome();
while (!parser.isExit()) {
String fullCommand = ui.readCommand();
ui.showLine();
parser.parse(fullCommand);
}
}

public static void main(String[] args) throws IOException {
new Duke("duke.txt").run();
}

}
24 changes: 24 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public class Event extends Task {
private final String from;
private final String to;

/**
* @param description description of the task
* @param from the start day of the task
* @param to the end day of the task
*/
public Event(String description, String from, String to) {
super(description);
this.from = from;
this.to = to;
}

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

97 changes: 97 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import java.io.IOException;
import java.util.ArrayList;

public class Parser {
private boolean exit = false;

/**
* Parse the user command and store to the taskList if applicable
* @param command the user input
*/
public void parse(String command) throws IOException {
if (command.equalsIgnoreCase("list")) {
System.out.println("Here are the tasks in your list:");
for (int i = 0; i < TaskList.list.size(); i++) {
System.out.println(i + 1 + "." + TaskList.list.get(i).toString());
}
UI.showLine();
} else if (command.equalsIgnoreCase("bye")) {
UI.showBye();
Storage.save(TaskList.list);
this.exit = true;
} else if (command.toLowerCase().contains("mark")) {
try {
String[] split = command.split("\\s+");
int toMark = Integer.parseInt(split[1]);
if (split[0].equalsIgnoreCase("mark")) {
TaskList.list.get(toMark - 1).markAsDone();
System.out.println("Nice! I've marked this task as done: ");
} else {
TaskList.list.get(toMark - 1).markAsUnDone();
System.out.println("OK, I've marked this task as not done yet: ");
}
System.out.println(TaskList.list.get(toMark - 1).toString() + '\n' + UI.lineBreak);
} catch (NullPointerException e) {
System.out.println("Item is not in list!");
}
} else if (command.toLowerCase().contains("delete")) {
String[] split = command.split("\\s+");
int toDelete = Integer.parseInt(split[1]);
TaskList.taskListDelete(toDelete - 1);
} else {
Task t;
if (command.toLowerCase().contains("deadline")) {
try {
String description = command.substring(command.indexOf(' ') + 1, command.indexOf('/'));
String ddl = command.substring(command.indexOf('/') + 1);
String by = ddl.replace("by", "");
t = new Deadline(description, by);
TaskList.taskListAdd(t);
} catch (StringIndexOutOfBoundsException e) {
System.out.println("☹ OOPS!!! The description of a deadline cannot be empty." + '\n' + UI.lineBreak);
}
} else if (command.toLowerCase().contains("event")) {
try {
String substring = command.substring(command.indexOf(' ') + 1);
String[] info = substring.split("/");
String from = info[1].replace("from", "");
String to = info[2].replace("to", "");
t = new Event(info[0], from, to);
TaskList.taskListAdd(t);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("☹ OOPS!!! The description of a event cannot be empty." + '\n' + UI.lineBreak);
}
} else if (command.toLowerCase().contains("todo")) {
if (command.indexOf(' ') == -1) {
System.out.println("☹ OOPS!!! The description of a todo cannot be empty." + '\n' + UI.lineBreak);
} else {
String description = command.substring(command.indexOf(' ') + 1);
t = new Todo(description);
TaskList.taskListAdd(t);
}
} else if (command.toLowerCase().contains("find")) {
String substring = command.substring(command.indexOf(' ') + 1);
ArrayList<Task> result=new ArrayList<>();
for(Task k:TaskList.list){
if(k.description.contains(substring)){
result.add(k);
}
}
System.out.println("Here are the matching tasks in your list:");
for(int i=0;i<result.size();i++){
System.out.println(i + 1 + "." + result.get(i).toString());
}
UI.showLine();
} else {
System.out.println("☹ OOPS!!! I'm sorry, but I don't know what that means :-(" + '\n' + UI.lineBreak);
}
}
}

/**
* @return check if the user want to stop the program
*/
public boolean isExit() {
return exit;
}
}
29 changes: 29 additions & 0 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public class Storage {
public static String filePath;

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

public static String load() {
return filePath;
}

/**
* to save the taskList to txt file
*
* @param list the whole taskList created by user
*/
public static void save(ArrayList<Task> list) throws IOException {
FileWriter writer = new FileWriter(filePath, false);
for (int i = 0; i < list.size(); i++) {
writer.write(list.get(i).toString());
writer.write("\r\n");
}
writer.close();
}
}
38 changes: 38 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
public class Task {
public final String description;
protected boolean isDone;

public Task(String description) {
this.description = description;
this.isDone = false;
}

/**
* @return the Icon of current task
*/
public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

/**
* Mark the task to done
*/
public void markAsDone() {
this.isDone = true;
}

/**
* Mark the task to unDone
*/
public void markAsUnDone() {
this.isDone = false;
}

/**
* @return convert to formatted string
*/
@Override
public String toString() {
return "[" + getStatusIcon() + "] " + description;
}
}
Loading