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

[Brian Chow] iP #296

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
487213c
Level-1
brian16600 Jan 19, 2022
63bd8fe
Level-2. Changed the return values of levelOneRespond and implemented…
brian16600 Jan 20, 2022
63b7384
Level-3
brian16600 Jan 20, 2022
5188549
Level-3
brian16600 Jan 20, 2022
629d77c
Level-3
brian16600 Jan 21, 2022
62a2177
Level-4.
brian16600 Jan 26, 2022
49d9e0a
Level-5.
brian16600 Jan 29, 2022
89c0746
Level-6
brian16600 Jan 29, 2022
22f31af
Level-7
brian16600 Feb 2, 2022
a2b7ffd
Level-8
brian16600 Feb 3, 2022
3c16b7b
Added Parser, Storage and Tasklist
brian16600 Feb 5, 2022
633dca6
Added TaskList and Parser classes. TaskList contains the arraylist of…
brian16600 Feb 5, 2022
38a2462
Added more OOP and documentation
brian16600 Feb 5, 2022
e129edd
Added packages: duke.duke, duke.ui, duke.storage and duke.task
brian16600 Feb 5, 2022
cd020f5
Merge branch 'add-gradle-support'
brian16600 Feb 5, 2022
6ace068
Added add-gradle-support branch by merging into master
brian16600 Feb 5, 2022
33617d4
Ensured javadoc documentation is complete for all methods
brian16600 Feb 5, 2022
6da11ff
Added InputHandlerTest.java and TaskListTest.java
brian16600 Feb 6, 2022
ae099f5
Added NumberFormatException handling for delete, unmark and mark if n…
brian16600 Feb 6, 2022
390edec
Changed formatting for coding standards based on feedback
brian16600 Feb 6, 2022
2607baf
Added find and NumberFormatException in cases where non-integer is pa…
brian16600 Feb 6, 2022
aca80eb
Added JAR functionality
brian16600 Feb 12, 2022
f97ff93
Shifted into packages
brian16600 Feb 12, 2022
bb37f21
revert
brian16600 Feb 12, 2022
255fbef
Tentative changes
brian16600 Feb 12, 2022
b4458cc
Adding Duke GUI
brian16600 Feb 15, 2022
3960ddc
Add Assertions
brian16600 Feb 15, 2022
9bd5f23
Clean up text-ui-test
brian16600 Feb 15, 2022
ee148e4
Tentative changes to code quality
brian16600 Feb 15, 2022
5344d8e
Improve Code Quality based on Issue Tracker
brian16600 Feb 16, 2022
747cd67
Merge pull request #2 from brian16600/branch-A-CodeQuality
brian16600 Feb 16, 2022
fee4ebb
Update README.md
brian16600 Feb 17, 2022
e1dec30
Update README.md
brian16600 Feb 17, 2022
c126d99
Create README.md
brian16600 Feb 17, 2022
133c672
Update README.md
brian16600 Feb 17, 2022
5d7d4fb
Update README.md
brian16600 Feb 17, 2022
87677f2
Update README.md
brian16600 Feb 17, 2022
805ab54
Update README.md
brian16600 Feb 17, 2022
effc8c7
Update README.md
brian16600 Feb 17, 2022
5e3b5c9
Update README.md
brian16600 Feb 17, 2022
9004041
Temporary addition of Snooze.
brian16600 Feb 17, 2022
4c29aa2
Add snooze command
brian16600 Feb 17, 2022
68e9fea
Merge branch 'master' of https://github.com/brian16600/ip
brian16600 Feb 17, 2022
436be42
Add Ui.png
brian16600 Feb 17, 2022
38d5c9a
Add Ui.png
brian16600 Feb 17, 2022
56d537e
Update README.md
brian16600 Feb 17, 2022
18b7995
Update README.md
brian16600 Feb 17, 2022
ca00570
Update README.md
brian16600 Feb 17, 2022
4460756
Update README.md
brian16600 Feb 17, 2022
a58d8da
Update README.md
brian16600 Feb 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
20 changes: 20 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;


/**
* Represents a Deadline which is a subclass of Task
* Includes a dueDate attribute. Overrides toString() from Task
*/
public class Deadline extends Task {
private String dueDate;
public Deadline(String name, String time) {super(name); this.dueDate = time;}

Choose a reason for hiding this comment

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

Missing javadocs for constructor.

Choose a reason for hiding this comment

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

Could leave spacing for better readability.


/**
* @override
* @return String of Deadline task, eg [D][X] Deadline (by:XX)
*/

Choose a reason for hiding this comment

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

Override should not be in the javadoc. Missing method's description for the javadoc.
Recommendation:

/**
* Prints the String representation for the Deadline task.
* 
* @return String of Deadline task, eg [D][X] Deadline (by:XX)
* /
@Override
public String toString() {...}


public String toString() { return "[D]" + super.toString() + "(by:" + this.dueDate + ")"; }
}
32 changes: 31 additions & 1 deletion src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
import java.util.Scanner; //import Scanner
import java.util.ArrayList; //import ArrayList
import java.util.Arrays; //import Arrays

public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
String dukeGreeting = "Hello! I'm Duke \nWhat can I do for you?";
String endMessage = "Bye. Hope to see you again soon!";

System.out.println(dukeGreeting);
Scanner sc = new Scanner(System.in);
InputHandler inputHandler = new InputHandler();
boolean isChatEnded = false;
while (!isChatEnded) {
try {
String input = sc.nextLine();
isChatEnded = inputHandler.handleInput(input);
} catch (DukeException e) {
System.out.println(e.getMessage());
}
}
System.out.println(endMessage);
}


}









Choose a reason for hiding this comment

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

Could clear by these empty spaces.

Choose a reason for hiding this comment

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

Agreed

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 @@
public class DukeException extends Exception{

Choose a reason for hiding this comment

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

Missing javadoc for class.

private String errorMessage;
public DukeException (String errorMessage) {
this.errorMessage = errorMessage;
}

/**
* @override
* @return String errorMessage
*/
public String getMessage() {return this.errorMessage;}
}
18 changes: 18 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;

/**
* Represents a Event which is a subclass of Task
* Overrides toString() from Task
*/
public class Event extends Task {
private String dueDate;
public Event (String name, String time) { super(name); this.dueDate = time;}

Choose a reason for hiding this comment

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

This do not follow the module coding standards.


/**
* @override
* @return String of Event task, eg: [E][X] Event
*/
public String toString() { return "[E]" + super.toString() + "(at:" + this.dueDate + ")"; }
}
127 changes: 127 additions & 0 deletions src/main/java/InputHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import java.util.ArrayList;
import java.util.Arrays;

/**
* Handles input in main in Duke.java. Receives String from Scanner in main
* Processes the input into 7 categories: Todo, Event, Deadline, list, mark, unmark, bye and throws error
*/
public class InputHandler {
private ArrayList<Task> arr;

Choose a reason for hiding this comment

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

Might be better to have a more specific and plural name for a list of task.
Recommendation:

private ArrayList<Task> tasks;

public InputHandler() {
this.arr = new ArrayList<>();
}


/**
*

Choose a reason for hiding this comment

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

Missing method description for javadoc.

* @param input String input from main in Duke.java, from user input
* @return boolean representing isChatEnded variable in main. If "bye" command is given, a true boolean is returned, else false is returned
* @throws DukeException Invalid input types, or unrecognisable commands
*/
public boolean handleInput(String input) throws DukeException {
String[] splitInput = input.split(" ");
String inputCommand = splitInput[0];
switch (inputCommand) {
case "todo":

Choose a reason for hiding this comment

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

I didn't like the indentation after the switch, are you sure this complies with the coding standard? Consider leaving no indentation for the case statements.

if (splitInput.length > 1) {
String[] nameArray = Arrays.copyOfRange(splitInput, 1, splitInput.length);
String name = String.join(" ", nameArray);
Todo newTodo = new Todo(name);
arr.add(newTodo);
printAddTaskMessage(newTodo);
return false;
} else {
throw new DukeException(":( OOPS!!! The description of a todo cannot be empty. Correct usage: todo [task]");
}
case "event":
if (splitInput.length > 3) {
String[] stringArrayExcludingEvent = Arrays.copyOfRange(splitInput, 1, splitInput.length);
String stringExcludingEvent = String.join(" ", stringArrayExcludingEvent);
String[] nameAndTimeArray = stringExcludingEvent.split("/at");
String name = nameAndTimeArray[0];
String time = nameAndTimeArray[1];
Event newEvent = new Event(name, time);
arr.add(newEvent);
printAddTaskMessage(newEvent);
return false;
} else {
throw new DukeException(":( OOPS!!! The description of a event cannot be empty. Correct usage: event [task] /at [time]");
}
case "deadline":
if (splitInput.length > 3) {
String[] stringArrayExcludingDeadline = Arrays.copyOfRange(splitInput, 1, splitInput.length);
String stringExcludingDeadline = String.join(" ", stringArrayExcludingDeadline);
String[] nameAndTimeArray = stringExcludingDeadline.split("/by");
String name = nameAndTimeArray[0];
String time = nameAndTimeArray[1];
Deadline newDeadline = new Deadline(name, time);
arr.add(newDeadline);
printAddTaskMessage(newDeadline);
return false;
} else {
throw new DukeException(":( OOPS!!! The description of a deadline cannot be empty. Correct usage: deadline [task] /by [time]");
}
case "list":
if (splitInput.length == 1) {
System.out.println("Here are the tasks in your list:");
int i = 0;
for (Task item : arr) {
i += 1;
if (item.isMark()) {
System.out.println(i + ". " + item);
} else {
System.out.println(i + ". " + item);
}
}
return false;
} else {
throw new DukeException("Wrong usage of list! Correct usage: list");
}
case "mark":
if (splitInput.length == 2) {
System.out.println("Nice! I've marked this task as done:\n");
int idx = Integer.parseInt(splitInput[1]) - 1;
Task taskToBeMarked = arr.get(idx);
taskToBeMarked.markTask();
return false;
} else {
throw new DukeException("Wrong usage of mark! Correct usage: mark [index]");
}
case "unmark":
if (splitInput.length == 2) {
System.out.println("OK, I've marked this task as not done yet:\n");
int idx = Integer.parseInt(splitInput[1]) - 1;
Task taskToBeUnmarked = arr.get(idx);
taskToBeUnmarked.unmarkTask();
return false;
} else {
throw new DukeException("Wrong usage of unmark! Correct usage: unmark [index]");
}
case "delete":
if (splitInput.length == 2) {
int idx = Integer.parseInt(splitInput[1]) - 1;
Task taskToBeDeleted = arr.get(idx);
arr.remove(idx);
System.out.println("Noted. I've removed this task:\n" + taskToBeDeleted + "\nNow you have " + arr.size() + " tasks in the list");
return false;
} else {
throw new DukeException("Wrong usage of delete! Correct usage: delete [index]");
}
case "bye":
return true;
default:
throw new DukeException(":( OOPS!!! I'm sorry, but I don't know what that means! Possible commands: todo [task], event [task] /at [time],"

Choose a reason for hiding this comment

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

Could add indentation.

+ " deadline [task] /by [time], mark [index], unmark [index], delete [index], bye");
}

Choose a reason for hiding this comment

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

This method severely exceeds the recommended number of lines in a method (30).
Recommendation:
Can try to abstract out the details of each case statement into a different method.


}

/**
* Prints out the task name that has been added as well as the number of tasks in the list
* @param task The task that has been added
*/
public void printAddTaskMessage(Task task) {
System.out.println("Got it. I've added this task:\n" + task + "\nNow you have " + arr.size() + " tasks in the list." );
}
}

60 changes: 60 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;

/**
* Represents a Task. Contains a Task constructor, two methods to mark and unmark tasks, toString() method as well as a isMark() method to check if Task is marked

Choose a reason for hiding this comment

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

Could add indentation.

*/
public class Task {
private boolean mark;

Choose a reason for hiding this comment

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

Not sure I like the naming of the boolean variable. As much as possible, use a prefix such as is, has, was, etc. for boolean variable/method names so that linters can automatically verify that this style rule is being followed. Perhaps it would be better to name it as follows?

Suggested change
private boolean mark;
private boolean isMarked;

public String name;

/**
* Constructor

Choose a reason for hiding this comment

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

Might be better to have a more specific description of a constructor instead of simply "Constructor".
Recommendation:

/**
* Creates a task object with the given parameter as the name of the task.
* @param name name of the task
*/

* @param name name of the task
*/
public Task (String name) {
this.name = name;
this.mark = false;
}

/**
* markTask as done
*/
public void markTask () {

Choose a reason for hiding this comment

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

Should this be named in this manner? Perhaps the following would comply with the coding standards better.

Suggested change
public void markTask () {
public void setMarkedTask () {

String markedMessage = "Nice! I've marked this task as done:\n";
this.mark = true;
System.out.println(markedMessage + " " + this);
}

/**
* unmarkTask
*/
public void unmarkTask() {

Choose a reason for hiding this comment

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

Should this be named in this manner? Perhaps the following would comply with the coding standards better.

Suggested change
public void unmarkTask() {
public void setUnmarkedTask () {

String unmarkedMessage = "OK, I've marked this task as not done yet:\n";
this.mark = false;
System.out.println(unmarkedMessage + " " + this);
}

/**
*
* @return boolean on whether task is marked
*/
public boolean isMark() {

Choose a reason for hiding this comment

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

Should this be changed to another name, if you do decide to accept the suggestion of the boolean variable naming? Perhaps the following would work.

Suggested change
public boolean isMark() {
public void hasBeenMarked () {

return this.mark;
}

/**
* @override
* @return String version of task, with marked and name. E.g. [X] Task
*/
public String toString() {
if (this.mark) {
String marked = "[X] ";
return marked + this.name;
} else {
String unmarked = "[ ] ";
return unmarked + this.name;
}
}
}
23 changes: 23 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;

/**
* Represents a Todo which is a subclass of Task
* Includes a dueDate attribute. Overrides toString() from Task
*/

public class Todo extends Task {
public Todo (String name) {
super(name);
}

/**
* @override
* @return String of Todo task, eg: [T][X] Todo
*/
public String toString() {
return "[T]" + super.toString();
}

}