Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
1541204
Add ability to read inputs and echo it as output
tin-jy Aug 25, 2022
18f1898
Add add and list functionality
tin-jy Aug 25, 2022
ec9fd31
Add functionality to mark and unmark tasks
tin-jy Aug 25, 2022
400cf62
Add different types of tasks
tin-jy Aug 29, 2022
7bc53d7
Add test cases for text-ui testing
tin-jy Aug 29, 2022
6f5be36
Add error handling for incorrect user inputs
tin-jy Aug 29, 2022
ddb1d97
Add functionality to remove tasks
tin-jy Aug 29, 2022
841c78b
Add a FileHandler class to deal with saving inputs in a local file
tin-jy Sep 1, 2022
129758c
Add functionality to save task list into a local file on every change
tin-jy Sep 1, 2022
c351d1d
Add functionality for Duke to load task list on startup
tin-jy Sep 1, 2022
a69c99c
Add ability for Duke to verify dates and time
tin-jy Sep 1, 2022
462fb51
Add classes Parser, Ui, TaskList to include more OOP
tin-jy Sep 3, 2022
4d4f45d
Place all Duke related Java files into packages
tin-jy Sep 3, 2022
fbdbd16
Merge branch 'add-gradle-support' of https://github.com/nus-cs2103-AY…
tin-jy Sep 6, 2022
304acb1
Add more packages and classes for organisation
tin-jy Sep 6, 2022
609dc79
Add more classes and error handling
tin-jy Sep 6, 2022
fe3f213
Add JUnit tests for public methods in some classes
tin-jy Sep 6, 2022
86fba2c
Update dependencies in build.gradle
tin-jy Sep 6, 2022
982ba6d
Add JavaDocs
tin-jy Sep 6, 2022
7338f37
Correct style issues to adhere to coding standards
tin-jy Sep 6, 2022
aef9014
Add ability to search for tasks using keywords
tin-jy Sep 6, 2022
8009da8
Merge branch 'branch-A-CodingStandard'
tin-jy Sep 6, 2022
b99000a
Merge branch 'branch-Level-9'
tin-jy Sep 6, 2022
3bda679
Add checkstyle.xml and suppressions.xml for checkstyle
tin-jy Sep 6, 2022
a2c8035
Fix a bug with the find command
tin-jy Sep 6, 2022
6741565
Add test cases
tin-jy Sep 6, 2022
ce8111d
Create JAR file
tin-jy Sep 7, 2022
217e318
Add a basic GUI for Duke
tin-jy Sep 8, 2022
7554d3d
Fully implement GUI and allow Duke to respond to commands
tin-jy Sep 8, 2022
cfabe0d
Merge branch 'branch-A-CheckStyle'
tin-jy Sep 8, 2022
5d7b0ab
Add package for GUI related java files
tin-jy Sep 8, 2022
1297ade
Add more JUnit tests
tin-jy Sep 8, 2022
ddf41bb
Add assert statements
tin-jy Sep 8, 2022
dafecc7
Improve code quality
tin-jy Sep 8, 2022
14da0b9
Merge pull request #1 from tin-jy/branch-A-Assertions
tin-jy Sep 8, 2022
4cd2cf6
Merge branch 'master' into branch-A-CodeQuality
tin-jy Sep 8, 2022
3c0576a
Merge pull request #2 from tin-jy/branch-A-CodeQuality
tin-jy Sep 8, 2022
7f02321
Add functionality to change the file path for local storage
tin-jy Sep 8, 2022
a883516
Change some output messages
tin-jy Sep 8, 2022
3574c8a
Add some bugfixes
tin-jy Sep 9, 2022
c8e2fdc
Fix checkstyle issues
tin-jy Sep 9, 2022
0d08193
Change profile images for Duke and the user.
tin-jy Sep 15, 2022
a2eb1a6
Add a user guide in README.md
tin-jy Sep 15, 2022
b8d38f9
Fix bug related to local file path
tin-jy Sep 16, 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
210 changes: 204 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,208 @@
import java.util.ArrayList;
import java.util.Locale;
import java.util.Scanner;

public class Duke {

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 apply OOP to split the Duke class into different smaller classes?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could split the class into various classes, i.e. TaskList, Event, Deadline, instead of putting them into one class

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could also add JavaDocs for documentation purposes


private static final ArrayList<Task> LIST_OF_THINGS = new ArrayList<>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe you could consider extracting this out as a separate TaskList class, which would handle adding tasks, etc.


private abstract static class 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.

Maybe you could create Task as a separate class, instead of nesting it in the Duke class.

private final String task_name;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should be camelcase formatting for variables

private boolean isCompleted;

private static class TodoTask extends Task {

public TodoTask(String name) {
super(name);
}

@Override
public String toString() {
if (isCompleted()) {
return String.format("[T][X] %s", getTaskName());
} else {
return String.format("[T][ ] %s", getTaskName());
}
}
}

private static class DeadlineTask extends Task {

private final String deadline;

public DeadlineTask(String name, String date) {
super(name);
deadline = date;
}

@Override
public String toString() {
if (isCompleted()) {
return String.format("[D][X] %s (By: %s)", getTaskName(), deadline);
} else {
return String.format("[D][ ] %s (By: %s)", getTaskName(), deadline);
}
}
}

private static class EventTask 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.

I like how you named the different Tasks clearly! 👍


private final String datetime;

public EventTask(String name, String date) {
super(name);
datetime = date;
}

@Override
public String toString() {
if (isCompleted()) {
return String.format("[E][X] %s (At: %s)", getTaskName(), datetime);
} else {
return String.format("[E][ ] %s (At: %s)", getTaskName(), datetime);
}
}
}

public Task(String name) {
task_name = name;
isCompleted = false;
}

public String getTaskName() {
return task_name;
}

public void markComplete() {
isCompleted = true;
}

public void markIncomplete() {
isCompleted = false;
}

public boolean isCompleted() {
return isCompleted;
}

@Override
public String toString() {
if (isCompleted) {
return String.format("[X] %s", task_name);
} else {
return String.format("[ ] %s", task_name);
}
}
}

public static boolean isMarkCommand(String str) {
if (str.length() < 6) {
return false;
}
if (!str.startsWith("mark")) {
return false;
}
try {
Integer.parseInt(str.substring(5));
return true;
} catch (NumberFormatException nfe) {
return false;
}
}

public static boolean isUnmarkCommand(String str) {
if (str.length() < 8) {
return false;
}
if (!str.startsWith("unmark")) {
return false;
}
try {
Integer.parseInt(str.substring(7));

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 you could consider using str.split(" ") rather than str.substring(7). May improve reusability of code instead of having to change the number according to the length of the command?

return true;
} catch (NumberFormatException nfe) {
return false;
}
}


public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
System.out.println("Hi, I'm Duke. What can I do for you?");
Scanner keyboard = new Scanner(System.in);
String message = keyboard.nextLine();
while (true) {
if (message.equals("bye")) {
System.out.println("Bye! See you next time!");
break;
} else if (message.equals("list")) {
StringBuilder output_message = new StringBuilder();
for (int i = 0; i < LIST_OF_THINGS.size(); i++) {
output_message.append(String.format("%d. %s", i + 1, LIST_OF_THINGS.get(i)));
output_message.append("\n");
}
System.out.println(output_message);
} else if (isMarkCommand(message)) {
int index = Integer.parseInt(message.substring(5));
if (index > LIST_OF_THINGS.size() || index < 1) {
System.out.printf("Sorry, task %d does not exist!%n", index);
} else {
Task task = LIST_OF_THINGS.get(index - 1);
task.markComplete();
System.out.printf("Good Job! This task has been marked as done:%n%s%n", task);
}
} else if (isUnmarkCommand(message)) {
int index = Integer.parseInt(message.substring(7));
if (index > LIST_OF_THINGS.size() || index < 1) {
System.out.printf("Sorry, task %d does not exist!%n", index);
} else {
Task task = LIST_OF_THINGS.get(index - 1);
task.markIncomplete();
System.out.printf("Get it done! This task has been marked as undone:%n%s%n", task);
}
} else if (message.startsWith("deadline")) {
int slash_char_pos = message.indexOf("/by");
if (slash_char_pos < 13) {
System.out.println("Deadline tasks require a task name and a deadline specified by /by");
} else {
String task_name = message.substring(9, slash_char_pos);
String deadline = message.substring(slash_char_pos + 4);
Task this_task = new Task.DeadlineTask(task_name, deadline);
LIST_OF_THINGS.add(this_task);
System.out.printf("I've added this task:%n%s%n", this_task);
}
} else if (message.startsWith(("event"))) {
int slash_char_pos = message.indexOf("/at");
if (slash_char_pos < 10) {
System.out.println("Event tasks require a task name and a datetime specified by /at");
} else {
String task_name = message.substring(6, slash_char_pos);
String date = message.substring(slash_char_pos + 4);
Task this_task = new Task.EventTask(task_name, date);
LIST_OF_THINGS.add(this_task);
System.out.printf("I've added this task:%n%s%n", this_task);
}
} else if (message.startsWith(("todo"))) {
String task_name = message.substring(5);
Task this_task = new Task.TodoTask(task_name);
LIST_OF_THINGS.add(this_task);
System.out.printf("I've added this task:%n%s%n", this_task);
} else if (message.startsWith("delete")) {
try {
int task_index = Integer.parseInt(message.substring(7)) - 1;
Task removed = LIST_OF_THINGS.remove(task_index);
System.out.printf("Noted. I've removed this task:%n%s%nNow you have %d tasks in the list%n",
removed, LIST_OF_THINGS.size());
} catch (StringIndexOutOfBoundsException e) {
System.out.println("Please indicate which task you would like to delete");
} catch (NumberFormatException e) {
System.out.println("You need to enter a number!");
} catch (IndexOutOfBoundsException e) {
System.out.printf("You only have %d tasks!%n", LIST_OF_THINGS.size());
}
} else {
System.out.println("Sorry, I don't know what that means :(");
}
message = keyboard.nextLine();
}
}
}
10 changes: 3 additions & 7 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

Hi, I'm Duke. What can I do for you?
I've added this task:
[D][ ] CS2013 (By: 1 September)
3 changes: 3 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
deadline CS2013 /by 1 September
list
mark 1
2 changes: 1 addition & 1 deletion text-ui-test/runtest.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@ECHO OFF
@ECHO OFF

REM create bin directory if it doesn't exist
if not exist ..\bin mkdir ..\bin
Expand Down