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

[Fahim Tajwar] iP #377

Open
wants to merge 84 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
7fb3c62
Started with chatbot that imitates user commands, and exits on 'bye'.
Jan 19, 2023
585628d
Added 'add' and 'list' functionality. Converted if-else-if tree to ne…
Jan 19, 2023
749cb50
Added Task class. Changes to Duke.java to store and print Task objects.
Jan 19, 2023
b1e0b2a
Added 'mark' and 'unmark' functionality.
Jan 19, 2023
37c96bf
Added line of text when calling 'list' command.
Jan 19, 2023
f7de89a
Added ToDo, Event and Deadline tasks as subclasses of Task.
Jan 19, 2023
1574507
Performed automated Text UI testing.
Jan 19, 2023
22a6ad8
Added exception handling for empty args, invalid command, bad indexes…
Jan 19, 2023
d62dc45
Added a DukeException class, as a parent class of all Duke-specific e…
Jan 19, 2023
2b0a112
Added delete functionality with exception handling.
Jan 19, 2023
f41e8e9
Style changes, add prevTask file detection.
Feb 1, 2023
8d23902
Add data.txt file reading functionality.
Feb 1, 2023
4e1ff5e
Remove save/load functionality from Duke.java (transfer to FileHandle…
Feb 2, 2023
a388982
Add FileHandler.java for save/load functionality.
Feb 2, 2023
349a0fc
Store Deadline dates as java.time.LocalDate.
Feb 3, 2023
a3cb086
Merge branch 'branch-Level-7'
Feb 3, 2023
85f2b1f
Extract all command line handling from Duke.java into UI.java.
Feb 4, 2023
7bf0c8d
Rename FileHandler.java to Storage.java
Feb 4, 2023
7effb96
Fix a bug where entering an invalid date created a Deadline with "by"…
Feb 4, 2023
9b3cf3f
Created separate welcome() method for welcome message.
Feb 4, 2023
8a7e229
Redesign to maintain OO principles.
Feb 8, 2023
f2ccca6
Group all classes into packages.
Feb 8, 2023
57565ad
Merge commit '556af3f47a96b32898ab4cdbd65b16486a4871e8'
Feb 12, 2023
af428b8
Add Gradle support.
Feb 12, 2023
8393433
Add JUnit testcases for TaskList.java.
Feb 12, 2023
bc50cb9
Modify TaskList.java to create new tasks.txt in the beginning if not …
Feb 12, 2023
3f4922b
Make all backend classes package-private.
Feb 13, 2023
914347b
Add Javadoc comments to duke.exceptions and duke.tasks package classes.
Feb 13, 2023
41b42ef
Modify TaskListTest to clear tasks.txt before testing.
Feb 13, 2023
97c39aa
Modify classes in duke.backend to conform to our Coding Standards.
Feb 13, 2023
020b0cc
Make Event start and end times private.
Feb 13, 2023
0c9f275
Modify duke.tasks classes to follow Coding Standard.
Feb 13, 2023
f3ae32d
Modify duke.exceptions classes to follow Coding Standard.
Feb 13, 2023
23f3ff2
Add Javadoc comments to duke.exceptions and duke.tasks package classes.
Feb 13, 2023
0c74c26
Modify TaskListTest to clear tasks.txt before testing.
Feb 13, 2023
9244628
Merge branch 'branch-A-JavaDoc'
Feb 14, 2023
48cbe28
Merge branch 'branch-A-codingStandard'. Resolved coding standards.
Feb 14, 2023
6c20142
Fully Resolved merge conflicts between A-JavaDoc, A-codingStandard an…
Feb 14, 2023
59489b0
Resolve some remaining merge conflicts in duke.exceptions.
Feb 14, 2023
dcdfadf
Add FIND keyword functionality.
Feb 14, 2023
30f927c
Add comments for UI:find() method.
Feb 14, 2023
e8e9f16
Set up Checkstyle for the project.
Feb 14, 2023
d90ccb8
Fix Checkstyle violations.
Feb 14, 2023
1af69e9
Create GUI
Feb 17, 2023
b0532a9
Add duke.commands package, containing all different types of commands.
Feb 18, 2023
d0b8fd2
Add functionality: close Duke on sending "bye" command.
Feb 18, 2023
3ec344e
Fix CheckStyle Violations.
Feb 18, 2023
b1b68cc
Use assertions to ensure correct indexes are passed during Delete and…
Feb 18, 2023
a2106a0
Merge pull request #2 from fahim-tazz/branch-A-codingStandard
fahim-tazz Feb 18, 2023
fa9494c
Merge pull request #3 from fahim-tazz/branch-Level-9
fahim-tazz Feb 18, 2023
0173c39
Merge pull request #4 from fahim-tazz/branch-A-CheckStyle
fahim-tazz Feb 18, 2023
a531450
Merge pull request #5 from fahim-tazz/branch-Level-10
fahim-tazz Feb 18, 2023
02c62a7
Merge pull request #6 from fahim-tazz/branch-A-Assertions
fahim-tazz Feb 18, 2023
76b459f
Add functionality: Detect tasks with duplicate names.
Feb 18, 2023
e5a54ba
Delete dead class Ui.java.
Feb 18, 2023
eda9529
Merge branch 'branch-A-CodeQuality'
Feb 19, 2023
6ac9078
Rename Duke to Jarvis.
Feb 19, 2023
1b3c45f
Add welcome message when GUI is first opened.
Feb 19, 2023
eee9720
'list' now says 'no items in list' when called on an empty list.
Feb 19, 2023
c651eb9
Change User and Chatbot profile pictures.
Feb 19, 2023
bd2f74e
Rename Jarvis to Chad.
Feb 19, 2023
3c98b99
Tweak Chad's responses.
Feb 19, 2023
f330f66
Change GUI background color.
Feb 19, 2023
f9dc729
Fix infinite recursion on 'bye' command.
Feb 19, 2023
3289ea2
Add JUnit tests for Parser.
Feb 20, 2023
e7a2ca3
Remove redundant Sout debug messages from Storage.java.
Feb 20, 2023
f1fd6f3
Set Gradle to build without checkstyle.
Feb 20, 2023
503133b
Fix NullPointerException in all Make commands.
Feb 20, 2023
e9ff01c
Add all exception handling to Parser.java.
Feb 20, 2023
96cb503
Merge tag 'A-MoreErrorHandling'
Feb 20, 2023
1113aee
Change window label to "Chad - Your Personal DIgital Assistant".
Feb 20, 2023
6c30c20
Add UI screenshot to docs folder.
Feb 20, 2023
67b82ba
Update README.md to include full User Guide.
fahim-tazz Feb 20, 2023
dbcd44f
Add save functionality when window is closed by [X] button.
Feb 20, 2023
ee130c6
Reduce app closing delay after sending 'bye' command.
Feb 20, 2023
ba43f57
Fix issue with not creating file. [Only works for command line execut…
Feb 20, 2023
3c82330
Update docs/README.md quick start to show how to launch through comma…
Feb 20, 2023
2371311
Add user guide as README to root directory.
Feb 20, 2023
a5d30e0
Add Error Handling for invalid arguments for delete command.
Feb 20, 2023
5ba3415
Fix hyperlink formatting in root/README.md
fahim-tazz Feb 20, 2023
a69ed15
Update README.md on root folder.
fahim-tazz Feb 20, 2023
d6d6a06
Update README.md
fahim-tazz Feb 20, 2023
0ee4cbe
Cleanup code.
Feb 20, 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
15 changes: 15 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class Deadline extends Task {

protected String by;

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

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

126 changes: 119 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,122 @@
import java.util.*;

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

Choose a reason for hiding this comment

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

Should basic indentation be changed from 2 spaces to 4 spaces to align with the Java coding standard?

Suggested change
public static void main(String[] args) {
public static void main(String[] args) {

// String logo = " ____ _ \n"
// + "| _ \\ _ _| | _____ \n"
// + "| | | | | | | |/ / _ \\\n"
// + "| |_| | |_| | < __/\n"
// + "|____/ \\__,_|_|\\_\\___|\n";
// System.out.println("Hello from\n" + logo);

String divider = "____________________________________________________________\n";
System.out.println(divider + "Hello! I'm Duke");
System.out.println("What can I do for you?\n" + divider);

ArrayList<Task> tasks = new ArrayList<>();
Scanner sc = new Scanner(System.in);

while(sc.hasNext()) {

Choose a reason for hiding this comment

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

I noticed several Java reserved words such as while in this case not being followed by a white space. e.g.

Suggested change
while(sc.hasNext()) {
while (sc.hasNext()) {

Perhaps you could consider using IntelliJ's code cleanup feature to add these white spaces automatically.

Copy link

Choose a reason for hiding this comment

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

Be careful of using sc.hasNext() vs sc.hasNextLine()

String instr = sc.nextLine();
switch(instr) { //Single-word instructions
case "list": //List down

Choose a reason for hiding this comment

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

Should indentation for case clauses be removed?

Suggested change
case "list": //List down
case "list":

System.out.println(divider + "Here are the tasks in your list:\n");
for(int i = 1; i <= tasks.size(); i++) {
System.out.println(i + ". " + tasks.get(i-1));
}
System.out.println(divider);
break;

case "bye": //Exit
System.out.println(divider + "Bye. Hope to see you again soon!\n" + divider);
return;

//Other single word commands go here.

default: //Instructions with arguments
StringTokenizer tokens = new StringTokenizer(instr, " ");
String action = tokens.nextToken(); //Splitting the action and args.

String keyword = ""; //keyword = argument(s) after the action.
while(tokens.hasMoreTokens()) {
keyword = keyword + " " + tokens.nextToken();
}
keyword = keyword.strip();
if(keyword.equals("")) {
System.out.println(divider + "OOPS!!! The description of a " + action + " cannot be empty.\n" + divider);
}

switch(action) { //For instructions with argument(s).
Copy link

Choose a reason for hiding this comment

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

Would recommend against nesting switch-case block for code quality

case "add":
tasks.add(new Task(keyword));
break;

case "mark":
try {
Task t1 = tasks.get(Integer.parseInt(keyword) - 1);
t1.mark();
System.out.println(divider + "Nice! I've marked this task as done:\n" + t1 + "\n" + divider);
} catch(IndexOutOfBoundsException ioobe) {
System.out.println("Sorry, the index number you've entered does not exist.");
continue;
} catch(NumberFormatException nfe) {
System.out.println("Please enter the index number you wish to mark/unmark.");
}
break;

case "unmark":
try {
Task t2 = tasks.get(Integer.parseInt(keyword) - 1);
t2.unmark();
System.out.println(divider + "OK! I've marked this task as not done yet:\n" + t2 + "\n" + divider);
} catch(IndexOutOfBoundsException ioobe) {
System.out.println("Sorry, the index number you've entered does not exist.");
continue;
} catch(NumberFormatException nfe) {
System.out.println("Please enter the index number you wish to mark/unmark.");
}
break;

case "todo":
tasks.add(new Todo(keyword));
break;

case "deadline":
String[] deadlineFinder = keyword.split(" /by "); //Split keyword into description and date, separated by "/by".
keyword = deadlineFinder[0];
try {
String deadline = deadlineFinder[1];
tasks.add(new Deadline(keyword, deadline));
} catch(IndexOutOfBoundsException ioobe) {
System.out.println("Please define a deadline following the keyword '/by'.");
}
break;

case "event":
String[] startFinder = keyword.split(" /from "); //Split keyword into description and start,end.
try{
String[] endFinder = startFinder[1].split(" /to "); //Split start,end into start and end.
tasks.add(new Event(startFinder[0], endFinder[0], endFinder[1]));
} catch(IndexOutOfBoundsException ioobe) {
System.out.println("Please define a start time following the keyword '/from'\nand then an end time following the keyword '/to'.");
}
break;

case "delete":
try {
int deleteIdx = Integer.parseInt(keyword);
tasks.remove(deleteIdx - 1);
} catch(NumberFormatException nfe) {
System.out.println("Please enter the index number you wish to delete.");
} catch(IndexOutOfBoundsException ioobe) {
System.out.println("Sorry, the index number you've entered does not exist.");
continue;
}
break;
default:
System.out.println(divider + "OOPS! I'm sorry, but I don't know what that means :-(\n" + divider); //For unknown action.
}
}
}
}
Copy link

Choose a reason for hiding this comment

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

A lot of nested blocks. Consider abstracting away with methods within the main class. For example you can have:

// in main
switch(...) {
    case "todo":
        addToDo(tokens);
}

// add implementation
public void addToDo(String[] tokens) {
// your implementation
}

}
5 changes: 5 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class DukeException extends Exception {
DukeException(String msg) {
super(msg);
}
}
17 changes: 17 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Event extends Task {

protected String start;
protected String end;

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

@Override
public String toString() {
return "[D]" + super.toString() + " (from: " + start + " to: " + end + ")";
}
}

27 changes: 27 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class Task {
protected String description;
protected boolean isDone;

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

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

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

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

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

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

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

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

85 changes: 79 additions & 6 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,80 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|
____________________________________________________________
Hello! I'm Duke
What can I do for you?
____________________________________________________________

____________________________________________________________
Here are the tasks in your list:

____________________________________________________________

____________________________________________________________
Here are the tasks in your list:

1. [T][ ] wash car
____________________________________________________________

____________________________________________________________
Nice! I've marked this task as done:
[T][X] wash car
____________________________________________________________

____________________________________________________________
Here are the tasks in your list:

1. [T][X] wash car
____________________________________________________________

____________________________________________________________
OK! I've marked this task as not done yet:
[T][ ] wash car
____________________________________________________________

____________________________________________________________
Here are the tasks in your list:

1. [T][ ] wash car
____________________________________________________________

____________________________________________________________
Here are the tasks in your list:

1. [T][ ] wash car
2. [T][ ] Take out trash
____________________________________________________________

____________________________________________________________
Nice! I've marked this task as done:
[T][X] Take out trash
____________________________________________________________

____________________________________________________________
Here are the tasks in your list:

1. [T][ ] wash car
2. [T][X] Take out trash
3. [D][ ] assignment (by: Sunday 3pm)
____________________________________________________________

____________________________________________________________
Nice! I've marked this task as done:
[D][X] assignment (by: Sunday 3pm)
____________________________________________________________

____________________________________________________________
Here are the tasks in your list:

1. [T][ ] wash car
2. [T][X] Take out trash
3. [D][X] assignment (by: Sunday 3pm)
____________________________________________________________

____________________________________________________________
Here are the tasks in your list:

1. [T][ ] wash car
2. [T][X] Take out trash
3. [D][X] assignment (by: Sunday 3pm)
4. [D][ ] Celebration (from: morning to: night)
____________________________________________________________

Empty file added text-ui-test/EXPECTED_UNIX.txt
Empty file.
16 changes: 16 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
list
todo wash car
list
mark 1
list
unmark 1
list
todo Take out trash
list
mark 2
deadline assignment /by Sunday 3pm
list
mark 3
list
event Celebration /from morning /to night
list
Empty file modified text-ui-test/runtest.sh
100644 → 100755
Empty file.