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

[Adrian Ong] iP #302

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
a632fc9
Add BufferedReader and BufferedWriter
AdrianOngJJ Jan 22, 2022
dcc799e
Add Level-1
AdrianOngJJ Jan 22, 2022
3c42ef7
Adjust spacing of output
AdrianOngJJ Jan 22, 2022
9d19fad
Add list function
AdrianOngJJ Jan 22, 2022
abde661
Add ability to mark oand unmark
AdrianOngJJ Jan 22, 2022
fa48c36
Add Task class
AdrianOngJJ Jan 22, 2022
af97092
Add Deadlines.java and Events.java
AdrianOngJJ Jan 25, 2022
e881447
Add Events.java and complete Level 4
AdrianOngJJ Jan 25, 2022
a78a820
Complete Level 4
AdrianOngJJ Jan 26, 2022
bd3878a
Add Delete function
AdrianOngJJ Jan 26, 2022
24dd4bf
Test file creating
AdrianOngJJ Feb 3, 2022
4488007
Update text-ui-test/runtest.bat syntax
AdrianOngJJ Feb 3, 2022
b23d3e5
Merge branch 'branch-Level-7' of https://github.com/AdrianOngJJ/ip
AdrianOngJJ Feb 3, 2022
b6fe97a
Improve directory saving. Cannot create duke.txt
AdrianOngJJ Feb 3, 2022
cb3b03c
Improve saving duke.txt. Unable to create duke.txt file
AdrianOngJJ Feb 17, 2022
51c90f5
Remove merge conflicts
AdrianOngJJ Feb 17, 2022
c927b39
Solve merge issue for runtest.bat
AdrianOngJJ Feb 21, 2022
7e02ee6
Implement correct saving
AdrianOngJJ Feb 21, 2022
40d8e48
Add DateTime function
AdrianOngJJ Feb 23, 2022
1ccf369
Resolve merge conflict
AdrianOngJJ Feb 23, 2022
b56678c
Merge branch-Level-7 with branch-Level-8
AdrianOngJJ Feb 23, 2022
42d4ed2
Add skeleton classes for MoreOOP
AdrianOngJJ Feb 23, 2022
c5e310e
Merge branch 'master' of https://github.com/AdrianOngJJ/ip
AdrianOngJJ Feb 24, 2022
8f75ea8
Update Parser.java
AdrianOngJJ Mar 16, 2022
ce96454
Update MoreOOP
AdrianOngJJ Mar 17, 2022
5d04bbf
Complete MoreOOP
AdrianOngJJ Mar 17, 2022
bb998d2
Place all class in duke package
AdrianOngJJ Mar 17, 2022
98f5a26
Create JAR files
AdrianOngJJ Mar 17, 2022
1ece1cd
Add javadocs
AdrianOngJJ Mar 18, 2022
9ef56c0
Update Duke to reflect coding standards
AdrianOngJJ Mar 18, 2022
c10b3cb
Merge branch 'add-gradle-support' of https://github.com/AdrianOngJJ/i…
AdrianOngJJ Mar 18, 2022
7368650
Merge branch 'master' of https://github.com/AdrianOngJJ/ip
AdrianOngJJ Mar 21, 2022
07c59e8
Add default GUI
AdrianOngJJ Mar 21, 2022
5777f61
Add GUI
AdrianOngJJ Mar 25, 2022
7a7865f
Improve Duke response
AdrianOngJJ Mar 25, 2022
5d7f39c
Functioning JAR file
AdrianOngJJ Mar 26, 2022
9f12d19
Fix Deadline parser
AdrianOngJJ Mar 26, 2022
f50bbd8
Update UG
AdrianOngJJ Mar 26, 2022
2f2fd99
Add find command
AdrianOngJJ Mar 27, 2022
6ffaf57
Update UG with missing command delete and find
AdrianOngJJ Mar 27, 2022
aad47e2
Add bye command into UG
AdrianOngJJ Mar 27, 2022
b89ebdd
Update bye command in UG
AdrianOngJJ Mar 27, 2022
89ecb35
Undo bye command changes in UG
AdrianOngJJ Mar 27, 2022
83355a4
Add a maybe
AdrianOngJJ May 17, 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
19 changes: 19 additions & 0 deletions src/main/java/Deadlines.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Deadlines tasks that need to be done before a specific date/time
* e.g., submit report by 11/10/2019 5pm
*/

Choose a reason for hiding this comment

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

Consider, perhaps, deleting this line break between the comments and the function for consistency

public class Deadlines extends Task {

private final String deadline;

public Deadlines(String description, String deadline) {
super(description);
this.deadline = deadline;
}

@Override
public String toString() {
return "[D]" + super.toString() + "(by: " + this.deadline + ")";
}
}
Binary file added src/main/java/Duke.class
Binary file not shown.
127 changes: 126 additions & 1 deletion src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,135 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;

/**
* Project Duke is a educational software project designed to take you
* through the steps of building a small software incrementally,
* while applying as many Java and SE techniques as possible along the way.
*
* @author AdrianOngJJ
* @version 0.1
* @since 22/1/2022
*/
public class Duke {
public static void main(String[] args) {
private static final String LINE_BREAK = "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
private static final ArrayList<Task> masterList = new ArrayList<>();
/**
* Prints line break.
* @return void

Choose a reason for hiding this comment

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

Consider adding a line break between the description of a function and its associated Javadoc tags for consistency. I noticed the same issue across other functions as well.

Choose a reason for hiding this comment

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

Should the @return tag here be deleted? It is not required here as per Oracle guidelines since the return type is void. Do refer to Javadoc guidelines for a more thorough reference for the conventions with respect to Javadoc comments.

*/
private static final void printLineBreak() {
System.out.println(LINE_BREAK);
}

/**
* Prints Master List
* @param bw BufferedWriter from main to print out the Master List.
* @throws java.io.IOException If an I/O error occurs. Only takes in string.
*/
private static final void printList(BufferedWriter bw) throws Exception {

Choose a reason for hiding this comment

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

Nice job on catching this! Do consider throwing an explicit IOException if you mention it as such in the documentation for the code though

for(int i = 0; i < masterList.size(); i++) {

Choose a reason for hiding this comment

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

You might want to include a whitespace after the 'for' keyword here?

Task curr = masterList.get(i);
bw.write((i + 1) + "." + curr.toString());
bw.newLine();
}
bw.flush();

Choose a reason for hiding this comment

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

A very intuitive set of code!

I was wondering if there's also a need for whitespace after the "for" word?

Nonetheless, neat work :)

}

private static final String getDateTime(String[] inputArr) {
return inputArr[1].split("/")[1].split(" ", 2)[1]; // split input from slash

Choose a reason for hiding this comment

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

Perhaps include the comment as a same-level indent above the line as opposed to an inline one? I noticed this in other places as well.

Since this function consists of a single line at the moment, you might want to add Javadoc-style documentation instead.

}

private static final String getDescription(String[] inputArr) {
return inputArr[1].split("/")[0]; // split input from slash
}

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
printLineBreak();
System.out.println("Hello! I'm Duke\nWhat can I do for you?");
String input; // to store raw input command
String[] inputArr; // to store split input command
boolean ifBye = false;

Choose a reason for hiding this comment

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

Intuitive boolean to check if the program should exit or not!

However, maybe:

Suggested change
boolean ifBye = false;
boolean shouldAbort = false;

do {
printLineBreak();
System.out.println();
input = br.readLine();
inputArr = input.split(" ", 2); // split first word from body
printLineBreak();
switch (inputArr[0]) {

Choose a reason for hiding this comment

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

Do consider separating the code into logical blocks with line breaks for ease of viewing. For instance, here, the do-while loop can be separated from the rest of the preceding lines, and the initialization of variables (e.g. BufferedReader) can be separated in a similar fashion as well.

case "bye":
ifBye = true;
System.out.println("Bye. Hope to see you again soon!");
break;

case "list":

Choose a reason for hiding this comment

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

Good job on following the guidelines with respect to the indentation levels of switch and case! There should be no need for line breaks between individual case statements, so maybe remove these as a final step?

bw.write("Here are the tasks in your list:\n");
printList(bw);
break;

case "mark":
bw.write("Nice! I've marked this task as done:\n");
int index = Integer.parseInt(inputArr[1]) - 1;
Task curr = masterList.get(index); // task to be marked
masterList.set(index, curr.markAsDone());
bw.write(masterList.get(index).toString());
bw.flush();
break;

case "unmark":
bw.write("OK, I've marked this task as not done yet:\n");
int indexUnmark = Integer.parseInt(inputArr[1]) - 1;
Task currUnmark = masterList.get(indexUnmark); // task to be unmarked
masterList.set(indexUnmark, currUnmark.unmarkItem());
bw.write(masterList.get(indexUnmark).toString());
bw.flush();
break;

case "deadline":
masterList.add(new Deadlines(getDescription(inputArr), getDateTime(inputArr)));
System.out.println("Got it. I've added this task:\n\t "
+ (masterList.get(masterList.size() - 1)).toString()
+ "\nNow you have " + masterList.size() + " tasks in the list.");
break;

case "todo":
masterList.add(new ToDos(getDescription(inputArr)));
System.out.println("Got it. I've added this task:\n\t "
+ (masterList.get(masterList.size() - 1)).toString()
+ "\nNow you have " + masterList.size() + " tasks in the list.");
break;

case "event":
masterList.add(new Events(getDescription(inputArr), getDateTime(inputArr)));
System.out.println("Got it. I've added this task:\n\t "
+ (masterList.get(masterList.size() - 1)).toString()
+ "\nNow you have " + masterList.size() + " tasks in the list.");
break;

case "delete":
bw.write("Noted. I've removed this task:\n\t");
int indexDel = Integer.parseInt(inputArr[1]) - 1;
bw.write(masterList.remove(indexDel).toString());
bw.write("\nNow you have " + masterList.size() + " tasks in list.");
bw.flush();
break;


default:
System.out.println("Invalid input: " + input);
}
} while (!ifBye);
printLineBreak();

}
}
11 changes: 11 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Exception class for Duke to handle Exceptions
*/

public class DukeException extends Exception {

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

Choose a reason for hiding this comment

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

Awesome that this class is kept simple!

However, maybe there should be some comments to document on what kind of exceptions you are expecting? 😄


}
19 changes: 19 additions & 0 deletions src/main/java/Events.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Events are tasks that start at a specific time and ends at a specific time
* e.g., team project meeting on 2/10/2019 2-4pm
*/

public class Events extends Task {

private final String duration;

public Events(String description, String duration) {
super(description);
this.duration = duration;
}

@Override
public String toString() {
return "[E]" + super.toString() + "(at: " + this.duration + ")";
}
}
43 changes: 43 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Task class contains the task's name and whether it is completed
*/
public class Task {
protected String description;
protected boolean isDone;

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

/**
* Check if task is done
* @return String "X" to indicate if a task is done
*/
public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done with X
}

/**
* Mark item as done
* @return Item that is done
*/
public Task markAsDone() {
this.isDone = true;
return this;
}

/**
* Mark item as undone
* @return Item that is undone
*/
public Task unmarkItem() {
this.isDone = false;
return this;
}

@Override
public String toString() {
return "[" + getStatusIcon() + "] " + this.description;
}
}
13 changes: 13 additions & 0 deletions src/main/java/ToDos.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* To Dos are tasks without any date/time attached to it
*/
public class ToDos extends Task {
public ToDos(String description) {
super(description);
}

@Override
public String toString() {
return "[T]" + super.toString();
}
}
42 changes: 42 additions & 0 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,45 @@ Hello from
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hello! I'm Duke
What can I do for you?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

event project meeting /at Mon 2-4pm

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Got it. I've added this task:
[E][ ] project meeting (at: Mon 2-4pm)
Now you have 1 tasks in the list.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

deadline return book /by Sunday

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Got it. I've added this task:
deadline return book /by Sunday
Now you have 2 tasks in the list.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

list

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here are the tasks in your list:
1.[E][ ] project meeting (at: Mon 2-4pm)
2.[D][ ] return book (by: Sunday)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

bye

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Bye. Hope to see you again soon!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Process finished with exit code 0
10 changes: 10 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
todo read book
deadline return book /by June 6th
event project meeting /at Aug 6th 2-4pm
todo join sports club
mark 1
mark 4
todo borrow book
list
deadline return book /by Sunday
event project meeting /at Mon 2-4pm
4 changes: 2 additions & 2 deletions text-ui-test/runtest.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ REM delete output from previous run
if exist ACTUAL.TXT del ACTUAL.TXT

REM compile the code into the bin folder
javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\*.java
javac -cp C:\Users\adria\Desktop\iP\src\main\java -Xlint:none -d ..\bin C:\Users\adria\Desktop\iP\src\main\java\*.java
IF ERRORLEVEL 1 (
echo ********** BUILD FAILURE **********
exit /b 1
)
REM no error here, errorlevel == 0

REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT
java -classpath ..\bin Duke < input.txt > ACTUAL.TXT
java -classpath ../bin Duke < input.txt > ACTUAL.TXT

REM compare the output to the expected output
FC ACTUAL.TXT EXPECTED.TXT
2 changes: 1 addition & 1 deletion text-ui-test/runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ then
fi

# compile the code into the bin folder, terminates if error occurred
if ! javac -cp ../src/main/java -Xlint:none -d ../bin ../src/main/java/*.java
if ! javac -cp C:\Users\adria\Desktop\iP\src\main\java -Xlint:none -d ../bin C:\Users\adria\Desktop\iP\src\main\java*.java
then
echo "********** BUILD FAILURE **********"
exit 1
Expand Down