-
Notifications
You must be signed in to change notification settings - Fork 76
[nihalzp] iP #61
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
nihalzp
wants to merge
65
commits into
nus-cs2113-AY2324S1:master
Choose a base branch
from
nihalzp: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
[nihalzp] iP #61
Changes from 29 commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
da9144b
Rename bot and implement basic greet, exit
nihalzp 75be7ce
Echo the user given command, exit when "bye"
nihalzp afc511c
Add indentation to responses
nihalzp 332b3f4
Add Python ASCII art
nihalzp 1ebb2bf
Add Python emoji before response
nihalzp 111d8a1
Store commands and display if requested
nihalzp 0093f07
Add task class
nihalzp 8f17b24
Allow mark and unmark of tasks
nihalzp 4cf5d1e
Rename taskList to tasks
nihalzp 7e8e63a
Format and change var names to match Java standards
nihalzp 875d4bb
Add Todo class
nihalzp dca8d87
Add toString method to task class
nihalzp bbb2a75
Implement Todo class
nihalzp a08b038
Implement Deadline class
nihalzp d0b678e
Implement Deadline class toString method
nihalzp ec7a82d
Implement Event class
nihalzp 0591c0f
Integrate Todo, Deadline, Event class into chatbot
nihalzp 846bfbf
Remove trailing spaces from Ascii art
nihalzp dd17203
Add input and expected behaviour of the bot
nihalzp 16606ac
Use all capitals for constant variables
nihalzp 2847381
Change method name to getDone
nihalzp 2ee7cc7
Use constant variables for command names
nihalzp edcb499
Use newlines to keep coherent blocks together
nihalzp 8235ebc
Add some comments
nihalzp 16258c4
Make Task class abstract
nihalzp 54707ec
Catch exceptions and respond for unexpected input
nihalzp c60023a
Fix typo in Duke
nihalzp 652ef28
Update input.txt and EXPECTED.TXT
nihalzp 0a328b0
Merging branch-Level-5 into master
nihalzp a45995b
Rename Duke to Python
nihalzp a35adec
Organize files into packages
nihalzp 6ce1ada
Update the path in runtest.sh
nihalzp 000bb2e
Merge branch-A-Packages into master
nihalzp 96f5be8
Use String.repeat instead of Arrays.fill
nihalzp 938cdb0
Change method name from getDone() to isDone()
nihalzp 085f7ec
Use Em Dash for horizontal line
nihalzp cabb00d
Fix path in runtest.sh
nihalzp 8dd6c03
Add support for deleting tasks
nihalzp 0960bfb
Add tests for delete feature
nihalzp 1d7a30b
Implement task details format method for file saving
nihalzp 4ea6ed5
Save tasks after each change to task lists
nihalzp 3c1dc3c
Use type icon constant variable
nihalzp 9141ff6
Add support for loading tasks from file
nihalzp d6ebb8f
Merge branch-Level-6 into master
nihalzp efa847a
Merge branch-Level-7 into master
nihalzp 6dbf985
Save tasks to file after delete command
nihalzp 5d81533
Ignore data folder
nihalzp 1e4f784
Use lower case for directory names
nihalzp e6fb515
Update text-ui-test input and expected text
nihalzp 19bf31a
Add Command class
nihalzp d34035c
Add Message class
nihalzp e13479b
Add Parser class
nihalzp e995cc5
Add Exception class
nihalzp 7bbab3b
Add TaskList class
nihalzp 4a3c6b7
Add Ui class
nihalzp c84f7dc
Refactor Python.java for more oop
nihalzp dd0cf10
Update text-ui-testing
nihalzp ae0c242
Add support for finding tasks
nihalzp dd55af9
Add manifest.mf
nihalzp cf0307f
Merge pull request #1 from nihalzp/branch-Level-9
nihalzp 1dab8c7
Add JavaDoc comments
nihalzp 85589ff
Merge pull request #2 from nihalzp/branch-A-JavaDoc
nihalzp f61a1b9
Add user guide
nihalzp 4d7bdfb
Reorder and fix formatting
nihalzp 3218369
Do not print task count at start
nihalzp 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,22 @@ | ||
| public class Deadline extends Task { | ||
| protected String by; | ||
|
|
||
| public Deadline(String description, String by) { | ||
| super(description); | ||
| this.by = by; | ||
| } | ||
|
|
||
| @Override | ||
| public String getTypeIcon() { | ||
| return "[D]"; | ||
| } | ||
|
|
||
| public String getBy() { | ||
| return by; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return super.toString() + " (by: " + getBy() + ")"; | ||
| } | ||
| } |
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,208 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Duke { | ||
| final private static String BOT_NAME = "Python"; | ||
| final private static String PYTHON_ASCII_ART = | ||
| "\t ____ _ _\n" + | ||
| "\t| _ \\ _ _| |_| |__ ___ _ __\n" + | ||
| "\t| |_) | | | | __| _ \\ / _ \\| _ \\\n" + | ||
| "\t| __/| |_| | |_| | | | (_) | | | |\n" + | ||
| "\t|_| \\__, |\\__|_| |_|\\___/|_| |_|\n" + | ||
| "\t |___/"; | ||
| final private static String PYTHON_EMOJI = "\uD83D\uDC0D"; | ||
|
|
||
| final static private List<Task> tasks = new ArrayList<>(); | ||
|
|
||
| final private static Scanner in = new Scanner(System.in); | ||
|
|
||
| public static final String COMMAND_BYE = "bye"; | ||
| public static final String COMMAND_LIST = "list"; | ||
| public static final String COMMAND_MARK = "mark"; | ||
| public static final String COMMAND_UNMARK = "unmark"; | ||
| public static final String COMMAND_TODO = "todo"; | ||
| public static final String COMMAND_DEADLINE = "deadline"; | ||
| public static final String COMMAND_EVENT = "event"; | ||
|
|
||
| final private static int HORIZONTAL_LINE_LENGTH = 80; | ||
| private static void printHorizontalLine() { | ||
| char[] horizontalLine = new char[HORIZONTAL_LINE_LENGTH]; | ||
| Arrays.fill(horizontalLine, '—'); | ||
|
nihalzp marked this conversation as resolved.
Outdated
|
||
| System.out.println("\t" + new String(horizontalLine)); | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
|
nihalzp marked this conversation as resolved.
Outdated
|
||
| String logo = " ____ _ \n" | ||
| + "| _ \\ _ _| | _____ \n" | ||
| + "| | | | | | | |/ / _ \\\n" | ||
| + "| |_| | |_| | < __/\n" | ||
| + "|____/ \\__,_|_|\\_\\___|\n"; | ||
| System.out.println("Hello from\n" + logo); | ||
| System.out.println(PYTHON_ASCII_ART); | ||
| printHorizontalLine(); | ||
| System.out.printf("\t%s: Hello! I am a short Java Bot %s!\n", PYTHON_EMOJI, BOT_NAME); | ||
| System.out.printf("\t%s: What can I do for you?\n", PYTHON_EMOJI); | ||
| printHorizontalLine(); | ||
|
|
||
| String inputLine; | ||
| do { | ||
| inputLine = in.nextLine(); | ||
|
|
||
| // Trim extra whitespace characters between words while splitting | ||
| String inputCommand = inputLine.split("\\s+")[0]; | ||
| printHorizontalLine(); | ||
|
|
||
| switch (inputCommand) { | ||
| case COMMAND_BYE: | ||
| System.out.printf("\t%s: Bye. See you again when you run the program again!\n", PYTHON_EMOJI); | ||
| break; | ||
|
nihalzp marked this conversation as resolved.
Outdated
|
||
| case COMMAND_LIST: | ||
| System.out.printf("\t%s: You have %d tasks to do!\n", PYTHON_EMOJI, tasks.size()); | ||
| for (int taskNo = 1; taskNo <= tasks.size(); taskNo++) { | ||
| System.out.printf("\t\t\t%d. %s\n", taskNo, tasks.get(taskNo - 1)); | ||
| } | ||
| break; | ||
| case COMMAND_MARK: { | ||
| int taskNo; | ||
| try { | ||
| taskNo = Integer.parseInt(inputLine.split(" ")[1]); | ||
| } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { | ||
| System.out.println("\t" + COMMAND_MARK + " command must be followed by an integer (task" + | ||
| " id)!"); | ||
| break; | ||
| } | ||
|
|
||
| // Handle unintended usage | ||
| if (taskNo > tasks.size()) { | ||
| System.out.printf("\t%s: Are you from the future?\n", PYTHON_EMOJI); | ||
| break; | ||
| } | ||
| if (tasks.get(taskNo - 1).getDone()) { | ||
| System.out.printf("\t%s: Are you from the past?\n", PYTHON_EMOJI); | ||
| System.out.printf("\t\tTask: %s\n \t\t is already done!!!\n", | ||
| tasks.get(taskNo - 1)); | ||
| break; | ||
| } | ||
|
|
||
| tasks.get(taskNo - 1).setDone(true); | ||
|
|
||
| System.out.printf("\t%s: Good job completing the task!\n", PYTHON_EMOJI); | ||
| System.out.printf("\t\t\t %s\n", tasks.get(taskNo - 1)); | ||
| break; | ||
| } | ||
| case COMMAND_UNMARK: { | ||
| int taskNo; | ||
| try { | ||
| taskNo = Integer.parseInt(inputLine.split(" ")[1]); | ||
| } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { | ||
| System.out.println("\t" + COMMAND_UNMARK + " command must be followed by an integer (task" + | ||
| " id)."); | ||
| break; | ||
| } | ||
|
|
||
| // Handle unintended usage | ||
| if (taskNo > tasks.size()) { | ||
| System.out.printf("\t%s: Are you from the future?\n", PYTHON_EMOJI); | ||
| break; | ||
| } | ||
| if (!tasks.get(taskNo - 1).getDone()) { | ||
| System.out.printf("\t%s: Alas! Only the completed tasks can be unmarked!\n", PYTHON_EMOJI); | ||
| System.out.printf("\t\tTask: %s\n \t\tis already sitting idle. Get started...!!!\n", | ||
| tasks.get(taskNo - 1)); | ||
| break; | ||
| } | ||
|
|
||
| tasks.get(taskNo - 1).setDone(false); | ||
|
|
||
| System.out.printf("\t%s: Its okay! To err is human! Unmarked!\n", PYTHON_EMOJI); | ||
| System.out.printf("\t\t\t %s\n", tasks.get(taskNo - 1)); | ||
| break; | ||
| } | ||
| case COMMAND_TODO: { | ||
| String todoDescription; | ||
| try { | ||
| todoDescription = inputLine.split(" ", 2)[1]; | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| System.out.println("\t" + COMMAND_TODO + " command must be followed by a task " + | ||
| "description!"); | ||
| break; | ||
| } | ||
|
|
||
| System.out.printf("\t%s: %s\n", PYTHON_EMOJI, "New Todo! You have added this todo:"); | ||
|
|
||
| Todo todo = new Todo(todoDescription); | ||
| tasks.add(todo); | ||
|
|
||
| System.out.printf("\t\t\t %s\n", todo); | ||
| System.out.printf("\t\tYou have %d tasks in total!\n", tasks.size()); | ||
| break; | ||
| } | ||
| case COMMAND_DEADLINE: { | ||
| String deadlineDetails, deadlineDescription, deadlineBy; | ||
| try { | ||
| deadlineDetails = inputLine.split(" ", 2)[1]; | ||
| deadlineDescription = deadlineDetails.split(" /by ")[0]; | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| System.out.println("\t" + COMMAND_DEADLINE + " command must be followed by a task " + | ||
| "description!"); | ||
| break; | ||
| } | ||
| try { | ||
| deadlineBy = deadlineDetails.split(" /by ")[1]; | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| System.out.println("\t" + COMMAND_DEADLINE + " command must have /by clause followed by " + | ||
| "time its due!"); | ||
| break; | ||
| } | ||
|
|
||
| System.out.printf("\t%s: %s\n", PYTHON_EMOJI, "New Deadline! You have added this deadline:"); | ||
|
|
||
| Deadline deadline = new Deadline(deadlineDescription, deadlineBy); | ||
| tasks.add(deadline); | ||
|
|
||
| System.out.printf("\t\t\t %s\n", deadline); | ||
| System.out.printf("\t\tYou have %d tasks in total!\n", tasks.size()); | ||
| break; | ||
| } | ||
| case COMMAND_EVENT: { | ||
| String eventDetails, eventDescription, eventFrom, eventTo; | ||
| try { | ||
| eventDetails = inputLine.split(" ", 2)[1]; | ||
| eventDescription = eventDetails.split("\\s+/from\\s+|\\s+/to\\s+", 3)[0]; | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| System.out.println("\t" + COMMAND_EVENT + " command must be followed by a task " + | ||
| "description!"); | ||
| break; | ||
| } | ||
| try { | ||
| eventFrom = eventDetails.split("\\s+/from\\s+|\\s+/to\\s+", 3)[1]; | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| System.out.println("\t" + COMMAND_EVENT + " command must have /from clause followed by " + | ||
| "time it starts!"); | ||
| break; | ||
| } | ||
| try { | ||
| eventTo = eventDetails.split("\\s+/from\\s+|\\s+/to\\s+", 3)[2]; | ||
| } catch (ArrayIndexOutOfBoundsException e) { | ||
| System.out.println("\t" + COMMAND_EVENT + " command must have /to clause followed by " + | ||
| "time it ends!"); | ||
| break; | ||
| } | ||
|
|
||
| System.out.printf("\t%s: %s\n", PYTHON_EMOJI, "New Event! You have added this event:"); | ||
|
|
||
| Event event = new Event(eventDescription, eventFrom, eventTo); | ||
| tasks.add(event); | ||
|
|
||
| System.out.printf("\t\t\t %s\n", event); | ||
| System.out.printf("\t\tYou have %d tasks in total!\n", tasks.size()); | ||
| break; | ||
| } | ||
| default: | ||
| if (inputLine.isEmpty()) { | ||
| System.out.printf("\t%s: %s\n", PYTHON_EMOJI, "Nothing for me?"); | ||
| break; | ||
| } | ||
| System.out.printf("\t%s: %s\n", PYTHON_EMOJI, "I cannot understand the command!"); | ||
| break; | ||
| } | ||
| printHorizontalLine(); | ||
| } while (!inputLine.equals(COMMAND_BYE)); | ||
| } | ||
| } | ||
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,26 @@ | ||
| public class Event extends Task { | ||
| protected String from, to; | ||
|
|
||
| public Event(String description, String from, String to) { | ||
| super(description); | ||
| this.from = from; | ||
| this.to = to; | ||
| } | ||
|
|
||
| public String getTypeIcon() { | ||
| return "[E]"; | ||
| } | ||
|
|
||
| public String getFrom() { | ||
| return from; | ||
| } | ||
|
|
||
| public String getTo() { | ||
| return to; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return super.toString() + " (from: " + getFrom() + " to: " + getTo() + ")"; | ||
| } | ||
| } |
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,32 @@ | ||
| public abstract class Task { | ||
|
nihalzp marked this conversation as resolved.
Outdated
|
||
| protected String description; | ||
| protected boolean isDone; | ||
|
|
||
| public Task(String description) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| public String getStatusIcon() { | ||
| return (isDone ? "[X]" : "[ ]"); // mark done task with X | ||
| } | ||
|
|
||
| public abstract String getTypeIcon(); | ||
|
|
||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| public boolean getDone() { | ||
|
nihalzp marked this conversation as resolved.
Outdated
|
||
| return isDone; | ||
| } | ||
|
|
||
| public void setDone(boolean done) { | ||
| isDone = done; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return getTypeIcon() + getStatusIcon() + " " + getDescription(); | ||
| } | ||
| } | ||
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,10 @@ | ||
| public class Todo extends Task { | ||
| public Todo(String description) { | ||
| super(description); | ||
| } | ||
|
|
||
| @Override | ||
| public String getTypeIcon() { | ||
| return "[T]"; | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.