Skip to content
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
wants to merge 99 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 Aug 22, 2024
24dd1c8
Add method to print breakline and exit
AjayShanker-geek Aug 22, 2024
07de1ac
:tada: Level-0
AjayShanker-geek Aug 22, 2024
84ac324
:memo: Level-0
AjayShanker-geek Aug 22, 2024
8e1d496
:art: Level-0
AjayShanker-geek Aug 22, 2024
833c440
Reformat code
AjayShanker-geek Aug 30, 2024
0209dec
Add Scanner
AjayShanker-geek Aug 30, 2024
bd7745e
Add method to echo user input
AjayShanker-geek Aug 30, 2024
e9fe9bd
Revert from using indention
AjayShanker-geek Aug 30, 2024
9acfbc9
Support adding and showing list
AjayShanker-geek Aug 30, 2024
ab1fe40
:sparkles: Add Task Class
AjayShanker-geek Aug 30, 2024
0fa9514
Rename items to tasks and cleanup
AjayShanker-geek Aug 30, 2024
c9e9cb7
Add more methods to Task
AjayShanker-geek Aug 30, 2024
cd600a1
Switch to switch to support more commands
AjayShanker-geek Aug 30, 2024
55ed565
:bulb: Add comments and cleanup
AjayShanker-geek Aug 30, 2024
6cc1c39
Cleanup variable inconsistancy
AjayShanker-geek Aug 30, 2024
61a974e
Formate Code
AjayShanker-geek Aug 30, 2024
20c0876
Update Task
AjayShanker-geek Sep 6, 2024
ef26b1d
Add Todo Class
AjayShanker-geek Sep 6, 2024
92e35d8
Add Dealine Class
AjayShanker-geek Sep 6, 2024
c1df0a4
Add Event
AjayShanker-geek Sep 6, 2024
51852f1
Update Javis
AjayShanker-geek Sep 6, 2024
96dc844
Improve readability
AjayShanker-geek Sep 6, 2024
a26b212
Update `runtest.sh` with correct chatbot name
AjayShanker-geek Sep 6, 2024
6b610c3
Add Input Test Cases
AjayShanker-geek Sep 6, 2024
8698da0
Update Expected output
AjayShanker-geek Sep 6, 2024
2d1dfa9
Add comments and improve code quality
AjayShanker-geek Sep 8, 2024
3e6aeaf
Create JarvisException
AjayShanker-geek Sep 11, 2024
2436660
Add class to handle errors
AjayShanker-geek Sep 11, 2024
4d30f12
Add task catch expection
AjayShanker-geek Sep 11, 2024
cf51eb5
Add Todo, Event and Deadline to catch expections
AjayShanker-geek Sep 11, 2024
bccee11
Add Error class to handle error messages and code
AjayShanker-geek Sep 11, 2024
7a5b750
Catch exceptions
AjayShanker-geek Sep 11, 2024
dfdb78c
Merge branch 'branch-Level-5'
AjayShanker-geek Sep 11, 2024
a0483b2
Divide task classes
AjayShanker-geek Sep 11, 2024
9ad849f
Divide expection classes
AjayShanker-geek Sep 11, 2024
13a9539
Update runtest script
AjayShanker-geek Sep 11, 2024
9e36e0a
Merge branch 'branch-A-Packages'
AjayShanker-geek Sep 11, 2024
71efd91
Clean up catching exceptions
AjayShanker-geek Sep 12, 2024
f1077d7
Merge branch 'A-Exceptions'
AjayShanker-geek Sep 12, 2024
0954bf6
Update Readme
AjayShanker-geek Sep 13, 2024
0733df5
Add support task as ArrayList
AjayShanker-geek Sep 18, 2024
693f805
Add support task as ArrayList
AjayShanker-geek Sep 18, 2024
2451c3b
Add support to delete task
AjayShanker-geek Sep 18, 2024
98badc3
Add saving and loading of tasks
AjayShanker-geek Sep 18, 2024
69e9c52
Add catch exceptions index out of bound
AjayShanker-geek Sep 18, 2024
586c155
Add Class to save and load
AjayShanker-geek Sep 18, 2024
24a5d7a
Merge branch 'branch-Level-6'
AjayShanker-geek Sep 18, 2024
6ed8b7e
Merge branch 'branch-Level-7'
AjayShanker-geek Sep 18, 2024
9ade014
Add checks if the data file exists
AjayShanker-geek Sep 18, 2024
42468e8
Improve test cases
AjayShanker-geek Sep 18, 2024
a31001b
Create jar manifest
AjayShanker-geek Sep 18, 2024
4a5e43a
Abstaract prompt relate as Prompt Class
AjayShanker-geek Sep 19, 2024
ee892de
Remove wild card import
AjayShanker-geek Sep 19, 2024
879414c
Clean up main after abstraction Prompt class
AjayShanker-geek Sep 19, 2024
ad8c4a2
Convert and move exit command to prompt
AjayShanker-geek Sep 19, 2024
3f4dc8c
Improve runtest.sh script
AjayShanker-geek Sep 24, 2024
db87a4c
Clean Task Class and Add TaskList
AjayShanker-geek Sep 24, 2024
f7fbb98
Add Parser and Constants
AjayShanker-geek Sep 24, 2024
637f85e
Rename Prompt to Ui
AjayShanker-geek Sep 24, 2024
1ab279b
Cleanup Main
AjayShanker-geek Sep 24, 2024
483f4cb
Restructure code to make the code more OOP
AjayShanker-geek Oct 5, 2024
0810124
Move exception into data folder
AjayShanker-geek Oct 5, 2024
841d2f3
Add TaskList and move into data folder
AjayShanker-geek Oct 5, 2024
36a8f23
Split each command into OOP
AjayShanker-geek Oct 5, 2024
5eb7fc7
Cleanup exceptions catches
AjayShanker-geek Oct 5, 2024
843aa5e
Remove variable to keep track of number of task
AjayShanker-geek Oct 5, 2024
179d7cc
Update text-ui-test
AjayShanker-geek Oct 5, 2024
369fed1
Merge pull request #1 from AjayShanker-geek/moreOOP
AjayShanker-geek Oct 5, 2024
6d16d99
Formate and delete unused codes
AjayShanker-geek Oct 5, 2024
c113d20
Add find command using stream
AjayShanker-geek Oct 10, 2024
b206860
Merge branch 'branch-Level-9'
AjayShanker-geek Oct 10, 2024
39d08af
Ensure storage file and folder exist
AjayShanker-geek Oct 10, 2024
e007cbb
Add support to catch invalid commands
AjayShanker-geek Oct 10, 2024
9cf42fe
Add support to catch deadline is not found
AjayShanker-geek Oct 10, 2024
5312669
Add support to catch event keyword not found
AjayShanker-geek Oct 10, 2024
dc1a56e
Add support to catch out of bound index
AjayShanker-geek Oct 10, 2024
befc96e
Add support catch empty datetime
AjayShanker-geek Oct 11, 2024
89488d3
Improve test cases to include edge cases
AjayShanker-geek Oct 11, 2024
d0b252b
Merge branch 'fix/exceptions'
AjayShanker-geek Oct 11, 2024
9223f71
Clean up UI
AjayShanker-geek Oct 11, 2024
5118288
Merge branch 'feature/clean-up'
AjayShanker-geek Oct 11, 2024
1ff7ade
Add JavaDoc for entry of the program
AjayShanker-geek Oct 11, 2024
c00c7dd
Add JavaDoc for storage
AjayShanker-geek Oct 11, 2024
22f850b
Add JavaDoc Tasks and Commands
AjayShanker-geek Oct 11, 2024
4c427c5
Merge branch 'branch-JavaDoc'
AjayShanker-geek Oct 11, 2024
ce50c7b
Update Docs readme
AjayShanker-geek Oct 11, 2024
1e57f41
Merge branch 'branch-UserGuide'
AjayShanker-geek Oct 11, 2024
def515e
Update runtest
AjayShanker-geek Oct 11, 2024
9d7fc3e
Update image path
AjayShanker-geek Oct 11, 2024
4e090f2
Fix image path
AjayShanker-geek Oct 11, 2024
4d5dc58
Resize image
AjayShanker-geek Oct 11, 2024
604bd97
Reduce size of the image
AjayShanker-geek Oct 11, 2024
5411175
Clean up docs
AjayShanker-geek Oct 11, 2024
caae126
Intergrated docsify
AjayShanker-geek Oct 11, 2024
9e2ba7c
Update User guide info
AjayShanker-geek Oct 11, 2024
7df86cb
Update User Guide image path
AjayShanker-geek Oct 11, 2024
ccc4f75
Fix jarvis cli image not showing
AjayShanker-geek Oct 11, 2024
fc396cb
Update repo README.md
AjayShanker-geek Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Duke project template
# J.A.R.V.I.S project template

This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it.
This is a project template for a greenfield Java project. It's named after the Java mascot _Jarvis_. Given below are instructions on how to use it.

## Setting up in Intellij

Expand All @@ -13,12 +13,13 @@ Prerequisites: JDK 17, update Intellij to the most recent version.
1. If there are any further prompts, accept the defaults.
1. Configure the project to use **JDK 17** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).<br>
In the same dialog, set the **Project language level** field to the `SDK default` option.
3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output:
1. After that, locate the `src/main/java/Jarvis.java` file, right-click it, and choose `Run Jarvis.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output:
```
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|
██╗ █████╗ ██████╗ ██╗ ██╗ ██╗ ███████╗
██║ ██╔══██╗ ██╔══██╗ ██║ ██║ ██║ ██╔════╝
██║ ███████║ ██████╔╝ ██║ ██║ ██║ ███████╗
██ ██║ ██╔══██║ ██╔══██╗ ╚██╗ ██╔╝ ██║ ╚════██║
╚█████╔╝██╗██║ ██║██╗██║ ██║██╗╚████╔╝██╗██║██╗███████║██╗
╚════╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═╝╚═╝╚═╝╚══════╝╚═╝
```
Empty file added data/jarvis.txt
Empty file.
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

3 changes: 3 additions & 0 deletions src/main/java/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: org.ajay.Jarvis

229 changes: 229 additions & 0 deletions src/main/java/org/ajay/Jarvis.java
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 src/main/java/org/ajay/exceptions/EmptyArgumentException.java
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);
}
}
34 changes: 34 additions & 0 deletions src/main/java/org/ajay/exceptions/Error.java
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 {

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.

// SUCCESS, WARN, ERROR, INFO,

// }
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);
}
}
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);
}
}
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);
}
}
7 changes: 7 additions & 0 deletions src/main/java/org/ajay/exceptions/JarvisException.java
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);
}
}
Loading