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

[Wang Zhihuang] iP #181

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
60a88c0
Level-0: Greet
zh1huang Aug 15, 2021
8747f62
Level-1
zh1huang Aug 25, 2021
ab4602c
Level 2
zh1huang Aug 25, 2021
b43adfa
Level-3
zh1huang Aug 25, 2021
68d69b3
A-CodingStandard
zh1huang Aug 26, 2021
c3cd436
Minor typo changes
zh1huang Aug 26, 2021
6b63884
Level-4
zh1huang Sep 2, 2021
9089498
A-CodeQuality
zh1huang Sep 2, 2021
5aab948
Level 5. Handle Errors
zh1huang Sep 8, 2021
5d11a58
bug fix
zh1huang Sep 8, 2021
aa34d61
Merge branch 'master' into branch-Level-5
zh1huang Sep 8, 2021
753e0a8
Formatting issues
zh1huang Sep 9, 2021
eea7087
Merge branch 'branch-Level-5'
zh1huang Sep 9, 2021
b6f0c99
Merge commit '753e0a8d9f752011003db89b100898f179545b01'
zh1huang Sep 9, 2021
326a6f2
Refactor packages
zh1huang Sep 10, 2021
04badc3
Merge branch 'branch-A-Packages'
zh1huang Sep 10, 2021
30ba786
Add Increment: Level-6 Delete
zh1huang Sep 14, 2021
22b68f0
Merge branch 'branch-Level-6'
zh1huang Sep 15, 2021
3a8a6f4
Cleaned up TaskManager
zh1huang Sep 15, 2021
793418f
Level-7: Save
zh1huang Sep 16, 2021
44695ee
Merge branch 'branch-Level-7'
zh1huang Sep 16, 2021
5cf8dd0
add manifest file
zh1huang Sep 16, 2021
6b52c9e
Bugfix of loading of tasks from file
zh1huang Sep 16, 2021
3d92406
Finalise and clean up Storage class
zh1huang Sep 28, 2021
054a4d6
Added Parser class
zh1huang Sep 28, 2021
770747e
Added Find
zh1huang Sep 28, 2021
99938ba
Added JavaDocs
zh1huang Sep 28, 2021
0b0382a
Merge pull request #1 from zh1huang/branch-Level-9
zh1huang Sep 28, 2021
258e217
Merge branch 'master' into A-JavaDoc
zh1huang Sep 28, 2021
25f9be6
Merge pull request #2 from zh1huang/A-JavaDoc
zh1huang Sep 28, 2021
433daa2
Testing user guide
zh1huang Sep 29, 2021
c89f1a9
test
zh1huang Sep 29, 2021
86057c2
test user guide
zh1huang Sep 29, 2021
60db3bb
Finalise User Guide
zh1huang Sep 29, 2021
b89640a
Final touching up
zh1huang Sep 30, 2021
8fbb849
Update README.md
zh1huang Oct 1, 2021
1e3f1a9
Update README.md
zh1huang Oct 1, 2021
e99c7f8
Update README.md
zh1huang Oct 1, 2021
ab2da15
Update README.md
zh1huang Oct 1, 2021
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
1 change: 1 addition & 0 deletions data/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
D | 0 | return book | Sunday
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

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

public class DukeException extends Exception {

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

import duke.task.TaskManager;
import java.io.IOException;
import java.util.Scanner;


public class Duke {
public static void main(String[] args) throws IOException {
TaskManager taskManager = new TaskManager();
Scanner scanner = new Scanner(System.in);
Ui ui = new Ui(taskManager, scanner);
ui.start();
}
}
116 changes: 116 additions & 0 deletions src/main/java/duke/command/Ui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package duke.command;

import duke.data.Storage;
import duke.task.TaskManager;
import duke.DukeException;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;

public class Ui {
private TaskManager taskManager;
private Scanner scanner;

private static final String LINE = " ____________________________________________________________\n";
private static final String LOGO = "\n" +
" \n" +
" ,--. ,------. ,--. ,--. ,--. \n" +
",-' '-.,---.| .-. \\ ,---.| | `--',---,-' '-. \n" +
"'-. .-| .-. | | \\ | .-. | | ,--( .-'-. .-' \n" +
" | | ' '-' | '--' ' '-' | '--| .-' `)| | \n" +
" `--' `---'`-------' `---'`-----`--`----' `--' \n" +
" \n";
private static final String GREETINGS = LINE
+ LOGO
+ " Welcome to the toDoList Chatbot\n"
+ " What would you like to do today?\n"
+ LINE;
private static final String FAREWELL = " Bye. Hope to see you again soon!";

private static final String TO_DO = "todo";
private static final String DEADLINE = "deadline";
private static final String EVENT = "event";
private static final String BYE = "bye";
private static final String LIST = "list";
private static final String DONE = "done";
private static final String DELETE = "delete";
private static final String ADD_SUCCESS = " Nice! I've marked this task as done: ";
private static final String DELETE_SUCCESS = " Noted. I've removed this task:";
private static final String PATH_NAME = "data/output.txt";

public Ui(TaskManager taskManager, Scanner scanner) {
this.taskManager = taskManager;
this.scanner = scanner;
}

private static void saveData() {
try {
String pathName = PATH_NAME;
//create folder with file if absent initially
Copy link

Choose a reason for hiding this comment

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

Consider adding a line spacing before a comment for improved readability.

Path path = Paths.get(pathName);
Files.createDirectories(path.getParent());
Storage.writeToFile(pathName);
} catch (IOException e) {
e.printStackTrace();
}
}

private static void loadData() throws IOException {
try {
Storage.load(PATH_NAME);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}

public void start() throws IOException {
loadData();
System.out.println(GREETINGS);
boolean isExit = false;
while (!isExit) {
String input = scanner.nextLine();
String[] command = input.split(" ");
String firstWord = command[0];

System.out.print(LINE);
try {
switch (firstWord) {
case BYE:
System.out.println(FAREWELL);
isExit = true;
break;
case LIST:
taskManager.list();
break;
case DONE:
int taskNumber = Integer.parseInt(command[1]);
System.out.println(ADD_SUCCESS);
taskManager.checkDone(command);
System.out.println(" " + taskManager.getName(taskNumber));
break;
case TO_DO:
case DEADLINE:
case EVENT:
taskManager.add(input);
break;
case DELETE:
System.out.println(DELETE_SUCCESS);
taskManager.deleteTask(command);
break;
default:
System.out.println(" ☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
}
} catch (DukeException e) {
System.out.println(" ☹ OOPS!!! The description of a " + firstWord + " cannot be empty.");
} catch (NumberFormatException e) {
System.out.println(" ☹ OOPS!!! The task's index should be an integer.");
}
System.out.print(LINE);
}
saveData();
}
}
66 changes: 66 additions & 0 deletions src/main/java/duke/data/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package duke.data;

import duke.task.Deadline;
import duke.task.Event;
import duke.task.Task;
import duke.task.TaskManager;

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

public class Storage {

public static void load(String filePath) throws IOException {
File newFile = new File(filePath);
Scanner scanner = new Scanner(newFile);

while (scanner.hasNext()) {
String line = scanner.nextLine();
String[] array = line.split(" | ");
Copy link

Choose a reason for hiding this comment

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

Might want to improve on the name for "array" to make it more meaningful.

switch (array[0]) {
case "T":
TaskManager.loadToDoFromFile(array[2]);
break;
case "D":
TaskManager.loadDeadlineFromFile(array[2], array[3]);
break;
case "E":
TaskManager.loadEventFromFile(array[2], array[3]);
break;
}
}
}


public static void appendToFile(String filePath, String textToAppend) throws IOException {
FileWriter fw = new FileWriter(filePath, true); // create a FileWriter in append mode
fw.write(textToAppend);
fw.close();
}

public static void writeToFile(String filePath) throws IOException {
File file = new File(filePath);
if (file.createNewFile()) {
System.out.println("File created");
}
String textToAppend;
for (Task task: TaskManager.taskList) {
String taskType = task.getIcon();
String status = task.getStatus();
String description = task.getDescription();
String timing = task.getTime();

textToAppend = taskType + " | " + status + " | " + description;
if (task instanceof Event || task instanceof Deadline) {
Copy link

Choose a reason for hiding this comment

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

Avoid complicated expressions, is there any way you can extract it out or make this more streamlined? (hint: use booleans)

textToAppend += " | " + timing;
}
textToAppend += "\n";
appendToFile(filePath, textToAppend);
}
}



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

public class Deadline extends Task {

protected String timing;

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

public String getIcon() {
return "D";
}

public String getTiming() {
return "(by:" + timing + ")";
}

public String getTime() {
return timing;
}

@Override
public String toString() {
return "[" + getIcon() + "]" + super.toString() + getTiming();
}
}
26 changes: 26 additions & 0 deletions src/main/java/duke/task/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package duke.task;

public class Event extends Task {
protected String timing;

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

public String getIcon() {
return "E";
}

public String getTiming() {
return "(at:" + timing + ")";
}

public String getTime() {
return timing;
}
@Override
public String toString() {
return "[" + getIcon() + "]" + super.toString() + getTiming();
}
}
45 changes: 45 additions & 0 deletions src/main/java/duke/task/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package duke.task;

public class Task {
protected String description;
protected boolean isDone;

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

public void taskDone() {
this.isDone = true;
}

public String getStatusIcon() {
return (isDone ? "[X]" : "[ ]");
}

public String getStatus() {
return (isDone ? "1" : "0");
}

public String getIcon() {
return "";
}

public String getTiming() {
return "";
}

public String getDescription() {
return description;
}

public String getTime() {
return "";
}

public String toString() {
return getStatusIcon() + " " + this.description ;
}


}
Loading