-
Notifications
You must be signed in to change notification settings - Fork 117
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
[Ajay Shanker] iP #117
Open
AjayShanker-geek
wants to merge
99
commits into
nus-cs2113-AY2425S1:master
Choose a base branch
from
AjayShanker-geek: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
[Ajay Shanker] iP #117
Changes from 52 commits
Commits
Show all changes
99 commits
Select commit
Hold shift + click to select a range
4dfe0fb
Rename Chatbot from Duke to Jarvis
AjayShanker-geek 24dd1c8
Add method to print breakline and exit
AjayShanker-geek 07de1ac
:tada: Level-0
AjayShanker-geek 84ac324
:memo: Level-0
AjayShanker-geek 8e1d496
:art: Level-0
AjayShanker-geek 833c440
Reformat code
AjayShanker-geek 0209dec
Add Scanner
AjayShanker-geek bd7745e
Add method to echo user input
AjayShanker-geek e9fe9bd
Revert from using indention
AjayShanker-geek 9acfbc9
Support adding and showing list
AjayShanker-geek ab1fe40
:sparkles: Add Task Class
AjayShanker-geek 0fa9514
Rename items to tasks and cleanup
AjayShanker-geek c9e9cb7
Add more methods to Task
AjayShanker-geek cd600a1
Switch to switch to support more commands
AjayShanker-geek 55ed565
:bulb: Add comments and cleanup
AjayShanker-geek 6cc1c39
Cleanup variable inconsistancy
AjayShanker-geek 61a974e
Formate Code
AjayShanker-geek 20c0876
Update Task
AjayShanker-geek ef26b1d
Add Todo Class
AjayShanker-geek 92e35d8
Add Dealine Class
AjayShanker-geek c1df0a4
Add Event
AjayShanker-geek 51852f1
Update Javis
AjayShanker-geek 96dc844
Improve readability
AjayShanker-geek a26b212
Update `runtest.sh` with correct chatbot name
AjayShanker-geek 6b610c3
Add Input Test Cases
AjayShanker-geek 8698da0
Update Expected output
AjayShanker-geek 2d1dfa9
Add comments and improve code quality
AjayShanker-geek 3e6aeaf
Create JarvisException
AjayShanker-geek 2436660
Add class to handle errors
AjayShanker-geek 4d30f12
Add task catch expection
AjayShanker-geek cf51eb5
Add Todo, Event and Deadline to catch expections
AjayShanker-geek bccee11
Add Error class to handle error messages and code
AjayShanker-geek 7a5b750
Catch exceptions
AjayShanker-geek dfdb78c
Merge branch 'branch-Level-5'
AjayShanker-geek a0483b2
Divide task classes
AjayShanker-geek 9ad849f
Divide expection classes
AjayShanker-geek 13a9539
Update runtest script
AjayShanker-geek 9e36e0a
Merge branch 'branch-A-Packages'
AjayShanker-geek 71efd91
Clean up catching exceptions
AjayShanker-geek f1077d7
Merge branch 'A-Exceptions'
AjayShanker-geek 0954bf6
Update Readme
AjayShanker-geek 0733df5
Add support task as ArrayList
AjayShanker-geek 693f805
Add support task as ArrayList
AjayShanker-geek 2451c3b
Add support to delete task
AjayShanker-geek 98badc3
Add saving and loading of tasks
AjayShanker-geek 69e9c52
Add catch exceptions index out of bound
AjayShanker-geek 586c155
Add Class to save and load
AjayShanker-geek 24a5d7a
Merge branch 'branch-Level-6'
AjayShanker-geek 6ed8b7e
Merge branch 'branch-Level-7'
AjayShanker-geek 9ade014
Add checks if the data file exists
AjayShanker-geek 42468e8
Improve test cases
AjayShanker-geek a31001b
Create jar manifest
AjayShanker-geek 4a5e43a
Abstaract prompt relate as Prompt Class
AjayShanker-geek ee892de
Remove wild card import
AjayShanker-geek 879414c
Clean up main after abstraction Prompt class
AjayShanker-geek ad8c4a2
Convert and move exit command to prompt
AjayShanker-geek 3f4dc8c
Improve runtest.sh script
AjayShanker-geek db87a4c
Clean Task Class and Add TaskList
AjayShanker-geek f7fbb98
Add Parser and Constants
AjayShanker-geek 637f85e
Rename Prompt to Ui
AjayShanker-geek 1ab279b
Cleanup Main
AjayShanker-geek 483f4cb
Restructure code to make the code more OOP
AjayShanker-geek 0810124
Move exception into data folder
AjayShanker-geek 841d2f3
Add TaskList and move into data folder
AjayShanker-geek 36a8f23
Split each command into OOP
AjayShanker-geek 5eb7fc7
Cleanup exceptions catches
AjayShanker-geek 843aa5e
Remove variable to keep track of number of task
AjayShanker-geek 179d7cc
Update text-ui-test
AjayShanker-geek 369fed1
Merge pull request #1 from AjayShanker-geek/moreOOP
AjayShanker-geek 6d16d99
Formate and delete unused codes
AjayShanker-geek c113d20
Add find command using stream
AjayShanker-geek b206860
Merge branch 'branch-Level-9'
AjayShanker-geek 39d08af
Ensure storage file and folder exist
AjayShanker-geek e007cbb
Add support to catch invalid commands
AjayShanker-geek 9cf42fe
Add support to catch deadline is not found
AjayShanker-geek 5312669
Add support to catch event keyword not found
AjayShanker-geek dc1a56e
Add support to catch out of bound index
AjayShanker-geek befc96e
Add support catch empty datetime
AjayShanker-geek 89488d3
Improve test cases to include edge cases
AjayShanker-geek d0b252b
Merge branch 'fix/exceptions'
AjayShanker-geek 9223f71
Clean up UI
AjayShanker-geek 5118288
Merge branch 'feature/clean-up'
AjayShanker-geek 1ff7ade
Add JavaDoc for entry of the program
AjayShanker-geek c00c7dd
Add JavaDoc for storage
AjayShanker-geek 22f850b
Add JavaDoc Tasks and Commands
AjayShanker-geek 4c427c5
Merge branch 'branch-JavaDoc'
AjayShanker-geek ce50c7b
Update Docs readme
AjayShanker-geek 1e57f41
Merge branch 'branch-UserGuide'
AjayShanker-geek def515e
Update runtest
AjayShanker-geek 9d7fc3e
Update image path
AjayShanker-geek 4e090f2
Fix image path
AjayShanker-geek 4d5dc58
Resize image
AjayShanker-geek 604bd97
Reduce size of the image
AjayShanker-geek 5411175
Clean up docs
AjayShanker-geek caae126
Intergrated docsify
AjayShanker-geek 9e2ba7c
Update User guide info
AjayShanker-geek 7df86cb
Update User Guide image path
AjayShanker-geek ccc4f75
Fix jarvis cli image not showing
AjayShanker-geek fc396cb
Update repo README.md
AjayShanker-geek 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 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 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 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: org.ajay.Jarvis | ||
|
This file contains 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,229 @@ | ||
package org.ajay; | ||
|
||
import java.util.ArrayList; | ||
import java.util.NoSuchElementException; | ||
import java.util.Scanner; | ||
import org.ajay.exceptions.*; | ||
import org.ajay.exceptions.Error; | ||
import org.ajay.exceptions.IllegalArgumentException; | ||
import org.ajay.task.*; | ||
import org.ajay.utils.Storage; | ||
|
||
public class Jarvis { | ||
// Constants | ||
static final int MAX_TASK_LENGTH = 100; // Maximum length of a string | ||
|
||
private static final String chatBotName = "Jarvis"; // Name of the chatbot | ||
|
||
private static ArrayList<Task> taskList = new ArrayList<>(); // ArrayList to store tasks | ||
|
||
static String command; // Variable to store the command | ||
static String task; // Variable to store the task | ||
|
||
/** | ||
* Prints a break line to the console. | ||
*/ | ||
private static void printBreakLine() { | ||
System.out.println("────────────────────────────────────────────────────────────"); | ||
} | ||
|
||
/** | ||
* Gracefully exits the program. | ||
* | ||
* @param status | ||
*/ | ||
private static void exit(int status) { | ||
System.exit(status); | ||
} | ||
|
||
/** | ||
* Prints the prompt to the console for visual marker for user to type. | ||
*/ | ||
private static void printPrompt() { | ||
System.out.print(" "); | ||
} | ||
|
||
/** | ||
* Prints the greeting messages to the console. | ||
*/ | ||
private static void printGreetingMsgs() { | ||
String[] greetings = {"Hello! I'm " + chatBotName + "\nWhat can I do for you?"}; // List of greetings | ||
|
||
// Print the greetings | ||
for (String greeting : greetings) { | ||
printBreakLine(); // Print a break line before each greeting | ||
System.out.println(greeting); // Print the greeting | ||
} | ||
printBreakLine(); | ||
} | ||
|
||
/** | ||
* Prints the goodbye messages to the console. | ||
*/ | ||
private static void printGoodbyeMsgs() { | ||
String[] goodbyes = {"Bye. Hope to see you again soon!"}; // List of goodbye messages | ||
|
||
// Print the goodbye messages | ||
for (String goodbye : goodbyes) { | ||
printBreakLine(); | ||
System.out.println(goodbye); // Print the goodbye message | ||
} | ||
printBreakLine(); | ||
exit(0); | ||
} | ||
|
||
/** | ||
* Prints the tasks to the console. | ||
*/ | ||
public static void printTasks() { | ||
printBreakLine(); | ||
Task.printAllTasks(taskList); | ||
printBreakLine(); | ||
} | ||
|
||
/** | ||
* Splits the command and task from the input. | ||
* | ||
* @param lineBufferString | ||
*/ | ||
public static void splitCommandAndTask(String lineBufferString) throws EmptyArgumentException { | ||
|
||
if (lineBufferString.isEmpty()) { | ||
throw new EmptyArgumentException(Error.EMPTY_ARG.toString()); | ||
} | ||
|
||
if (lineBufferString.contains(" ")) { | ||
command = lineBufferString.split(" ")[0]; | ||
task = lineBufferString.substring(command.length() + 1); | ||
} else { | ||
command = lineBufferString; | ||
task = null; | ||
} | ||
} | ||
|
||
/** | ||
* Reads the input from the user and processes it. | ||
* | ||
* @param in | ||
* @param lineBufferString | ||
*/ | ||
public static void readInput(Scanner in, String lineBufferString) { | ||
try { | ||
printPrompt(); // Print the prompt to the console | ||
lineBufferString = in.nextLine(); | ||
splitCommandAndTask(lineBufferString); | ||
|
||
switch (command) { | ||
case "bye": | ||
printGoodbyeMsgs(); | ||
break; | ||
case "exit": // Habit of typing exit to exit the program | ||
printGoodbyeMsgs(); | ||
break; | ||
case Task.LIST_COMMAND_STRING: // List all the tasks | ||
printTasks(); | ||
break; | ||
case Todo.COMMAND_STRING: // Add a todo task | ||
// taskList[Task.getNumberOfTasks()] = new Todo(task); | ||
taskList.add(new Todo(task)); | ||
printBreakLine(); | ||
|
||
Storage.saveTaskList(taskList); | ||
break; | ||
case Deadline.COMMAND_STRING: // Add a deadline task | ||
// taskList[Task.getNumberOfTasks()] = new Deadline(task); | ||
taskList.add(new Deadline(task)); | ||
printBreakLine(); | ||
|
||
Storage.saveTaskList(taskList); | ||
break; | ||
case Event.COMMAND_STRING: // Add an event task | ||
// taskList[Task.getNumberOfTasks()] = new Event(task); | ||
taskList.add(new Event(task)); | ||
printBreakLine(); | ||
|
||
Storage.saveTaskList(taskList); | ||
break; | ||
case Task.MARK_COMMAND_STRING: // Mark the task as done | ||
int taskNumberMark = Integer.parseInt(task); // Get the task number | ||
Task.markAsDone(taskList, taskNumberMark); // Mark the task as done | ||
|
||
Storage.saveTaskList(taskList); | ||
break; | ||
case Task.UNMARK_COMMAND_STRING: // Mark the task as undone | ||
int taskNumberUnmark = Integer.parseInt(task); // Get the task number | ||
Task.markAsUndone(taskList, taskNumberUnmark); // Mark the task as undone | ||
|
||
Storage.saveTaskList(taskList); | ||
break; | ||
case Task.DELETE_COMMAND_STRING: // Delete the task | ||
int taskNumberDelete = Integer.parseInt(task); // Get the task number | ||
Task.deleteTask(taskList, taskNumberDelete); // Delete the task | ||
|
||
Storage.saveTaskList(taskList); | ||
break; | ||
default: | ||
throw new IllegalCommandException(Error.ILLEGAL_COMMAND.toString()); | ||
} | ||
|
||
readInput(in, lineBufferString); // Recursively call the function to read the next input | ||
} catch (EmptyArgumentException | IllegalCommandException | InvalidCommandFormatException | | ||
IllegalArgumentException e) { | ||
printBreakLine(); | ||
System.out.println(e); | ||
printBreakLine(); | ||
readInput(in, lineBufferString); | ||
} catch (NoSuchElementException e) { | ||
// FIXME: Facing unexpected NoSuchElementException error | ||
} | ||
|
||
} | ||
|
||
public static void main(String[] args) { | ||
String logo = """ | ||
@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@% @@ @@ @@@ | ||
@@ @@ @@ @@ | ||
@@ @@ @@ @@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@ *@ | ||
@@@ @@@ | ||
@ @@@ @@@ @ | ||
@& @@ @@@@@@@@@@@@@@@@@@@@@ @@. @@ | ||
@ @@@ @@ @@ @@@ @ | ||
@ *@@ @@ @( @@( @ | ||
@ ,@@@@ @@ @@ @@@@ @ | ||
@ @@@@@ %@@ @@ @ @@& @@@@@ @ | ||
@@@@ @@@ /@ @@ @@@ *@@@@/ | ||
@@ @@@ @@ @@@ @@ | ||
@@ @@& (@@ @@ | ||
@ @@@@@@@@ @@@@@@@ @ | ||
@@ @@@@* @@, @@ @@@@ @& | ||
@@ @@@ @@@ @@ | ||
@@@ @@ @@ @@# | ||
@@@@ @@@ @@@ @@@@ | ||
@@@@@@@@@@@@@ | ||
|
||
██╗ █████╗ ██████╗ ██╗ ██╗ ██╗ ███████╗ | ||
██║ ██╔══██╗ ██╔══██╗ ██║ ██║ ██║ ██╔════╝ | ||
██║ ███████║ ██████╔╝ ██║ ██║ ██║ ███████╗ | ||
██ ██║ ██╔══██║ ██╔══██╗ ╚██╗ ██╔╝ ██║ ╚════██║ | ||
╚█████╔╝██╗██║ ██║██╗██║ ██║██╗╚████╔╝██╗██║██╗███████║██╗ | ||
╚════╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═╝╚═╝╚═╝╚══════╝╚═╝ | ||
"""; | ||
|
||
String lineBufferString = ""; // Buffer to store the input from the user | ||
Scanner in = new Scanner(System.in); // Scanner object to read input from the user | ||
|
||
System.out.println("Hello from\n" + logo); | ||
printGreetingMsgs(); | ||
|
||
try { | ||
Storage.loadTaskList(taskList); | ||
} catch (EmptyArgumentException | IllegalArgumentException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
readInput(in, lineBufferString); // Read the input from the user | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/ajay/exceptions/EmptyArgumentException.java
This file contains 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 org.ajay.exceptions; | ||
|
||
public class EmptyArgumentException extends JarvisException { | ||
public EmptyArgumentException(String msg) { | ||
super(msg); | ||
} | ||
} |
This file contains 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,34 @@ | ||
package org.ajay.exceptions; | ||
|
||
|
||
// NOTE: Taken from https://stackoverflow.com/questions/446663/best-way-to-define-error-codes-strings-in-java | ||
public enum Error { | ||
|
||
EMPTY_ARG(0, "Empty argument found."), ILLEGAL_COMMAND(1, "Invalid command found."), INVAILD_COMMAND_FORMAT(2, "Invalid command format found."), OUT_OF_BOUNDS(3, "Index out of bounds."); | ||
|
||
private final int code; | ||
private final String description; | ||
|
||
private Error(int code, String description) { | ||
this.code = code; | ||
this.description = description; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public int getCode() { | ||
return code; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return description + " (Error Code: " + code + ")"; | ||
} | ||
} | ||
|
||
// public enum ErrorLevel { | ||
// SUCCESS, WARN, ERROR, INFO, | ||
|
||
// } |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/ajay/exceptions/IllegalArgumentException.java
This file contains 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 org.ajay.exceptions; | ||
|
||
public class IllegalArgumentException extends JarvisException { | ||
public IllegalArgumentException(String msg) { | ||
super(msg); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/org/ajay/exceptions/IllegalCommandException.java
This file contains 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,8 @@ | ||
package org.ajay.exceptions; | ||
|
||
|
||
public class IllegalCommandException extends JarvisException { | ||
public IllegalCommandException(String msg) { | ||
super(msg); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/org/ajay/exceptions/InvalidCommandFormatException.java
This file contains 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,8 @@ | ||
package org.ajay.exceptions; | ||
|
||
|
||
public class InvalidCommandFormatException extends JarvisException { | ||
public InvalidCommandFormatException(String msg) { | ||
super(msg); | ||
} | ||
} |
This file contains 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 org.ajay.exceptions; | ||
|
||
public class JarvisException extends Exception { | ||
public JarvisException(String msg) { | ||
super(msg); | ||
} | ||
} |
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.
Remember to remove the commented code.