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

[Sien Soon] iP #505

Open
wants to merge 65 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
dbb7d2f
Added Level-1: Greet, Echo, Exit functions
ssyap98 Aug 18, 2022
3dcd64e
Added Level-2: Add, list functions
ssyap98 Aug 18, 2022
f8486c1
Added Level-3: Mark as Done function
ssyap98 Aug 22, 2022
ff25932
Added Level-4: ToDos, Events, Deadlines
ssyap98 Aug 22, 2022
f9492c8
Added A-TextUiTesting: Automated Text UI Testing
ssyap98 Aug 23, 2022
5551f11
Added Level-5: Handle Errors
ssyap98 Aug 24, 2022
690ced2
Added Level-6: Delete tasks from list
ssyap98 Aug 24, 2022
65661df
Add Level-7: Save
ssyap98 Aug 29, 2022
daf1faa
Add Level-8: Dates and Times
ssyap98 Aug 29, 2022
68c04ca
Merge branch 'branch-Level-8'
ssyap98 Aug 29, 2022
efd5205
Add A-MoreOOP
ssyap98 Sep 11, 2022
e0cdb1b
Organise all classes into one package
ssyap98 Sep 11, 2022
2a7633a
Organise all classes into 1 package
ssyap98 Sep 11, 2022
e81658d
Move all classes into the duke folder
ssyap98 Sep 11, 2022
99aabf4
Merge commit '556af3f47a96b32898ab4cdbd65b16486a4871e8'
ssyap98 Sep 12, 2022
7717770
Save Event, Deadline and ToDo tasks to file when created
ssyap98 Sep 13, 2022
793b714
Add JUnit Tests for Event and ToDo class
ssyap98 Sep 13, 2022
6203c9c
Change mainClassName and archiveBaseName in build.gradle
ssyap98 Sep 13, 2022
7a38405
Add JavaDoc comments for Duke.java
ssyap98 Sep 13, 2022
e0cf62a
Use plural form to represent a list of tasks
ssyap98 Sep 13, 2022
32d820c
Add ability to find a task by searching for a keyword
ssyap98 Sep 13, 2022
1ec5154
Merge branch 'branch-A-JavaDoc'
ssyap98 Sep 13, 2022
dc7219e
Merge branch 'branch-A-CodingStandard'
ssyap98 Sep 13, 2022
fcdd02a
Change list to tasks to follow coding standard
ssyap98 Sep 13, 2022
102f161
Create GUI for Duke
ssyap98 Sep 16, 2022
020a8e3
Merge branch 'branch-Level-10'
ssyap98 Sep 16, 2022
d5f52df
Adds date and time to Event class
ssyap98 Sep 19, 2022
79972fa
Adds flip() method in DialogBox
ssyap98 Sep 19, 2022
2a96419
Adds assertion to document important assumptions
ssyap98 Sep 19, 2022
b50dfe3
Fix code quality in Storage class
ssyap98 Sep 19, 2022
a8d3ebc
Merge pull request #2 from ssyap98/branch-A-Assertions
ssyap98 Sep 19, 2022
b3caa65
Merge branch 'master' into branch-A-CodeQuality
ssyap98 Sep 19, 2022
41554b3
Merge pull request #3 from ssyap98/branch-A-CodeQuality
ssyap98 Sep 19, 2022
c6c399c
Fix minor bug
ssyap98 Sep 19, 2022
57ec27f
Add case "bye" to parser which was accidentally removed earlier
ssyap98 Sep 19, 2022
331eb34
Adds Category C extension: C-Help
ssyap98 Sep 19, 2022
e916bf3
Merge branch 'branch-C-Help'
ssyap98 Sep 19, 2022
d9e999c
Change some phrases used by Duke when responding to commands
ssyap98 Sep 19, 2022
a05cbe5
Adds User Guide and Ui screenshot
ssyap98 Sep 19, 2022
04ce912
Update README.md
ssyap98 Sep 19, 2022
eca8928
Create MainWindow.fxml and DialogBox.fxml in src/main/resources/view
ssyap98 Oct 11, 2022
26c05ac
Use FXML for Duke
ssyap98 Oct 11, 2022
1080320
Replace image name
ssyap98 Oct 11, 2022
f1bb5d6
Add welcome/greeting message upon running Duke
ssyap98 Oct 11, 2022
753caa7
Fix "bye" command
ssyap98 Oct 11, 2022
5641335
Fix error message when unknown command is entered by user
ssyap98 Oct 11, 2022
132a977
Add method to show error message when invalid todo, deadline, event, …
ssyap98 Oct 11, 2022
2090ffe
Set purple color background for dialog box
ssyap98 Oct 11, 2022
27aa548
Change dialogbox font size and color
ssyap98 Oct 11, 2022
7388ab3
Change mainwindow background color to black
ssyap98 Oct 11, 2022
d38b68b
Set dialogbox's minimum height
ssyap98 Oct 11, 2022
62b7e1d
Add header comments in Deadline.java
ssyap98 Oct 12, 2022
3ee3d3d
Remove empty space
ssyap98 Oct 12, 2022
9f170d3
Add header comments in DialogBox.java
ssyap98 Oct 12, 2022
79dde49
Update header comment in Deadline.java
ssyap98 Oct 12, 2022
b04f6d8
Add header comments in Duke.java
ssyap98 Oct 12, 2022
c6ef386
Add header comments in DukeException.java
ssyap98 Oct 12, 2022
8cab955
Add header comments in Event.java
ssyap98 Oct 12, 2022
02c42d4
Add header comments in Parser.java
ssyap98 Oct 12, 2022
a937afe
Add header comments in Storage.java
ssyap98 Oct 12, 2022
f966e87
Add header comments in Task.java
ssyap98 Oct 12, 2022
24eabe0
Add header comments in TaskList.java
ssyap98 Oct 12, 2022
ac4a600
Add header comments in ToDo.java
ssyap98 Oct 12, 2022
8813ac4
Add header comments in Ui.java
ssyap98 Oct 12, 2022
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
24 changes: 24 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Deadline extends Task {

protected LocalDateTime by;

Choose a reason for hiding this comment

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

Maybe you could name it as "deadlineTime" instead of "by"?


public Deadline(String description, String by) {
super(description);
this.by = LocalDateTime.parse(by); //Obtains an instance of LocalDateTime from a text string such as 2007-12-03T10:15:30.
}

@Override
public String saveString() {
return "D | " + (this.isDone ? "1 | " : "0 | ") + this.description + " | " + this.by;
}

@Override
public String toString() {
return "[D]" + super.toString() +
" (by: " + this.by.format(DateTimeFormatter.ofPattern("MMM d yyyy hh:mm:ss")) + ")";
}

}
237 changes: 231 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,235 @@
import java.util.Scanner;
import java.util.ArrayList;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

public class Duke {

private final String horizontalLine = "-------------------------";
Copy link

Choose a reason for hiding this comment

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

You may want the name of your constant variables like this one to match the coding standard. Perhaps something like:

Suggested change
private final String horizontalLine = "-------------------------";
private final String HORIZONTAL_LINE = "-------------------------";

private ArrayList<Task> taskList;
private Scanner sc;
private static File saveFile = new File("duke.txt");

public Duke() {
this.taskList = new ArrayList<>();
}
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
Duke duke = new Duke();
duke.greeting();
duke.run();
duke.goodBye();

Choose a reason for hiding this comment

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

Maybe you could name the methods as verbs like greet() and exit() instead?

}
//Solution below adapted from https://github.com/24Donovan24/ip

private void run() {
if (saveFile.exists()) {
load();
} else {
initialise();
}
}

public void load() {
try {
sc = new Scanner(this.saveFile);
while (sc.hasNextLine()) {
String taskInFile = sc.nextLine();
String[] taskInArray = taskInFile.split(" \\| "); //The \\ is really equivalent to a single \ (the first \ is required as a Java escape sequence in string literals).
// It is then a special character in regular expressions which means "use the next character literally, don't interpret its special meaning"
String taskType = taskInArray[0];
switch (taskType) {
case "T": {
Task task = new ToDo(taskInArray[2]);
taskList.add(task);
if (taskInArray[1].equals("1")) {
task.markAsDone();
}
break;
}

case "D": {
Task task = new Deadline(taskInArray[2], taskInArray[3]);
taskList.add(task);
if (taskInArray[1].equals("1")) {
task.markAsDone();
}
break;
}

case "E": {
Task task = new Event(taskInArray[2], taskInArray[3]);
taskList.add(task);
if (taskInArray[1].equals("1")) {
task.markAsDone();
}

Choose a reason for hiding this comment

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

Since in each case you are marking the task as done when loading them, maybe u can abstract the process out?

break;
}
Copy link

Choose a reason for hiding this comment

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

The indentation for each case statement should be aligned to the switch


}
}
initialise();
} catch (FileNotFoundException exception) {
System.out.println("File not found!");
}
}


private void initialise() {
sc = new Scanner(System.in);
String command = sc.next();

while (!command.equals("bye")) {
try {

switch (command) {

case "list": {
showList();
break;
}

case "mark": {
int index = sc.nextInt() - 1;
markTask(index);
save(taskList);
break;
}

case "unmark": {
int index = sc.nextInt() - 1;
unMarkTask(index);
save(taskList);
break;
}

case "todo": {
String description = sc.nextLine();
setToDo(description);
save(taskList);
break;
}

case "deadline": {
String input = sc.nextLine();
String description = input.substring(0, input.indexOf("/") - 1);
String by = input.substring(input.indexOf("/") + 4);
setDeadLine(description, by);
save(taskList);
break;
}

case "event": {
String input = sc.nextLine();
String description = input.substring(0, input.indexOf("/") - 1);
String at = input.substring(input.indexOf("/") + 4);
setEvent(description, at);
save(taskList);
break;
}

case "delete": {
int index = sc.nextInt() - 1;
deleteTask(index);
save(taskList);
break;
}

default:
sc.nextLine();
throw new DukeException("I'm sorry, but I don't know what that means.");
}
} catch (DukeException exception) {
System.out.println(exception);
}
command = sc.next();
}

}

private void greeting() {
System.out.println("To all Subjects of Ymir. My name is Eren Yeager.\n" + "How can I help you?" + "\n" + horizontalLine);
}

private void goodBye() {
System.out.println(horizontalLine + "\n" + "Keep moving forward until you finish all your tasks. Goodbye." + "\n" + horizontalLine);
}

private void showList() {
System.out.println(horizontalLine + "\n" + "Here are the tasks in your list:");
for (int i = 0; i < taskList.size(); i++) {
System.out.println((i + 1) + ". " + taskList.get(i));
}
System.out.println(horizontalLine);
}

private void markTask(int index) {
Task completedTask = taskList.get(index);
completedTask.markAsDone();
System.out.println(horizontalLine);
System.out.println("Nice! I've marked this task as done:" + "\n" + completedTask);
System.out.println(horizontalLine);
}

private void unMarkTask(int index) {
Task unfinishedTask = taskList.get(index);
unfinishedTask.markAsNotDone();
System.out.println(horizontalLine);
System.out.println("OK, I've marked this task as not done yet:" + "\n" + unfinishedTask);
System.out.println(horizontalLine);
}

private void setToDo(String description) throws DukeException {
if (description.isEmpty()) {
throw new DukeException("The description of todo cannot be empty");
}
Task toDo = new ToDo(description);
taskList.add(toDo);
System.out.println(horizontalLine);
System.out.println("Got it. I've added this task:" + "\n" + toDo + "\n" + "Now you have " + taskList.size()
+ " tasks in your list.");
System.out.println(horizontalLine);
}

private void setDeadLine(String description, String by) {
Task deadLine = new Deadline(description, by);
taskList.add(deadLine);
System.out.println(horizontalLine);
System.out.println("Got it. I've added this task:" + "\n" + deadLine + "\n" + "Now you have " + taskList.size()
+ " tasks in your list.");
System.out.println(horizontalLine);
}

private void setEvent(String description, String at) {
Task event = new Event(description, at);
taskList.add(event);
System.out.println(horizontalLine);
System.out.println("Got it. I've added this task:" + "\n" + event + "\n" + "Now you have " + taskList.size()
+ " tasks in your list.");
System.out.println(horizontalLine);
}

private void deleteTask(int index) {
Task toBeDeleted = taskList.get(index);
taskList.remove(index);
System.out.println(horizontalLine);
System.out.println("Noted. I've removed this task:" + "\n" + toBeDeleted + "\n" + "Now you have " + taskList.size()
+ " tasks in your list.");
System.out.println(horizontalLine);
}

public void save(List<Task> list) {
try {
FileWriter writer = new FileWriter(saveFile.getPath());
for (Task task : list) {
writer.write(task.saveString() + System.lineSeparator());
}
writer.close();
} catch (IOException exception) {
System.out.println("I cannot save your tasks in the file.");
}
}

}
13 changes: 13 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class DukeException extends Exception {

public DukeException(String errorMessage) {
super(errorMessage);
}

@Override
public String toString() {
String horizontalLine = "-------------------------";
return horizontalLine + "\n" + super.toString() + "\n" + horizontalLine;
}

}
19 changes: 19 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class Event extends Task {

protected String at;

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

@Override
public String saveString() {
return "E | " + (this.isDone ? "1 | " : "0 | ") + this.description + " | " + this.at;
}

@Override
public String toString() {
return "[E]" + super.toString() + " (at: " + this.at + ")";
}
}
29 changes: 29 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
public abstract class Task {
protected String description;
protected boolean isDone;

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

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

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

public void markAsNotDone() {
this.isDone = false;
}

abstract String saveString();

@Override
public String toString() {
return "[" + getStatusIcon() + "] " + this.description;
}

}
17 changes: 17 additions & 0 deletions src/main/java/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class ToDo extends Task {

public ToDo(String description) {
super(description);
}

@Override
public String saveString() {
return "T | " + (this.isDone ? "1 | " : "0 | ") + this.description;
}

@Override
public String toString() {
return "[T]" + super.toString();
}

}
40 changes: 33 additions & 7 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

To all Subjects of Ymir. My name is Eren Yeager.
How can I help you?
-------------------------
-------------------------
DukeException: I'm sorry, but I don't know what that means.
-------------------------
-------------------------
Got it. I've added this task:
[T][ ] borrow book
Now you have 1 tasks in your list.
-------------------------
-------------------------
Got it. I've added this task:
[D][ ] return book (by: Monday)
Now you have 2 tasks in your list.
-------------------------
-------------------------
Here are the tasks in your list:
1. [T][ ] borrow book
2. [D][ ] return book (by: Monday)
-------------------------
-------------------------
Nice! I've marked this task as done:
[D][X] return book (by: Monday)
-------------------------
-------------------------
Here are the tasks in your list:
1. [T][ ] borrow book
2. [D][X] return book (by: Monday)
-------------------------
-------------------------
Keep moving forward until you finish all your tasks. Goodbye.
-------------------------
7 changes: 7 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eat lunch
todo borrow book
deadline return book /by Monday
list
mark 2
list
bye