-
Notifications
You must be signed in to change notification settings - Fork 270
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
base: master
Are you sure you want to change the base?
[Adrian Ong] iP #302
Changes from 11 commits
d839859
a632fc9
dcc799e
3c42ef7
9d19fad
abde661
fa48c36
af97092
e881447
a78a820
bd3878a
24dd4bf
4488007
b23d3e5
b6fe97a
cb3b03c
51c90f5
c927b39
7e02ee6
40d8e48
1ccf369
b56678c
42d4ed2
c5e310e
8f75ea8
ce96454
5d04bbf
bb998d2
98f5a26
1ece1cd
9ef56c0
c10b3cb
7368650
07c59e8
5777f61
7a7865f
5d7f39c
9f12d19
f50bbd8
2f2fd99
6ffaf57
aad47e2
b89ebdd
89ecb35
83355a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
*/ | ||
|
||
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 + ")"; | ||
} | ||
} |
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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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++) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
do { | ||||||
printLineBreak(); | ||||||
System.out.println(); | ||||||
input = br.readLine(); | ||||||
inputArr = input.split(" ", 2); // split first word from body | ||||||
printLineBreak(); | ||||||
switch (inputArr[0]) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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": | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||||||
|
||||||
} | ||||||
} |
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); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? 😄 |
||
|
||
} |
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 + ")"; | ||
} | ||
} |
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; | ||
} | ||
} |
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(); | ||
} | ||
} |
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 |
There was a problem hiding this comment.
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