-
Notifications
You must be signed in to change notification settings - Fork 361
[Zhu Le Yao] iP #414
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
ZhuLeYao
wants to merge
52
commits into
nus-cs2103-AY2223S2:master
Choose a base branch
from
ZhuLeYao: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
[Zhu Le Yao] iP #414
Changes from 8 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
556af3f
Add Gradle support
55cebd9
Add skeletal version of Duke
ZhuLeYao 2a7c671
Add list to store text entered by user
ZhuLeYao 03fbf9b
Revert "Add list to store text entered by user"
ZhuLeYao 09fcc0c
Add list to store text entered by user
ZhuLeYao b5d3ce2
Add option to mark tasks and Task class
ZhuLeYao 0035506
Add task types: Todo, Deadline and Event
ZhuLeYao b5e1e00
Add exceptions to task commands
ZhuLeYao 2008de1
Add function to delete a task
ZhuLeYao 70feaa9
Fix time to be read as date time instead of string
ZhuLeYao 441456a
Add save task list to hard disk function
ZhuLeYao 98df06b
Merge branch 'branch-level-7'
ZhuLeYao e5a768c
Remove print lines for debugging
ZhuLeYao 909e8e0
Update git ignore list
ZhuLeYao 6025774
Merge branch 'branch-level-8'
ZhuLeYao bdac24c
Edit data time format of task saved to hard disk
ZhuLeYao 3172b9d
Add command to find deadlines or events on date
ZhuLeYao 81d434a
Move exception methods from Duke to DukeException
ZhuLeYao d91abba
Refactor the code to extract out closely related code as classes
ZhuLeYao 35b7277
Divide classes into packages
ZhuLeYao a21fea9
Merge branch 'add-gradle-support'
ZhuLeYao 81658cd
Add JUnit tests for Todo and TaskList
ZhuLeYao cc98e9e
Package the App as a JAR file
ZhuLeYao 2ad5871
Add JavaDoc comments
ZhuLeYao 3c4cd7d
Tweak the code to comply with a coding standard
ZhuLeYao a081d94
Add function for users to find a task by searching for a keyword
ZhuLeYao c5a2e16
Merge branch 'branch-A-JavaDoc'
ZhuLeYao bb5df21
Merge branch 'branch-A-CodingStandard'
ZhuLeYao 8f8d7d2
Merge branch 'branch-Level-9'
ZhuLeYao 94259dd
Update JavaDoc comments for duke.main package
ZhuLeYao 5e7d440
Update JavaDoc comments for duke.task package
ZhuLeYao 2047ab4
Update JavaDoc comments for duke.exception package
ZhuLeYao f6091ea
Create GUi for Duke
ZhuLeYao 74ae1f0
Remove border lines from Ui
ZhuLeYao 50b766b
Edit ShadowJar values
ZhuLeYao 34c226e
Merge branch 'branch-Level-10'
ZhuLeYao a962e4b
Add Assertions for assumptions in main
ZhuLeYao 7af212d
Modify git.ignore to allow ACTUAL.TXT
ZhuLeYao eadcc8a
Improve code quality
ZhuLeYao b766be6
Merge pull request #2 from ZhuLeYao/branch-A-Assertions
ZhuLeYao a86c23a
Merge branch 'master' of github.com:ZhuLeYao/ip
ZhuLeYao 97912f0
Merge pull request #3 from ZhuLeYao/branch-A-CodeQuality
ZhuLeYao b2cfd05
Merge branch 'master' of github.com:ZhuLeYao/ip
ZhuLeYao 99bac14
Add a way to archive items
ZhuLeYao b39df94
Merge branch 'branch-BCD-Extension'
ZhuLeYao daeeed6
Add Ui image and update README.md
ZhuLeYao cbb483e
Add images into README.md
ZhuLeYao fcc5170
Format README.md
ZhuLeYao 2a9e367
Format README.md
ZhuLeYao 387cb45
Edit boolean naming of isMarked
ZhuLeYao cad8d37
Correct archive saving mechanism
ZhuLeYao e9e2226
Abstract long methods
ZhuLeYao 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,58 @@ | ||
| public class Deadline extends Task { | ||
| private final String taskType; | ||
| private final String taskDeadline; | ||
|
|
||
| Deadline(int taskNumber, boolean taskStatus, String task, String taskDeadline, int totalNumOfTasks) { | ||
| super(taskNumber, taskStatus, task, totalNumOfTasks); | ||
| this.taskType = "[D]"; | ||
| this.taskDeadline = taskDeadline; | ||
| } | ||
|
|
||
| @Override | ||
| public void markAsDone() { | ||
|
||
| System.out.println("\t____________________________________________________________" + | ||
| "\n\t Nice! I've marked this task as done:\n" + | ||
| "\t " + this.taskType + "[X]" + " " + super.task + | ||
| " (by: " + this.taskDeadline + ")" + | ||
| "\n\t____________________________________________________________"); | ||
| } | ||
|
|
||
| @Override | ||
| public void unmarkAsUndone() { | ||
| System.out.println("\t____________________________________________________________" + | ||
| "\n\t OK, I've marked this task as not done yet:\n" + | ||
| "\t " + this.taskType + "[ ]" + " " + super.task + | ||
| " (by: " + this.taskDeadline + ")" + | ||
| "\n\t____________________________________________________________"); | ||
| } | ||
|
|
||
| public void printDeadlineTask() { | ||
| System.out.println("\t____________________________________________________________" + | ||
| "\n\t Got it. I've added this task:" + | ||
| "\n\t [D]" + super.getTaskStatus() + " " + super.task + | ||
| "(by: " + this.taskDeadline + ")" + | ||
| "\n\t Now you have " + super.totalNumOfTasks + " tasks in the list." + | ||
| "\n\t____________________________________________________________"); | ||
| } | ||
|
|
||
| @Override | ||
| public void printDelete() { | ||
| int newTotalNumOfTasks = super.totalNumOfTasks - 1; | ||
| System.out.println("\t____________________________________________________________" + | ||
| "\n\t Noted. I've removed this task:" + | ||
| "\n\t " + this.taskType + | ||
| super.getTaskStatus() + " " + super.task + " (by: " + this.taskDeadline + ")" + | ||
| "\n\t Now you have " + newTotalNumOfTasks + " tasks in the list." + | ||
| "\n\t____________________________________________________________"); | ||
| } | ||
|
|
||
| @Override | ||
| public String getTaskType() { | ||
| return this.taskType; | ||
| } | ||
|
|
||
| @Override | ||
| public String getDeadline() { | ||
| return this.taskDeadline; | ||
| } | ||
| } | ||
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,254 @@ | ||
| import java.util.Scanner; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class Duke { | ||
|
|
||
| Scanner sc = new Scanner(System.in); | ||
|
|
||
| public static void main(String[] args) { | ||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
|
|
||
| Duke duke = new Duke(); | ||
| duke.chatDuke(); | ||
| } | ||
|
|
||
| public void chatDuke() { | ||
|
|
||
| List<Task> allTasks = new ArrayList<>(); | ||
|
|
||
| this.printGreetingMessage(); | ||
|
|
||
| boolean saidBye = false; | ||
| while (!saidBye) { | ||
| String command = sc.nextLine(); | ||
|
|
||
| try { | ||
| if (command.equals("list")) { | ||
| this.printCommandList(allTasks); | ||
|
||
| } else if (command.startsWith("mark")) { | ||
| missingIndexException(command); | ||
| invalidIndexException(command, allTasks.size()); | ||
| String[] str = command.split(" "); | ||
| int taskIndex = Integer.parseInt(str[1]) - 1; | ||
| Task oldTask = allTasks.get(taskIndex); | ||
| if (oldTask.getTaskType().equals("[T]")) { | ||
| Todo todo = new Todo(oldTask.getTaskNumber(), | ||
| true, oldTask.getTask(), | ||
| allTasks.size()); | ||
| allTasks.set(taskIndex, todo); | ||
| todo.markAsDone(); | ||
| } else if (oldTask.getTaskType().equals("[D]")) { | ||
| Deadline deadline = new Deadline(oldTask.getTaskNumber(), | ||
| true, oldTask.getTask(), | ||
| oldTask.getDeadline(), allTasks.size()); | ||
| allTasks.set(taskIndex, deadline); | ||
| deadline.markAsDone(); | ||
| } else if (oldTask.getTaskType().equals("[E]")) { | ||
| Event event = new Event(oldTask.getTaskNumber(), | ||
| true, oldTask.getTask(), | ||
| oldTask.getEventStartTime(), | ||
| oldTask.getEventEndTime(), allTasks.size()); | ||
| allTasks.set(taskIndex, event); | ||
| event.markAsDone(); | ||
| } | ||
| } else if (command.startsWith("unmark")) { | ||
| missingIndexException(command); | ||
| invalidIndexException(command, allTasks.size()); | ||
| String[] str = command.split(" "); | ||
| int taskIndex = Integer.parseInt(str[1]) - 1; | ||
| Task oldTask = allTasks.get(taskIndex); | ||
| if (oldTask.getTaskType().equals("[T]")) { | ||
| Todo todo = new Todo(oldTask.getTaskNumber(), | ||
| false, oldTask.getTask(), | ||
| allTasks.size()); | ||
| allTasks.set(taskIndex, todo); | ||
| todo.unmarkAsUndone(); | ||
| } else if (oldTask.getTaskType().equals("[D]")) { | ||
| Deadline deadline = new Deadline(oldTask.getTaskNumber(), | ||
| false, oldTask.getTask(), | ||
| oldTask.getDeadline(), allTasks.size()); | ||
| allTasks.set(taskIndex, deadline); | ||
| deadline.unmarkAsUndone(); | ||
| } else if (oldTask.getTaskType().equals("[E]")) { | ||
| Event event = new Event(oldTask.getTaskNumber(), | ||
| false, oldTask.getTask(), | ||
| oldTask.getEventStartTime(), | ||
| oldTask.getEventEndTime(), allTasks.size()); | ||
| allTasks.set(taskIndex, event); | ||
| event.unmarkAsUndone(); | ||
| } | ||
| } else if (command.startsWith("todo")) { | ||
| emptyCommandException(command); | ||
| String[] str = command.split("todo"); | ||
| String taskName = str[1]; | ||
| Todo todo = new Todo(allTasks.size(), false, | ||
| taskName, allTasks.size() + 1); | ||
| allTasks.add(todo); | ||
| todo.printToDoTask(); | ||
| } else if (command.startsWith("deadline")) { | ||
| emptyCommandException(command); | ||
| missingTimingException(command); | ||
| String[] str = command.split("/by"); | ||
| String taskName = str[0].split("deadline")[1]; | ||
| String taskDeadline = str[1]; | ||
| Deadline deadline = new Deadline(allTasks.size(), false, | ||
| taskName, taskDeadline, allTasks.size() + 1); | ||
| allTasks.add(deadline); | ||
| deadline.printDeadlineTask(); | ||
| } else if (command.startsWith("event")) { | ||
| emptyCommandException(command); | ||
| missingTimingException(command); | ||
| String[] str = command.split("/from"); | ||
| String taskName = str[0].split("event")[1]; | ||
| String[] eventStartEndTime = str[1].split("/to"); | ||
| String eventStartTime = eventStartEndTime[0]; | ||
| String eventEndTime = eventStartEndTime[1]; | ||
| Event event = new Event(allTasks.size(), false, | ||
| taskName, eventStartTime, eventEndTime, allTasks.size() + 1); | ||
| allTasks.add(event); | ||
| event.printEventTask(); | ||
| } else if (command.startsWith("delete")) { | ||
| missingIndexException(command); | ||
| invalidIndexException(command, allTasks.size()); | ||
| String[] str = command.split(" "); | ||
| int taskIndex = Integer.parseInt(str[1]) - 1; | ||
| Task task = allTasks.get(taskIndex); | ||
| task.printDelete(); | ||
| allTasks.remove(taskIndex); | ||
| } else if (command.equals("bye")){ | ||
| saidBye = true; | ||
| this.printByeMessage(); | ||
| } else { | ||
| invalidCommandException(command); | ||
| } | ||
| } catch (DukeException d) { | ||
| System.out.println(d.getMessage()); | ||
| } catch (NumberFormatException nfe) { | ||
| System.out.println("\t____________________________________________________________" + | ||
| "\n\t ☹ OOPS!!! The task index to delete or un/mark a task cannot be a non-integer." + | ||
| "\n\t____________________________________________________________"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void printGreetingMessage() { | ||
| System.out.println("\t____________________________________________________________" + | ||
| "\n\t Hello! I'm Duke\n" + | ||
| "\t What can I do for you?" + | ||
| "\n\t____________________________________________________________"); | ||
| } | ||
|
|
||
| public void printCommandList(List<Task> allTasks) { | ||
| System.out.println("\t____________________________________________________________"); | ||
| System.out.println("\t Here are the tasks in your list:"); | ||
| for (int i = 0; i < allTasks.size(); i++) { | ||
| int numbering = i + 1; | ||
| Task task = allTasks.get(i); | ||
| String time = ""; | ||
| if (task.getTaskType().equals("[D]")) { | ||
| time = " (by: " + task.getDeadline() + ")"; | ||
| } else if (task.getTaskType().equals("[E]")) { | ||
| time = " (from: " + task.getEventStartTime() + " to: " | ||
| + task.getEventEndTime() + ")"; | ||
| } | ||
| System.out.println("\t " + numbering + "." + | ||
| task.getTaskType() + task.getTaskStatus() + " " | ||
| + task.getTask() + time); | ||
| } | ||
|
|
||
| System.out.println("\t____________________________________________________________"); | ||
| } | ||
|
|
||
| public void printByeMessage() { | ||
| System.out.println("\t____________________________________________________________" + | ||
| "\n\t Bye. Hope to see you again soon!" + | ||
| "\n\t____________________________________________________________"); | ||
| } | ||
|
|
||
| public void emptyCommandException(String command) throws DukeException { | ||
| switch (command) { | ||
| case "todo": | ||
| throw new DukeException("\t____________________________________________________________" + | ||
| "\n\t ☹ OOPS!!! The description of a todo cannot be empty." + | ||
| "\n\t____________________________________________________________"); | ||
| case "deadline": | ||
| throw new DukeException("\t____________________________________________________________" + | ||
| "\n\t ☹ OOPS!!! The description of a deadline cannot be empty." + | ||
| "\n\t____________________________________________________________"); | ||
| case "event": | ||
| throw new DukeException("\t____________________________________________________________" + | ||
| "\n\t ☹ OOPS!!! The description of an event cannot be empty." + | ||
| "\n\t____________________________________________________________"); | ||
| } | ||
| } | ||
|
|
||
| public void missingTimingException(String command) throws DukeException { | ||
| if (command.startsWith("deadline") && !command.contains("/by")) { | ||
| throw new DukeException("\t____________________________________________________________" + | ||
| "\n\t ☹ OOPS!!! The timing of a deadline cannot be empty." + | ||
| "\n\t____________________________________________________________"); | ||
| } else if (command.startsWith("event") && !command.contains("/from")) { | ||
| throw new DukeException("\t____________________________________________________________" + | ||
| "\n\t ☹ OOPS!!! The start time of an event cannot be empty." + | ||
| "\n\t____________________________________________________________"); | ||
| } else if (command.startsWith("event") && !command.contains("/to")) { | ||
| throw new DukeException("\t____________________________________________________________" + | ||
| "\n\t ☹ OOPS!!! The end time of an event cannot be empty." + | ||
| "\n\t____________________________________________________________"); | ||
| } | ||
| } | ||
|
|
||
| public void missingIndexException(String command) throws DukeException { | ||
| if (command.equals("mark")) { | ||
| throw new DukeException("\t____________________________________________________________" + | ||
| "\n\t ☹ OOPS!!! The task index to mark a task as done cannot be empty." + | ||
| "\n\t____________________________________________________________"); | ||
| } else if (command.equals("unmark")) { | ||
| throw new DukeException("\t____________________________________________________________" + | ||
| "\n\t ☹ OOPS!!! The task index to unmark a task as not done cannot be empty." + | ||
| "\n\t____________________________________________________________"); | ||
| } else if (command.equals("delete")) { | ||
| throw new DukeException("\t____________________________________________________________" + | ||
| "\n\t ☹ OOPS!!! The task index to delete a task as not done cannot be empty." + | ||
| "\n\t____________________________________________________________"); | ||
| } | ||
| } | ||
|
|
||
| public void invalidIndexException(String command, int taskSize) throws DukeException { | ||
| if (command.startsWith("mark") || command.startsWith("unmark") | ||
| ||command.startsWith("delete")) { | ||
| String index = command.split(" ")[1]; | ||
| int index1 = Integer.parseInt(index); | ||
| if (index1 <= 0) { | ||
| throw new DukeException("\t____________________________________________________________" + | ||
| "\n\t ☹ OOPS!!! The task index to delete or un/mark a task cannot be zero or less." + | ||
| "\n\t____________________________________________________________"); | ||
| } else if (index.equals("")) { | ||
| throw new DukeException("\t____________________________________________________________" + | ||
| "\n\t ☹ OOPS!!! The task index to delete or un/mark a task cannot be empty." + | ||
| "\n\t____________________________________________________________"); | ||
| } else if (index1 > taskSize) { | ||
| throw new DukeException("\t____________________________________________________________" + | ||
| "\n\t ☹ OOPS!!! The task index to delete or un/mark a task cannot be more than" + | ||
| " number of tasks." + | ||
| "\n\t____________________________________________________________"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void invalidCommandException(String command) throws DukeException { | ||
| if (!command.startsWith("event") || !(command.startsWith("deadline")) || | ||
| !command.startsWith("todo") || command.startsWith("mark") || | ||
| !command.startsWith("unmark")) { | ||
| throw new DukeException("\t____________________________________________________________" + | ||
| "\n\t ☹ OOPS!!! I'm sorry, but I don't know what that means :-(" + | ||
| "\n\t____________________________________________________________"); | ||
| } | ||
| } | ||
| } | ||
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,5 @@ | ||
| class DukeException extends Exception { | ||
| DukeException(String message) { | ||
| super(message); | ||
| } | ||
| } |
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,69 @@ | ||
| class Event extends Task { | ||
| private final String taskType; | ||
| private final String eventStartTime; | ||
| private final String eventEndTime; | ||
|
|
||
| Event(int taskNumber, boolean taskStatus, String task, | ||
| String eventStartTime, String eventEndTime, int totalNumOfTasks) { | ||
| super(taskNumber, taskStatus, task, totalNumOfTasks); | ||
| this.taskType = "[E]"; | ||
| this.eventStartTime = eventStartTime; | ||
| this.eventEndTime = eventEndTime; | ||
| } | ||
|
|
||
| @Override | ||
| public void markAsDone() { | ||
| System.out.println("\t____________________________________________________________" + | ||
| "\n\t Nice! I've marked this task as done:\n" + | ||
| "\t " + this.taskType + "[X]" + " " + super.task + | ||
| " (from: " + this.eventStartTime + " to: " | ||
| + this.eventEndTime + | ||
| "\n\t____________________________________________________________"); | ||
| } | ||
|
|
||
| @Override | ||
| public void unmarkAsUndone() { | ||
| System.out.println("\t____________________________________________________________" + | ||
| "\n\t OK, I've marked this task as not done yet:\n" + | ||
| "\t " + this.taskType + "[ ]" + " " + super.task + | ||
| " (from: " + this.eventStartTime + " to: " | ||
| + this.eventEndTime + | ||
| "\n\t____________________________________________________________"); | ||
| } | ||
|
|
||
| public void printEventTask() { | ||
| System.out.println("\t____________________________________________________________" + | ||
| "\n\t Got it. I've added this task:" + | ||
| "\n\t [E]" + super.getTaskStatus() + " " + super.task + | ||
| "(from: " + this.eventStartTime + " to: " + this.eventEndTime + ")" + | ||
| "\n\t Now you have " + super.totalNumOfTasks + " tasks in the list." + | ||
| "\n\t____________________________________________________________"); | ||
| } | ||
|
|
||
| @Override | ||
| public void printDelete() { | ||
| int newTotalNumOfTasks = super.totalNumOfTasks - 1; | ||
| System.out.println("\t____________________________________________________________" + | ||
| "\n\t Noted. I've removed this task:" + | ||
| "\n\t " + this.taskType + | ||
| super.getTaskStatus() + " " + super.task + " (from: " + this.eventStartTime + | ||
| " to: " + this.eventEndTime + ")" + "\n\t Now you have " + | ||
| newTotalNumOfTasks + " tasks in the list." + | ||
| "\n\t____________________________________________________________"); | ||
| } | ||
|
|
||
| @Override | ||
| public String getTaskType() { | ||
| return this.taskType; | ||
| } | ||
|
|
||
| @Override | ||
| public String getEventStartTime() { | ||
| return this.eventStartTime; | ||
| } | ||
|
|
||
| @Override | ||
| public String getEventEndTime() { | ||
| return this.eventEndTime; | ||
| } | ||
| } |
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.
Needs Javadocs for these public classes & public methods