-
Notifications
You must be signed in to change notification settings - Fork 197
[kristianachwan] iP #204
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
kristianachwan
wants to merge
46
commits into
nus-cs2113-AY2223S2:master
Choose a base branch
from
kristianachwan: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
[kristianachwan] iP #204
Changes from 32 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
1e44177
Update welcome message
kristianachwan d604700
Add greet, echo, and exit feature
kristianachwan ea35053
Add add and list feature
kristianachwan 6c9b878
Add mark as done feature and Task class
kristianachwan 76d2e4c
Follow coding standard and refactor repeated code
kristianachwan 1c8a1eb
Create ToDo, Deadline, Event entities
kristianachwan 5d62adf
Incorporate adding todo, deadline, event entity
kristianachwan 9423d8a
Fix formatting
kristianachwan aa5f8b5
Bug fix empty line + add UI testing
kristianachwan 4fffeda
Change linebreak into the safer linearSeparator
kristianachwan 3cb44ea
Fix bug for adding deadline
kristianachwan 02cb628
Reformat code
kristianachwan 6f74566
Reformat code (2)
kristianachwan f9c599b
Refactor using case statement
kristianachwan 37eb12a
Fix bug not adding break in case
kristianachwan 85f757f
Add parser to each entity
kristianachwan 374ac57
Add exceptions and error handling
kristianachwan 3d199c2
Organize into packages
kristianachwan 0f6fcc6
Fix UI-testing
kristianachwan 2ca1e40
Improve variables naming
kristianachwan 075e95f
Adding command and payload model
kristianachwan 967378f
Add unknown command
kristianachwan 5838b80
Improve code quality
kristianachwan 21cedfd
Implement ArrayList for storing tasks
kristianachwan ffc1076
Extract methods refactoring
kristianachwan 5f38dce
Add delete task feature
kristianachwan 2a0f5ab
Add DataAccess class
kristianachwan 2fe149c
Merge pull request #1 from kristianachwan/branch-Level-6
kristianachwan 220b7b7
Merge branch 'master' into branch-Level-7
kristianachwan baac899
Merge pull request #2 from kristianachwan/branch-Level-7
kristianachwan 62219f3
Resolve error after merging
kristianachwan 5a25935
Fix bug writing duke.txt
kristianachwan 3496b8e
Clean code
kristianachwan 8a1dba8
Refactor to more OOP
kristianachwan 2b7328b
Add find feature
kristianachwan a8e51f7
Add method header comments
kristianachwan 08339d6
Merge pull request #3 from kristianachwan/branch-Level-9
kristianachwan f41e223
Syncing with master
kristianachwan 917ba29
Merge pull request #4 from kristianachwan/branch-A-JavaDoc
kristianachwan 5d5a498
Add user guide
kristianachwan 59d2021
Fix typo userguide
kristianachwan 13b1697
Change user guide filenaming
kristianachwan 89999d6
Change filepath of duke.txt
kristianachwan ae2b710
Change the format of printing search results
kristianachwan 2e3774d
Add line separator
kristianachwan 89782e8
Update minor mistake on UG
kristianachwan 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
Empty file.
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,166 @@ | ||
| package duke; | ||
|
|
||
| import duke.exception.InvalidCommandException; | ||
| import duke.model.*; | ||
| import duke.utils.DataAccess; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Duke { | ||
| static final String TASK_ADDED_PREFIX = "Got it. I've added this task:" + System.lineSeparator() + "\t"; | ||
| static final String TASK_REMOVED_PREFIX = "Noted! I've removed this task" + System.lineSeparator() + "\t"; | ||
| static DataAccess dataAccess = new DataAccess("data/duke.txt"); | ||
| static ArrayList<Task> tasks = new ArrayList<Task>(); | ||
|
|
||
| public static void main(String[] args) { | ||
| Scanner scanner = new Scanner(System.in); | ||
| printDuke(); | ||
| String input; | ||
| String outputMessage; | ||
| while (true) { | ||
| input = scanner.nextLine(); | ||
| Command command = new Command(input); | ||
| String[] payloadData = command.getPayload().getData(); | ||
| try { | ||
| switch (command.getType()) { | ||
| case "list": | ||
| outputMessage = getTasksList(); | ||
| break; | ||
| case "mark": | ||
| outputMessage = handleMarkTask(command); | ||
| break; | ||
| case "unmark": | ||
| outputMessage = handleUnmarkTask(command); | ||
| break; | ||
| case "task": | ||
| outputMessage = handleAddTask(payloadData); | ||
| break; | ||
| case "todo": | ||
| outputMessage = handleAddTodo(payloadData); | ||
| break; | ||
| case "deadline": | ||
| outputMessage = handleAddDeadline(payloadData); | ||
| break; | ||
| case "event": | ||
| outputMessage = handleAddEvent(payloadData); | ||
| break; | ||
| case "delete": | ||
| outputMessage = handleDeleteTask(payloadData); | ||
| break; | ||
| case "bye": | ||
| outputMessage = "Bye. Hope to see you again soon!"; | ||
| System.exit(0); | ||
| default: | ||
| throw new InvalidCommandException(); | ||
| } | ||
| } catch (InvalidCommandException e) { | ||
| outputMessage = e.getMessage(); | ||
| } | ||
| System.out.println("\t____________________________________________________________"); | ||
| System.out.println("\t" + outputMessage); | ||
| System.out.println("\t____________________________________________________________"); | ||
| dataAccess.writeToFile("\t" + getTasksList()); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public static String handleDeleteTask(String[] payloadData) throws InvalidCommandException { | ||
| String outputMessage; | ||
| int removedIndex = Integer.parseInt(payloadData[0]); | ||
| Task removedTask = tasks.get(removedIndex - 1); | ||
| tasks.remove(removedIndex - 1); | ||
| outputMessage = TASK_REMOVED_PREFIX + removedTask.toString() + System.lineSeparator() + "\t" + getTasksInformation(); | ||
| return outputMessage; | ||
| } | ||
|
|
||
| public static String handleAddEvent(String[] payloadData) throws InvalidCommandException { | ||
| String outputMessage; | ||
| Task newEvent = new Event(payloadData); | ||
| tasks.add(newEvent); | ||
| outputMessage = TASK_ADDED_PREFIX + newEvent.toString() + System.lineSeparator() + "\t" | ||
| + getTasksInformation(); | ||
| return outputMessage; | ||
| } | ||
|
|
||
| public static String handleAddDeadline(String[] payloadData) throws InvalidCommandException { | ||
| String outputMessage; | ||
| Deadline newDeadline = new Deadline(payloadData); | ||
| tasks.add(newDeadline); | ||
| outputMessage = TASK_ADDED_PREFIX + newDeadline.toString() + System.lineSeparator() + "\t" | ||
| + getTasksInformation(); | ||
| return outputMessage; | ||
| } | ||
|
|
||
| public static String handleAddTodo(String[] payloadData) throws InvalidCommandException { | ||
| String outputMessage; | ||
| Task newTodo = new ToDo(payloadData); | ||
| tasks.add(newTodo); | ||
| outputMessage = TASK_ADDED_PREFIX + newTodo.toString() + System.lineSeparator() + "\t" | ||
| + getTasksInformation(); | ||
| return outputMessage; | ||
| } | ||
|
|
||
| public static String handleAddTask(String[] payloadData) throws InvalidCommandException { | ||
| String outputMessage; | ||
| Task newTask = new Task(payloadData); | ||
| tasks.add(newTask); | ||
| outputMessage = TASK_ADDED_PREFIX + newTask.toString() + System.lineSeparator() + "\t" | ||
| + getTasksInformation(); | ||
| return outputMessage; | ||
| } | ||
|
|
||
| public static String handleMarkTask(Command command) { | ||
| int taskIndex; | ||
| String outputMessage; | ||
| taskIndex = Integer.parseInt(command.getPayload().getData()[0]) - 1; | ||
| tasks.get(taskIndex).markAsDone(); | ||
| outputMessage = "Nice! I've marked this task as done:" + System.lineSeparator() + "\t" | ||
| + tasks.get(taskIndex).toString(); | ||
| return outputMessage; | ||
| } | ||
|
|
||
| public static String handleUnmarkTask(Command command) { | ||
| String outputMessage; | ||
| int taskIndex; | ||
| taskIndex = Integer.parseInt(command.getPayload().getData()[0]) - 1; | ||
| tasks.get(taskIndex).unmarkAsDone(); | ||
| outputMessage = "Ok, I've marked this task as not done:" + System.lineSeparator() + "\t" | ||
| + tasks.get(taskIndex).toString(); | ||
| return outputMessage; | ||
| } | ||
|
|
||
| public static void printDuke() { | ||
| String logo = " ____ _" + System.lineSeparator() | ||
| + "| _ \\ _ _| | _____" + System.lineSeparator() | ||
| + "| | | | | | | |/ / _ \\" + System.lineSeparator() | ||
| + "| |_| | |_| | < __/" + System.lineSeparator() | ||
| + "|____/ \\__,_|_|\\_\\___|" + System.lineSeparator(); | ||
| System.out.println("____________________________________________________________" + System.lineSeparator() | ||
| + logo | ||
| + "Hello! I'm duke.Duke!" + System.lineSeparator() | ||
| + "What I can do for you?" + System.lineSeparator() | ||
| + "____________________________________________________________" + System.lineSeparator() | ||
| ); | ||
| } | ||
|
|
||
| public static String getTasksInformation() { | ||
| return "Now you have " + tasks.size() + " tasks in the list."; | ||
| } | ||
|
|
||
| public static String getTasksList() { | ||
| if (tasks.size() == 0) { | ||
| return "Tasks is empty..."; | ||
| } | ||
| String tasksList = ""; | ||
| int numberOfTasks = tasks.size(); | ||
| for (int i = 0; i < numberOfTasks; i++) { | ||
| tasksList += String.format("%3d. ", (i + 1)) + tasks.get(i).toString(); | ||
| if (i < numberOfTasks - 1) { | ||
| tasksList += System.lineSeparator() + "\t"; | ||
| } | ||
| } | ||
| return tasksList; | ||
| } | ||
|
|
||
| } | ||
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,21 @@ | ||
| package duke.exception; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| public class DukeException extends Exception { | ||
| private static final String DUKE_PREFIX = "Duke Error: "; | ||
|
|
||
|
|
||
| public static String[] parseCommand (String command) throws InvalidCommandException{ | ||
|
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. why is there parseCommand in exception class? |
||
| String[] commandArray = command.split(" "); | ||
| if (commandArray.length < 2){ | ||
| throw new InvalidCommandException("Description of cannot be empty!"); | ||
| } | ||
| return Arrays.copyOfRange(commandArray, 1, commandArray.length); | ||
| } | ||
|
|
||
| public DukeException(String message) { | ||
| super(DUKE_PREFIX + 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,13 @@ | ||
| package duke.exception; | ||
|
|
||
| public class InvalidCommandException extends DukeException{ | ||
| private static final String DEFAULT_MESSAGE = "I'm sorry but I couldn't understand you :("; | ||
|
|
||
| public InvalidCommandException(String message){ | ||
| super(message); | ||
| } | ||
|
|
||
| public InvalidCommandException () { | ||
| super(DEFAULT_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,33 @@ | ||
| package duke.model; | ||
|
|
||
| public class Command { | ||
| protected String type; | ||
| protected Payload payload; | ||
|
|
||
| public Command(String input) { | ||
| String[] commandArray = input.split(" "); | ||
| this.type = commandArray[0].trim(); | ||
| String[] payloadStringArray = input.split(this.type); | ||
| if (payloadStringArray.length > 1) { | ||
| payload = new Payload(trimStringArray(payloadStringArray[1].split("/"))); | ||
| } else { | ||
| payload = new Payload(); | ||
| } | ||
| } | ||
|
|
||
| public String getType() { | ||
| return this.type; | ||
| } | ||
|
|
||
| public Payload getPayload() { | ||
| return this.payload; | ||
| } | ||
|
|
||
| public String[] trimStringArray(String[] stringArray) { | ||
| String[] trimmedStringArray = new String[stringArray.length]; | ||
| for (int i = 0; i < stringArray.length; i++) { | ||
| trimmedStringArray[i] = stringArray[i].trim(); | ||
| } | ||
| return trimmedStringArray; | ||
| } | ||
| } |
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,23 @@ | ||
| package duke.model; | ||
|
|
||
| import duke.exception.InvalidCommandException; | ||
|
|
||
| public class Deadline extends Task { | ||
| protected String deadlineBy; | ||
|
|
||
| public Deadline(String[] descriptionArray) throws InvalidCommandException { | ||
| if (descriptionArray.length < 2) { | ||
| throw new InvalidCommandException("Incomplete deadline description!"); | ||
| } | ||
| this.taskName = descriptionArray[0]; | ||
| this.deadlineBy = descriptionArray[1]; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| String deadlinePrefix = "[D]"; | ||
| String taskString = super.toString(); | ||
| String deadlinePostfix = " (" + "by: " + this.deadlineBy + ")"; | ||
| return deadlinePrefix + taskString + deadlinePostfix; | ||
| } | ||
| } |
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,27 @@ | ||
| package duke.model; | ||
|
|
||
| import duke.exception.InvalidCommandException; | ||
|
|
||
| public class Event extends Task { | ||
| protected String eventStart; | ||
| protected String eventEnd; | ||
|
|
||
| public Event(String[] descriptionArray) throws InvalidCommandException { | ||
| if (descriptionArray.length < 3) { | ||
| throw new InvalidCommandException("Incomplete description of event!"); | ||
| } | ||
| System.out.println("test"); | ||
| this.taskName = descriptionArray[0]; | ||
| this.eventStart = descriptionArray[1]; | ||
| this.eventEnd = descriptionArray[2]; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| String deadlinePrefix = "[E]"; | ||
| String taskString = super.toString(); | ||
| String eventPostfix = " (" + "from: " + this.eventStart + " to: " + this.eventEnd + ")"; | ||
| return deadlinePrefix + taskString + eventPostfix; | ||
| } | ||
| } | ||
|
|
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,18 @@ | ||
| package duke.model; | ||
|
|
||
| public class Payload { | ||
| protected String[] data; | ||
|
|
||
| public Payload() { | ||
| this.data = new String[0]; | ||
| } | ||
|
|
||
| public Payload(String[] data) { | ||
| this.data = data; | ||
| } | ||
|
|
||
| public String[] getData() { | ||
| return data; | ||
| } | ||
|
|
||
| } |
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,43 @@ | ||
| package duke.model; | ||
|
|
||
| import duke.exception.InvalidCommandException; | ||
|
|
||
| public class Task { | ||
| protected String taskName; | ||
| protected boolean isDone; | ||
|
|
||
| public Task() { | ||
| } | ||
|
|
||
| public Task(String[] descriptionArray) throws InvalidCommandException { | ||
| if (descriptionArray.length < 1) { | ||
| throw new InvalidCommandException("Description of task cannot be empty!"); | ||
| } | ||
| this.taskName = descriptionArray[0]; | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| public Task(String[] descriptionArray, boolean isDone) throws InvalidCommandException { | ||
| this(descriptionArray); | ||
| this.isDone = isDone; | ||
| } | ||
|
|
||
|
|
||
| public void markAsDone() { | ||
| this.isDone = true; | ||
| } | ||
|
|
||
| public void unmarkAsDone() { | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| public String getStatusIcon() { | ||
| return this.isDone ? "X" : " "; | ||
| } | ||
|
|
||
| public String toString() { | ||
| return "[" + this.getStatusIcon() + "]" + "\t" + this.taskName; | ||
| } | ||
|
|
||
|
|
||
| } |
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,20 @@ | ||
| package duke.model; | ||
|
|
||
| import duke.exception.InvalidCommandException; | ||
|
|
||
| public class ToDo extends Task { | ||
| public ToDo(String[] descriptionArray) throws InvalidCommandException { | ||
| if (descriptionArray.length < 1) { | ||
| throw new InvalidCommandException("Incomplete description of ToDo!"); | ||
| } | ||
| this.taskName = descriptionArray[0]; | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| String todoPrefix = "[T]"; | ||
| String taskString = super.toString(); | ||
| return todoPrefix + taskString; | ||
| } | ||
| } |
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.
use condition here instead of system.Exit later