Skip to content
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
3b19ba1
Add Gradle support
May 24, 2020
d6b1456
level-1
nicktohzyu Aug 19, 2020
49fdaf1
add greet
nicktohzyu Aug 19, 2020
52ff3b3
level2
nicktohzyu Aug 19, 2020
48f8a1e
task tostring for done status
nicktohzyu Aug 19, 2020
1c9189f
mark task as done
nicktohzyu Aug 19, 2020
d91440c
Level 4
nicktohzyu Aug 20, 2020
28ca00a
automated testing
nicktohzyu Aug 20, 2020
b2c3edd
filter invalid input
nicktohzyu Aug 20, 2020
17f4128
Update Duke.java
nicktohzyu Aug 20, 2020
f74aa3c
abstract out Tasks class
nicktohzyu Aug 24, 2020
73ecf65
serialization
nicktohzyu Aug 24, 2020
9d526f1
data storage
nicktohzyu Aug 24, 2020
dea5581
implement LocalDate for Event and Deadline
nicktohzyu Aug 24, 2020
f128e30
Merge branch 'branch-Level-8' into master
nicktohzyu Aug 24, 2020
d3d481d
OOP UI
nicktohzyu Aug 24, 2020
43fd410
OOP Storage
nicktohzyu Aug 24, 2020
eba4197
OOP Parser
nicktohzyu Aug 24, 2020
68f0af7
add message on successful load
nicktohzyu Aug 24, 2020
92603f8
fix serialization bug, rename Tasks to TaskList
nicktohzyu Aug 24, 2020
54597fe
fix styling
nicktohzyu Aug 24, 2020
24f5318
A-JUnit
nicktohzyu Aug 25, 2020
9d2e2e4
Create MANIFEST.MF
nicktohzyu Aug 25, 2020
a7ae636
cleanup TaskList
nicktohzyu Aug 26, 2020
8dfb179
A-CodingStandard
nicktohzyu Aug 26, 2020
99b108f
Add javadocs
nicktohzyu Aug 26, 2020
f143e67
Level-9
nicktohzyu Aug 26, 2020
3607d1a
Merge tag 'Level-9' into master
nicktohzyu Aug 26, 2020
316ab12
Merge tag 'A-CodingStandard' into master
nicktohzyu Aug 26, 2020
42e8830
Update TaskList.java
nicktohzyu Aug 26, 2020
3f2e05e
Remove redundant code
nicktohzyu Aug 26, 2020
a75fcee
build.gradle: Update version to 8.29
Aug 29, 2020
34f572c
Merge branch 'add-gradle-support'
nicktohzyu Sep 2, 2020
d24d425
Update build.gradle
nicktohzyu Sep 2, 2020
6de3764
Update build.gradle
nicktohzyu Sep 8, 2020
9933b7b
Update .gitignore
nicktohzyu Sep 8, 2020
6a8c20a
Update .gitignore
nicktohzyu Sep 8, 2020
0177fda
Merge branch 'branch-Level-10' into master
nicktohzyu Sep 8, 2020
0a4bb48
add assertions
nicktohzyu Sep 9, 2020
02bc264
improve code quality
nicktohzyu Sep 9, 2020
7671eb9
Merge pull request #2 from nicktohzyu/branch-A-CodeQuality
nicktohzyu Sep 9, 2020
dc66c72
Merge pull request #1 from nicktohzyu/branch-A-Assertions
nicktohzyu Sep 9, 2020
aedb323
move tasks to package
nicktohzyu Sep 11, 2020
41238c8
Fix imports and remove unreachable statement
nicktohzyu Sep 14, 2020
9132476
Update .gitignore
nicktohzyu Sep 14, 2020
1467d91
C-sort
nicktohzyu Sep 14, 2020
7b29628
implement GUI part 1 to 3
nicktohzyu Sep 16, 2020
29d63f0
refactor fxml
nicktohzyu Sep 16, 2020
d7274aa
Update Parser.java
nicktohzyu Sep 16, 2020
98466a8
Merge branch 'branch-Level-10' into master
nicktohzyu Sep 16, 2020
16f9125
improve gui
nicktohzyu Sep 16, 2020
4fd75cc
update readme and ui screenshot
nicktohzyu Sep 16, 2020
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ bin/

/text-ui-test/ACTUAL.txt
text-ui-test/EXPECTED-UNIX.TXT

*.ser
23 changes: 23 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.time.LocalDate;

/**
* Represents a task to be completed by a certain time
*/
public class Deadline extends Task {

/**

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps adding a short summary of the method? This can also apply to other methods that do not have a description in other places.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

thanks, not sure how I should describe the constructor or toString, do you have suggestions?

* @param description Task description

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There should be a punctuation behind every parameter description. I have noticed similar issue in other places too.

* @param date Deadline for the task
*/
public Deadline(String description, LocalDate date) {
super(description, date);
}

/**
* @return String representation of the task
*/
@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + date.toString() + ")\n";
}
}
38 changes: 31 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
/**

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps putting the class in a package?

* Main class for Duke program.
*/
public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);

/**
* Entry point of the duke program. Read from storage and creates a UI class instance.
* Serves as intermediate between the UI and parser.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is incorrect as there should be an empty line between the description and parameter. I have noticed similar issues in several other places too.

* @param args
* @throws DukeException
*/
public static void main(String[] args) throws DukeException {
TaskList tasks = Storage.read();
UI ui = new UI();
ui.welcome(tasks);
String input = ui.getInput();
Parser parser = new Parser(tasks);
while (!input.equals("bye")) {
try {
if (input.isEmpty()) {
input = ui.getInput();
continue;
}
parser.parse(input);
} catch (DukeException e) {
UI.print(e.getMessage() + "\n");
}

input = ui.getInput();
}
ui.bye();
}

}
12 changes: 12 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* An exception class used for errors caused by inappropriate user input. Displays a message.
*/
public class DukeException extends Exception {
/**
* Constructor for DukeException.
* @param msg the message to be displayed.
*/
DukeException(String msg) {
super("☹ OOPS!!! " + msg);
}
}
23 changes: 23 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.time.LocalDate;

/**
* Represents a task occurring at a certain time
*/
public class Event extends Task {

/**
* @param description Task description
* @param date Date of the event
*/
public Event(String description, LocalDate date) {
super(description, date);
}

/**
* @return String representation of the task
*/
@Override
public String toString() {
return "[E]" + super.toString() + " (at: " + date.toString() + ")\n";
}
}
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

95 changes: 95 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import java.time.LocalDate;
import java.time.format.DateTimeParseException;

/**
* Class that handles user input
*/
public class Parser {
TaskList tasks;

/**
* @param tasks TaskList to use
*/
public Parser(TaskList tasks) {
this.tasks = tasks;
}

/**
* Parses the user command
* @param input input from the user
* @throws DukeException
*/
void parse(String input) throws DukeException {
String[] words = input.split(" ");
String command = words[0];
Task newTask;
String[] subst;
LocalDate date;
switch (command) {
case "list":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is incorrect because there should not be any indentation for the case clauses.

tasks.print_tasks();
break;
case "done":
case "delete":
Comment on lines +40 to +41

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The "done" case should end with a break; statement. You might have unintentionally shifted the "done" case into the "delete" case.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi, this was intentional as both commands use the same logic of tokenizing the input to get the task number, then getting that task object. It is after these steps where the logic then differs. Do you have a suggestion of a better way to do this?

int i = Integer.parseInt(words[1]) - 1;
Task task = tasks.get(i);
if (command.equals("done")) {
tasks.setDone(i, true);
UI.print("Nice! I've marked this task as done: \n" + task);
} else if (command.equals("delete")) {
tasks.remove(i);
UI.print("Noted. I've removed this task: \n" + task + tasks.numTasks());
}
break;
case "todo":
if (input.length() < 6) {
throw new DukeException("The description of a todo cannot be empty.");
}
String text = input.substring(5);
newTask = new Todo(text);
tasks.addTask(newTask);
break;
case "deadline":
if (input.length() < 10) {
throw new DukeException("The description of a deadline cannot be empty.");
}
subst = input.substring(9).split(" /by ");
if (subst.length < 2) {
throw new DukeException("The due date must be specified.");
}
try {
date = LocalDate.parse(subst[1]);
newTask = new Deadline(subst[0], date);
tasks.addTask(newTask);
} catch (DateTimeParseException e) {
throw new DukeException(e.getMessage());
}
break;
case "event":
if (input.length() < 7) {
throw new DukeException("The description of an event cannot be empty.");
}
subst = input.substring(6).split(" /at ");
if (subst.length < 2) {
throw new DukeException("The event date must be specified.");
}
try {
date = LocalDate.parse(subst[1]);
newTask = new Event(subst[0], date);
tasks.addTask(newTask);
} catch (DateTimeParseException e) {
throw new DukeException(e.getMessage());
}
break;
case "find":
if (input.length() < 6) {
throw new DukeException("Text to search for cannot be empty.");
}
tasks.find(input.substring(5));
break;
default:
throw new DukeException("I'm sorry, but I don't know what that means :-(");
// break;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A break statement should be included for the default case too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hmm intellij complains about this as it's an unreachable statement. Do you know how I can configure it to ignore this error, or have a suggestion on how to implement this logic instead?

}
}
}
55 changes: 55 additions & 0 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import java.io.*;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The imported classes should be listed explicitly.

import java.nio.file.Paths;

/**
* Class that provides file storage utilities
*/
public class Storage {
public static final File storage_file = Paths.get("tasks.ser").toFile();

public Storage() {
}

/**
* Serializes a TaskList and writes it to file
* @param t tasklist to be stored
*/
public static void store(TaskList t) {
try {
//noinspection ResultOfMethodCallIgnored
storage_file.createNewFile(); //creates file if it does not exist
FileOutputStream fileOut = new FileOutputStream(storage_file);
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(t);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}

/**
* Reads a serialized TaskList
* @return tasklisk read from file
*/
public static TaskList read() {
try {
TaskList t;
FileInputStream fileIn = new FileInputStream(storage_file);
ObjectInputStream in = new ObjectInputStream(fileIn);
t = (TaskList) in.readObject();
in.close();
fileIn.close();
t.loadMessage = "Successfully loaded from storage. " + t.numTasks();
return t;
} catch (FileNotFoundException i) {
return new TaskList();
} catch (IOException i) {
i.printStackTrace();
return new TaskList();
} catch (ClassNotFoundException c) {
System.out.println("Employee class not found");
c.printStackTrace();
return new TaskList();
}
}
}
26 changes: 26 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.time.LocalDate;

/**
* Represents a task
*/
public class Task implements java.io.Serializable {
String text;
boolean done;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps a more intuitive variable name that will sound more like a boolean?

LocalDate date;

/**
* @param text Task description
* @param date Date of the task
*/
public Task(String text, LocalDate date) {
this.text = text;
this.date = date;
}

/**
* @return String representation of the task
*/
public String toString() {
return "[" + (done ? "✓" : "✗") + "] " + text;
}
}
Loading