-
Notifications
You must be signed in to change notification settings - Fork 267
[Tan Juay Hee] iP #315
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
Open
juayhee
wants to merge
103
commits into
nus-cs2103-AY2122S2:master
Choose a base branch
from
juayhee:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Tan Juay Hee] iP #315
Changes from 27 commits
Commits
Show all changes
103 commits
Select commit
Hold shift + click to select a range
d839859
Add Gradle support
7b4399b
Duke.java: Added formatAnswer method for formatting Duke's outputs
juayhee 20727de
Duke.java: Updated main(): Duke will now echo all commands (except ex…
juayhee 97f6a4d
Duke.java: Fixed javadocs formatting
juayhee ed4337c
Command.java: Added Command class
juayhee cdbfc4d
* Abstracted commands - Duke.main() now only calls a CommandFactory t…
juayhee 8723e8a
Formatting
juayhee d966605
TaskManager.java: Added TaskManager, to manage a todo list for the user.
juayhee e873f1c
Updated scope of abstract method in Command to public
juayhee a0644ae
Added AddTaskCommand and ListCommand
juayhee d0aec24
TaskManager.java: Changed taskList to use ArrayList instead of array …
juayhee 1d0ed92
AddTaskCommand.java:
juayhee 7fd4062
ListCommand.java: Added formatted taskList printing.
juayhee 2f8c2dc
Added support for marking tasks as done/undone
juayhee bfabfc4
Revert "Added support for marking tasks as done/undone"
juayhee d0c7e0d
Revert "Revert "Added support for marking tasks as done/undone""
juayhee 61656f5
Added Mark and UnmarkCommand, for keeping track of completion status …
juayhee 57956c4
Formatting update
juayhee 3cf225d
Mark/Unmark formatting update
juayhee 248b305
Task inheritance
juayhee d82d80f
Added 3 types of tasks
juayhee b101bbd
Task.java: Updated tto become general parent class for the different …
juayhee 8287dd3
CommandFactory.java: Added factory methods for 3 new tasks (Event, De…
juayhee 3db0f4a
AddTaskCommand.java: Now adds the appropriate task to the TaskManager…
juayhee cfdfd2a
DeadlineTask: Formatting
juayhee 2af976f
DeadlineTask.java: Comment update
juayhee 4db97ca
EventTask.java: Completed functionality
juayhee 47f5f59
Duke lines
juayhee 966526c
Semi-automated testing
juayhee 30de0fd
Exception handling:
juayhee 5beda05
Added delete functionality for deleting tasks from the task list
juayhee d937b63
test commit
juayhee be5f127
Delete README.md copy
juayhee 69a5f11
Update EXPECTED.TXT
juayhee 74a2c76
Fix Issue #1
juayhee 5a8e292
Duke.java: Add tasklist.txt file on init functionality
juayhee f69c29e
Update gitignore
juayhee 7ad1b73
Merge branch 'master' of https://github.com/juayhee/ip
juayhee 44d9e53
Update Duke.java
juayhee fb0dcd4
Update Duke.java
juayhee 27ab11c
Update AddTaskCommand.java
juayhee c5b41cb
Merge branch 'master' into branch-Level-7
juayhee 5d651b4
Update Task.java
juayhee 3d44bb3
Update AddTaskCommand.java
juayhee bc740e1
Refactor the way Duke updates tasklist.txt
juayhee b2a7783
Add task saving ability
juayhee 5d6fe8d
Added Duke functionality
juayhee a4f8f9c
Fix reader mistake in TaskManager.java
juayhee f15ab5d
Change file writing process
juayhee bbeb23c
TaskManager.java: Delete unused code
juayhee 0956cbd
Change DeadlineTask.java
juayhee c083eea
Change date display
juayhee 2ef087b
Merge branch 'branch-Level-8'
juayhee 759928f
Add Ui to manage user interactions
juayhee 3840260
ByeCommand.java: Move system print to Ui
juayhee 80f7830
ListCommand.java: Move system print to Ui
juayhee e26c321
Ui.java: Improve output format of printAddTask()
juayhee b234b5f
MarkCommand.java: Move system print to ui
juayhee db98dc6
MarkCommand.java: Deprecate unused code
juayhee 0bed81c
Duke.java: Move introduction print to ui
juayhee 2361f53
DeleteCommand.java: Move delete confirmation print to ui
juayhee 52bda78
UnmarkCommand.java: Move delete confirmation print to ui
juayhee 85b1867
Delete a bunch of deprecated code
juayhee 73ac0f4
Delete EchoCommand.java
juayhee c183af8
Duke.java: Delete deprecated formatting code
juayhee 1d1dc1d
Rename TaskManager to TaskList
juayhee 8096783
Replace CommandFactory with Parser
juayhee 89bc29c
Refactor code
juayhee e31eb90
Move all files into package: duke
juayhee d786f16
Update gitignore
juayhee f7f91d0
no message
juayhee c19fdea
no message
juayhee a2f29b8
no message
juayhee 1007b0c
no message
juayhee a5ce67d
Duke.java: Fix error where duke tries to load the tasklist before the…
juayhee 7e7952b
Add ParserTest to test the parser for Duke
juayhee 8019fe1
Update ParserTest with more tests
juayhee 4d7e4e8
Add TaskTest.java to test Task.java of Duke
juayhee f804901
no message
juayhee 4510ca1
Add javadocs header comments
juayhee 8c54d0b
Formatting
juayhee 1f545cd
Add search function for tasks
juayhee f373b0b
Merge branch 'branch-A-CodingStandard'
juayhee 258aec9
Merge branch 'branch-A-JavaDoc'
juayhee 684b1ed
Fix additional whitespaces during printing of list
juayhee 20443e1
Merge remote-tracking branch 'origin/add-gradle-support'
juayhee f7cdf58
Gradle integration
juayhee 2b225c7
Add GUI classes
juayhee ad9f2d3
Add GUI mockup
juayhee 0921ff0
Add DialogBox stuff
juayhee 80c0521
Edit GUI to make Duke display text on one side and the user display t…
juayhee 6ade60a
Refactor userText variable
juayhee baf32d6
Link DukeGUI inputs to Duke
juayhee 1944558
DukeGUI now prints output correctly
juayhee 00d3761
Fix output formatting
juayhee 2263420
Update Gradle build file
juayhee 9988e6f
Add assertions
juayhee 31c8ffb
Delete dead code
juayhee 256c1e4
Merge pull request #3 from juayhee/branch-A-CodeQuality
juayhee 46aa19e
Merge branch 'master' into branch-A-Assertions
juayhee 5006aec
Merge pull request #4 from juayhee/branch-A-Assertions
juayhee a59d26f
Add command aliases to Duke
juayhee 874de1e
Add product website, fix bugs
juayhee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /** | ||
| * Generates the correct type of task and adds it to the task list | ||
| */ | ||
|
|
||
| public class AddTaskCommand extends Command { | ||
|
|
||
| private String input; // Details of the task | ||
| private String type; // Type of task | ||
|
|
||
| public AddTaskCommand(String input, String type) { | ||
| this.input = input; | ||
| this.type = type; | ||
| } | ||
|
|
||
| /** | ||
| * Formats the echo for the task that was added to the user as confirmation | ||
| * @return Formatted echo | ||
| */ | ||
| private String formatOutput(Task newTask) { | ||
| String response = "added: " + newTask.toString(); | ||
| String formattedString = Duke.indent(response, 1); | ||
| String finalFormatted = Duke.formatLines(formattedString); | ||
|
|
||
| return finalFormatted; | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| Task newTask; | ||
| if (this.type.equals("todo")) { | ||
| newTask = new TodoTask(this.input); | ||
| } else if (this.type.equals("deadline")) { | ||
| newTask = new DeadlineTask(this.input); | ||
| } else if (this.type.equals("event")) { | ||
| newTask = new EventTask(this.input); | ||
| } else { | ||
| newTask = null; | ||
| } | ||
|
|
||
| // Adding task to TaskManager | ||
| TaskManager.taskList.add(newTask); | ||
|
|
||
| // System prints | ||
| String output = formatOutput(newTask); | ||
| System.out.println(output); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /** | ||
| * Prints bye message, terminating command for Duke.main() | ||
| */ | ||
| public class ByeCommand extends Command { | ||
|
|
||
| final String EXIT = "Duke terminated"; | ||
|
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 use of naming standards |
||
|
|
||
| private String formatOutput() { | ||
| String formattedBye = Duke.indent(EXIT, 1); | ||
| String finalFormatted = Duke.formatLines(formattedBye); | ||
|
|
||
| return finalFormatted; | ||
| } | ||
| @Override | ||
| public void execute() { | ||
| // Console prints | ||
| String output = formatOutput(); | ||
|
|
||
| System.out.println(output); | ||
|
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| public abstract class Command { | ||
| public abstract void execute(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /** | ||
| * Decides which type of command to generate given user input | ||
| */ | ||
| public class CommandFactory { | ||
|
|
||
| /** | ||
| * Extracts the command portion of the input provided by the user (usually first word) | ||
| * | ||
| * @param input Input from the user | ||
| * @return One word string | ||
| */ | ||
| private String isolateCommand(String input) { | ||
| int whiteSpaceIndex = input.indexOf(" "); // Index of first whitespace | ||
| if (whiteSpaceIndex == -1) { // If the input string has no whitespaces (i.e. one word) | ||
| return input; | ||
| } | ||
| return input.substring(0, whiteSpaceIndex); | ||
| } | ||
|
|
||
| /** | ||
| * Extracts the command parameters portion of the input provided by the user (stuff after first word) | ||
| * | ||
| * @param input Input from the user | ||
| * @return Multiple-word string | ||
| */ | ||
| private String isolateParameters(String input) { | ||
| int whiteSpaceIndex = input.indexOf(" "); // Index of first whitespace | ||
| if (whiteSpaceIndex == -1) { // If the input string has no whitespaces (i.e. one word) | ||
| return null; | ||
| } | ||
| return input.substring(whiteSpaceIndex + 1); // Return the rest of the word, starting from after whitespace | ||
| } | ||
|
|
||
| /** | ||
| * Generates the appropriate command type given the input | ||
| * | ||
| * @param input Input from the user | ||
| * @return Value of parent type Command | ||
| */ | ||
| public Command makeCommand(String input) { | ||
| String commandWord = isolateCommand(input); | ||
| String commandParameters = isolateParameters(input); | ||
|
|
||
| if (commandWord.equals("bye")) { | ||
| return new ByeCommand(); | ||
| } else if (commandWord.equals("list")) { | ||
| return new ListCommand(); | ||
| } else if (commandWord.equals("mark")) { | ||
| return new MarkCommand(commandParameters); | ||
| } else if (commandWord.equals("unmark")) { | ||
| return new UnmarkCommand(commandParameters); | ||
| } else if (commandWord.equals("todo")) { | ||
| return new AddTaskCommand(commandParameters, "todo"); | ||
| } else if (commandWord.equals("deadline")) { | ||
| return new AddTaskCommand(commandParameters, "deadline"); | ||
| } else if (commandWord.equals("event")) { | ||
| return new AddTaskCommand(commandParameters, "event"); | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| public class DeadlineTask extends Task { | ||
| public DeadlineTask(String input) { | ||
| super(input); | ||
| this.type = "deadline"; | ||
| this.updateDescription(); | ||
| } | ||
|
|
||
| /** | ||
| * Format DeadlineTask description into display format for Duke | ||
| */ | ||
| private void updateDescription() { | ||
| this.description += this.getInfo(); | ||
| this.description += "(by: "; | ||
| this.description += this.getDate(); | ||
| this.description += ")"; | ||
|
Comment on lines
+18
to
+
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. I like your proper use of method naming standards(descriptive, camelCased verbs) |
||
| } | ||
|
|
||
| /** | ||
| * Find the index from which datetime information starts | ||
| * | ||
| * @return Integer index | ||
| */ | ||
| private int findDeadlineIndex() { | ||
| int index = this.input.indexOf("/by "); // "/" as delimiting character for events | ||
| return index; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the task information | ||
| * | ||
| * @return Task information | ||
| */ | ||
| private String getInfo() { | ||
| int index = this.findDeadlineIndex(); | ||
| String info = this.input.substring(0, index); | ||
|
|
||
| return info; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the deadline date | ||
| * | ||
| * @return Deadline date string | ||
| */ | ||
| private String getDate() { | ||
| int index = this.findDeadlineIndex() + 4; | ||
| String date = this.input.substring(index); | ||
|
|
||
| return date; | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,96 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Duke { | ||
| public static void main(String[] args) { | ||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| // Constant strings | ||
| final String INTRO = "Duke initialised"; | ||
|
|
||
| // Init | ||
| Scanner sc = new Scanner(System.in); | ||
|
|
||
| // Printing Duke's intro | ||
| String formattedIntroText = Duke.indent(INTRO, 1); | ||
| String formattedIntro = Duke.formatLines(formattedIntroText); | ||
| System.out.println(formattedIntro); | ||
|
|
||
| // Reading and processing inputs | ||
| String nextLine = sc.nextLine(); | ||
| CommandFactory commandFactory = new CommandFactory(); | ||
| while (true) { | ||
| Command nextCommand = commandFactory.makeCommand(nextLine); // Creating the appropriate command | ||
| nextCommand.execute(); | ||
|
|
||
| if (nextCommand instanceof ByeCommand) { // Check for exit command | ||
| break; | ||
| } | ||
| nextLine = sc.nextLine(); // Update nextLine variable with next input | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Checks if input is "bye" | ||
| */ | ||
| private boolean isBye(String input) { | ||
|
|
||
| return (input.equals("bye")); | ||
| } | ||
|
|
||
| /** | ||
| * Formats the given input between lines | ||
| * @param input Formatted input with proper indents and newlines. | ||
| */ | ||
| public static String formatLines(String input) { | ||
| String output = ""; | ||
| output += Duke.line(); | ||
| output += input; | ||
| output += "\n" + Duke.line(); | ||
|
|
||
| return output; | ||
| } | ||
|
|
||
| /** | ||
| * Provides a formatting line for Duke's responses | ||
| * | ||
| * @return A formatted line | ||
| */ | ||
| public static String line() { | ||
| String line = "\t____________________________________________________________\n"; | ||
| return line; | ||
| } | ||
|
|
||
| /** | ||
| * Formats a single line with a new line | ||
| * | ||
| * @param input Input string | ||
| * @return String with newline | ||
| */ | ||
| public static String newLine(String input) { | ||
| String output = input + "\n"; | ||
| return output; | ||
| } | ||
|
|
||
| /** | ||
| * Formats a single line with the specified number of indentations | ||
| * | ||
| * @param input Input string | ||
| * @param indents Number of indents to add | ||
| * @return String with specified number of indents | ||
| */ | ||
| public static String indent(String input, int indents) { | ||
| String indent = ""; | ||
| String output = ""; | ||
|
|
||
| // Adding the appropriate number of indents | ||
| for (int i = 0; i < indents; i++) { | ||
| indent += "\t"; | ||
| } | ||
|
|
||
| // Forming the final string | ||
| output = indent + input; | ||
|
|
||
| return output; | ||
|
|
||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /** | ||
| * Repeats input to user | ||
| */ | ||
| public class EchoCommand extends Command { | ||
|
|
||
| private String input; | ||
|
|
||
| public EchoCommand (String input) { | ||
| this.input = input; | ||
| } | ||
|
|
||
| public String formatOutput (String input) { | ||
| String formattedInput = Duke.indent(input, 1); | ||
| String finalFormatted = Duke.formatLines(formattedInput); | ||
|
|
||
| return finalFormatted; | ||
| } | ||
| @Override | ||
| public void execute() { | ||
|
|
||
| // Console prints | ||
| String output = formatOutput(input); | ||
| System.out.println(output); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| public class EventTask extends Task { | ||
| public EventTask(String input) { | ||
| super(input); | ||
| this.type = "event"; | ||
| this.updateDescription(); | ||
| } | ||
|
|
||
| /** | ||
| * Format EventTask description into display format for Duke | ||
| */ | ||
| private void updateDescription() { | ||
| this.description += this.getInfo(); | ||
| this.description += "(at: "; | ||
| this.description += this.getDate(); | ||
| this.description += ")"; | ||
| } | ||
|
|
||
| /** | ||
| * Find the index from which datetime information starts | ||
| * @return Integer index | ||
| */ | ||
| private int findEventIndex() { | ||
| int index = this.input.indexOf("/at "); // "/at" as delimiting character for events | ||
| return index; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the task information | ||
| * @return Task information | ||
| */ | ||
| private String getInfo() { | ||
| int index = this.findEventIndex(); | ||
| String info = this.input.substring(0, index); | ||
|
|
||
| return info; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the deadline date | ||
| * @return Deadline date string | ||
| */ | ||
| private String getDate() { | ||
| int index = this.findEventIndex() + 4; // Offset of the string "/at " | ||
| String date = this.input.substring(index); | ||
|
|
||
| return date; | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I believe class names should be nouns written in camelCasing according to coding standards.