-
Notifications
You must be signed in to change notification settings - Fork 114
[Ong JunZheng] iP #114
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
kaboomzxc
wants to merge
38
commits into
nus-cs2113-AY2425S1:master
Choose a base branch
from
kaboomzxc: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
[Ong JunZheng] iP #114
Changes from 20 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
b44b350
Refractor Duke to Quinn and implement Level-0
1a384e7
Implement Level-1
80154db
Implement Level-2
83bc054
Implement Level-3 and adhere to coding standard
9cdfdcd
Implement Level-4
e9a5a29
Implement Level-5 and review code quality
6a82856
Merge branch 'branch-Level-5'
8e7dc1c
Organise classes into different packages
e16f866
Merge branch 'branch-A-Packages'
53936b5
Update README.md
b25c7de
Implement Level-6
b06b90c
Fix some text errors due to refactoring
9c924df
Merge branch 'master' into branch-Level-6
bdaa224
Fix text errors in Quinn java file
6799df1
Merge branch 'master' into branch-Level-6
9dde6b8
Implement Level-7
d8e6940
Merge branch 'branch-Level-6'
06ca525
Merge branch 'branch-Level-7'
db7785f
Implement saving after deletion of tasks
8a57ddf
update some responses by quinn
b35fedf
Implement A-MoreOOP, refactor code to extract out more classes
a9c924a
Implement Level-8 for chatbot to understand date time
b46f621
Implement Level-9
68cff40
Merge pull request #1 from kaboomzxc/branch-Level-8
kaboomzxc c29453c
Merge branch 'master' into branch-Level-9
5b746ce
Merge pull request #2 from kaboomzxc/branch-Level-9
kaboomzxc 02bc63a
Added JavaDoc comments
a4e9125
Merge pull request #3 from kaboomzxc/branch-A-JavaDoc
kaboomzxc c621d5e
Implement User Guide
b0bf095
Update User Guide
bb7a02e
Update User Guide
0054652
Update User Guide
626cc6b
Update User Guide
e0003ff
Update User Guide
2d4c709
Update download link
0681301
Update UG
1444e91
remove "build.gradle" file
389da92
Change "Checkmark" symbol to "X" symbol
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
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,4 +1,4 @@ | ||
| # Duke User Guide | ||
| # quinn.Quinn User Guide | ||
|
|
||
| // Update the title above to match the actual product name | ||
|
|
||
|
|
||
This file was deleted.
Oops, something went wrong.
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,312 @@ | ||
| package quinn; | ||
|
|
||
| import quinn.exception.QuinnException; | ||
| import quinn.task.Deadline; | ||
| import quinn.task.Event; | ||
| import quinn.task.Task; | ||
| import quinn.task.ToDo; | ||
| import quinn.ui.Ui; | ||
| import quinn.storage.Storage; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class Quinn { | ||
| private final Ui ui; | ||
| private Storage storage; | ||
| private List<Task> tasks; | ||
|
|
||
| public Quinn(String folderName, String fileName) { | ||
| ui = new Ui(); | ||
|
|
||
| try { | ||
| storage = new Storage(folderName, fileName); | ||
| tasks = storage.loadTasksFromFile(); | ||
| } catch (QuinnException | IOException e) { | ||
| ui.displayError(e.getMessage()); | ||
| tasks = new ArrayList<>(); | ||
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| new Quinn("data", "tasks.txt").run(); | ||
| } | ||
|
|
||
| public void run() { | ||
| ui.displayWelcome(); | ||
|
|
||
| String commandLine = ""; | ||
|
|
||
| while (!commandLine.equals("bye")) { | ||
| commandLine = ui.readCommand(); | ||
|
|
||
| try { | ||
| processCommand(commandLine); | ||
| } catch (QuinnException | IOException e) { | ||
| ui.displayError(e.getMessage()); | ||
| } finally { | ||
| ui.displayLine(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void processCommand(String commandLine) throws QuinnException, IOException { | ||
| String[] commandLineParts = commandLine.split(" ", 2); | ||
|
|
||
| String commandType; | ||
| String commandInfo; | ||
|
|
||
| if (commandLineParts.length == 2) { | ||
| commandType = commandLineParts[0].trim(); | ||
| commandInfo = commandLineParts[1].trim(); | ||
|
|
||
| if ((commandType.equals("bye") || commandType.equals("list")) && !commandInfo.isEmpty()) { | ||
| throw new QuinnException("INVALID COMMAND. Please try again!"); | ||
| } | ||
| } else { // for "bye" and "list" commands which does not have any input behind | ||
| commandType = commandLineParts[0]; | ||
| commandInfo = ""; | ||
| } | ||
|
|
||
| executeCommand(commandType, commandInfo); | ||
| } | ||
|
|
||
| public void executeCommand(String commandType, String commandInfo) throws QuinnException, IOException { | ||
| int taskNum; | ||
| Task task; | ||
| String taskDescription; | ||
| String taskInfo; | ||
|
|
||
| switch (commandType.toLowerCase()) { | ||
| case "bye": | ||
| ui.displayExit(); | ||
| break; | ||
| case "list": | ||
| displayTasks(); | ||
| break; | ||
| case "mark": | ||
| taskNum = getTaskNumFromMarkCommand(commandInfo); | ||
| markTask(taskNum); | ||
| break; | ||
| case "unmark": | ||
| taskNum = getTaskNumFromUnmarkCommand(commandInfo); | ||
| unmarkTask(taskNum); | ||
| break; | ||
| case "delete": | ||
| taskNum = getTaskNumFromDeleteCommand(commandInfo); | ||
| deleteTask(taskNum); | ||
| break; | ||
| case "todo": | ||
| taskDescription = getTaskDescriptionFromToDoCommand(commandInfo); | ||
| task = new ToDo(taskDescription); | ||
| addTask(task); | ||
| break; | ||
| case "deadline": | ||
| taskInfo = processTaskInfoFromDeadlineCommand(commandInfo); | ||
| String[] deadlineTaskDetails = taskInfo.split("/by", 2); | ||
| task = new Deadline(deadlineTaskDetails[0].trim(), deadlineTaskDetails[1].trim()); | ||
| addTask(task); | ||
| break; | ||
| case "event": | ||
| taskInfo = processTaskInfoFromEventCommand(commandInfo); | ||
| String[] eventTaskDetails = taskInfo.split("/from|/to", 3); | ||
| task = new Event(eventTaskDetails[0].trim(), eventTaskDetails[1].trim(), eventTaskDetails[2].trim()); | ||
| addTask(task); | ||
| break; | ||
| default: | ||
| throw new QuinnException("INVALID COMMAND. Please try again!"); | ||
| } | ||
| } | ||
|
|
||
| private boolean isCommandInfoPresent(String commandInfo) { | ||
| return !commandInfo.trim().isEmpty(); | ||
| } | ||
|
|
||
| private int getTaskNumFromMarkCommand(String commandInfo) throws QuinnException { | ||
| if (isCommandInfoPresent(commandInfo)) { | ||
| try { | ||
| return Integer.parseInt(commandInfo); | ||
| } catch (NumberFormatException e) { | ||
| throw new QuinnException("Please enter a valid task number to be marked as done!"); | ||
| } | ||
| } else { | ||
| throw new QuinnException("Please enter a task number to be marked as done!"); | ||
| } | ||
| } | ||
|
|
||
| private int getTaskNumFromUnmarkCommand(String commandInfo) throws QuinnException { | ||
| if (isCommandInfoPresent(commandInfo)) { | ||
| try { | ||
| return Integer.parseInt(commandInfo); | ||
| } catch (NumberFormatException e) { | ||
| throw new QuinnException("Please enter a valid task number to be marked as not done yet!"); | ||
| } | ||
| } else { | ||
| throw new QuinnException("Please enter a task number to be marked as not done yet!"); | ||
| } | ||
| } | ||
|
|
||
| private int getTaskNumFromDeleteCommand(String commandInfo) throws QuinnException { | ||
| if (isCommandInfoPresent(commandInfo)) { | ||
| try { | ||
| return Integer.parseInt(commandInfo); | ||
| } catch (NumberFormatException e) { | ||
| throw new QuinnException("Please enter a valid task number to be deleted!"); | ||
| } | ||
| } else { | ||
| throw new QuinnException("Please enter a task number to be deleted!"); | ||
| } | ||
| } | ||
|
|
||
| private String getTaskDescriptionFromToDoCommand(String commandInfo) throws QuinnException { | ||
| if (isCommandInfoPresent(commandInfo)) { | ||
| return commandInfo; | ||
| } else { | ||
| throw new QuinnException("The description of a todo cannot be empty!"); | ||
| } | ||
| } | ||
|
|
||
| private String processTaskInfoFromDeadlineCommand(String commandInfo) throws QuinnException { | ||
| if (!isCommandInfoPresent(commandInfo)) { | ||
| throw new QuinnException("INCOMPLETE COMMAND" | ||
| + System.lineSeparator() + "\t" | ||
| + "The description and date/time of a deadline cannot be empty!" | ||
| + System.lineSeparator() + "\t" | ||
| + "[Note: Enter /by before specifying the date/time]"); | ||
| } else { | ||
| String[] deadlineInfoParts = commandInfo.split("/by", 2); | ||
|
|
||
| if (deadlineInfoParts.length != 2) { | ||
| throw new QuinnException("INVALID COMMAND" | ||
| + System.lineSeparator() + "\t" | ||
| + "Please check that the description and date/time of a deadline is present!" | ||
| + System.lineSeparator() + "\t" | ||
| + "[Note: Enter /by before specifying the date/time]"); | ||
| } | ||
|
|
||
| String deadlineDescription = deadlineInfoParts[0].trim(); | ||
| String deadlineByDateTime = deadlineInfoParts[1].trim(); | ||
|
|
||
| if (deadlineDescription.isEmpty()) { | ||
| throw new QuinnException("INCOMPLETE COMMAND" | ||
| + System.lineSeparator() + "\t" | ||
| + "The description of a deadline cannot be empty!"); | ||
| } | ||
|
|
||
| if (deadlineByDateTime.isEmpty()) { | ||
| throw new QuinnException("INCOMPLETE COMMAND" | ||
| + System.lineSeparator() + "\t" | ||
| + "The date/time of a deadline cannot be empty!" | ||
| + System.lineSeparator() + "\t" | ||
| + "[Note: Enter /by before specifying the date/time]"); | ||
| } | ||
|
|
||
| return commandInfo; | ||
| } | ||
| } | ||
|
|
||
| private String processTaskInfoFromEventCommand(String commandInfo) throws QuinnException { | ||
| if (!isCommandInfoPresent(commandInfo)) { | ||
| throw new QuinnException("INCOMPLETE COMMAND" | ||
| + System.lineSeparator() + "\t" | ||
| + "The description and date/time of an event cannot be empty!" | ||
| + System.lineSeparator() + "\t" | ||
| + "[Note: Specify the date/time with '/from /to']"); | ||
| } else { | ||
| String[] eventInfoParts = commandInfo.split("/from|/to", 3); | ||
|
|
||
| if (eventInfoParts.length != 3) { | ||
| throw new QuinnException("INVALID COMMAND" | ||
| + System.lineSeparator() + "\t" | ||
| + "Please check that the description and date/time of an event is present!" | ||
| + System.lineSeparator() + "\t" | ||
| + "[Note: Specify the date/time with '/from /to']"); | ||
| } | ||
|
|
||
| String eventDescription = eventInfoParts[0].trim(); | ||
| String eventFromDateTime = eventInfoParts[1].trim(); | ||
| String eventToDateTime = eventInfoParts[2].trim(); | ||
|
|
||
| if (eventDescription.isEmpty()) { | ||
| throw new QuinnException("INCOMPLETE COMMAND" | ||
| + System.lineSeparator() + "\t" | ||
| + "The description of an event cannot be empty!"); | ||
| } | ||
|
|
||
| if (eventFromDateTime.isEmpty() || eventToDateTime.isEmpty()) { | ||
| throw new QuinnException("INCOMPLETE COMMAND" | ||
| + System.lineSeparator() + "\t" | ||
| + "The date/time of an event cannot be empty!" | ||
| + System.lineSeparator() + "\t" | ||
| + "[Note: Specify the date/time with '/from /to']"); | ||
| } | ||
|
|
||
| return commandInfo; | ||
| } | ||
| } | ||
|
|
||
| public void addTask(Task task) throws IOException { | ||
| tasks.add(task); | ||
|
|
||
| String response = ui.taskAddedMessage(task) | ||
| + System.lineSeparator() | ||
| + ui.numOfTasksInListMessage(tasks); | ||
| ui.displayResponse(response); | ||
|
|
||
| storage.saveTasksToFile(tasks); | ||
| } | ||
|
|
||
| public void displayTasks() throws QuinnException { | ||
| if (!tasks.isEmpty()) { | ||
| String response = ui.tasksInListMessage(tasks); | ||
| ui.displayResponse(response); | ||
| } else { | ||
| throw new QuinnException("There are no tasks in your list!"); | ||
| } | ||
| } | ||
|
|
||
| public void markTask(int taskNum) throws QuinnException, IOException { | ||
| if (taskNum > 0 && taskNum <= tasks.size()) { | ||
| Task task = tasks.get(taskNum - 1); | ||
| task.setDone(); | ||
|
|
||
| String message = ui.taskDoneMessage(task); | ||
| ui.displayResponse(message); | ||
|
|
||
| storage.saveTasksToFile(tasks); | ||
| } else { | ||
| throw new QuinnException("Task not found. Please try again!"); | ||
| } | ||
| } | ||
|
|
||
| public void unmarkTask(int taskNum) throws QuinnException, IOException { | ||
| if (taskNum > 0 && taskNum <= tasks.size()) { | ||
| Task task = tasks.get(taskNum - 1); | ||
| task.setNotDone(); | ||
|
|
||
| String message = ui.taskNotDoneMessage(task); | ||
| ui.displayResponse(message); | ||
|
|
||
| storage.saveTasksToFile(tasks); | ||
| } else { | ||
| throw new QuinnException("Task not found. Please try again!"); | ||
| } | ||
| } | ||
|
|
||
| public void deleteTask(int taskNum) throws QuinnException, IOException { | ||
| if (taskNum > 0 && taskNum <= tasks.size()) { | ||
| Task task = tasks.get(taskNum - 1); | ||
| tasks.remove(task); | ||
|
|
||
| String message = ui.taskDeletedMessage(task) | ||
| + System.lineSeparator() | ||
| + ui.numOfTasksInListMessage(tasks); | ||
| ui.displayResponse(message); | ||
|
|
||
| storage.saveTasksToFile(tasks); | ||
| } else { | ||
| throw new QuinnException("Task not found. Please try again!"); | ||
| } | ||
| } | ||
| } | ||
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,7 @@ | ||
| package quinn.exception; | ||
|
|
||
| public class QuinnException extends Exception { | ||
| public QuinnException(String errorMessage) { | ||
| super(errorMessage); | ||
| } | ||
| } |
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.
Perhaps it is better to use a more specific name for this method such as checkAndSplitCommand as process might not be a very specific term. See https://nus-cs2113-ay2425s1.github.io/website/se-book-adapted/chapters/codeQuality.html#guideline-name-well