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

[Tan Hin Khai Stephen] iP #454

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
3b19ba1
Add Gradle support
May 24, 2020
04795bd
Level 1 added
blackonyyx Aug 17, 2020
af52847
Level 2 is here
blackonyyx Aug 17, 2020
6dbdb55
Level 3
blackonyyx Aug 18, 2020
00166f5
A-Classes used classes to represent tasks
blackonyyx Aug 18, 2020
962693b
Added Inheritance for tasks and managed tasks via manager
blackonyyx Aug 19, 2020
69ac44d
Added sh script automated testing
blackonyyx Aug 20, 2020
379eb1c
Added Enums, Packaged Related classes together, Error handling
blackonyyx Aug 20, 2020
8e70ce3
Added Delete command to the list of supported commands
blackonyyx Aug 20, 2020
7287ce9
Added IO file handling to the Chatbot Application such that the Chatbot
blackonyyx Aug 25, 2020
cd26774
Added datetime parsing to the TimedTask Classes
blackonyyx Aug 25, 2020
25b8c2a
Merge branch 'branch-Level-8'
blackonyyx Aug 27, 2020
f909eb3
More OOP
blackonyyx Aug 27, 2020
b90a157
1. Add jUnit Testing on Timed Task and TextParser Class
blackonyyx Aug 27, 2020
04db2ff
Branch for Level 9 of Duke Project.
blackonyyx Aug 28, 2020
8ad3c66
Make Code adheres to java code standards of module.
blackonyyx Aug 28, 2020
5a72d63
Add javadocs for all constructors and class headers,
blackonyyx Aug 29, 2020
535afe7
Merge branch 'A-JavaDoc' of https://github.com/blackonyyx/ip
blackonyyx Aug 29, 2020
f7f5414
Merge branch 'branch-Level-9' of https://github.com/blackonyyx/ip
blackonyyx Aug 29, 2020
08208e0
Merge branch 'add-gradle-support' of https://github.com/blackonyyx/ip
blackonyyx Aug 31, 2020
6261301
Add gradle integration into master branch.
blackonyyx Aug 31, 2020
454fbd2
Enforced CheckStyle on all violating code blocks
blackonyyx Sep 2, 2020
0c58a00
Add a GUI for the Duke Application
blackonyyx Sep 5, 2020
bf97679
Add Major overhaul and refactor of code base to follow a more functional
blackonyyx Sep 9, 2020
4ab281c
Add new refactoring of GUI to have better feel.
blackonyyx Sep 11, 2020
ad6ee84
Amend Code to conform with Checkstyle requirements.
blackonyyx Sep 11, 2020
34dc6db
Minor String Formatting modifications
blackonyyx Sep 11, 2020
1cabdc8
Merge pull request #1 from blackonyyx/branch-A-Assertions
blackonyyx Sep 11, 2020
fa1e1bb
Minor Code Formatting modifications
blackonyyx Sep 11, 2020
26295c2
Merge branch 'master' into branch-A-CodeQuality
blackonyyx Sep 11, 2020
97fccd0
Create gradle.yml
blackonyyx Sep 11, 2020
58e7cc9
Merge pull request #4 from blackonyyx/Continuous-Integ-2
blackonyyx Sep 11, 2020
3ae73c5
Merge pull request #3 from blackonyyx/branch-A-CodeQuality
blackonyyx Sep 11, 2020
42861a1
stuff
blackonyyx Sep 14, 2020
0371616
Merge branch 'master' of https://github.com/blackonyyx/ip
blackonyyx Sep 14, 2020
9caac97
Amend Code to contain less this.<attribute / method> to conform with the
blackonyyx Sep 14, 2020
4f15860
Add User Guide to the project repository and update README.md to reflect
blackonyyx Sep 14, 2020
40edbce
Add README.md and Userguide help.
blackonyyx Sep 14, 2020
e4d5cf5
Set theme jekyll-theme-dinky
blackonyyx Sep 15, 2020
c94b6d0
Merge branch 'master' of https://github.com/blackonyyx/ip
blackonyyx Sep 15, 2020
ec13865
Add README.md and Userguide help.
blackonyyx Sep 15, 2020
b45c888
Set theme jekyll-theme-dinky
blackonyyx Sep 17, 2020
bb34eff
Removed boiler plate code
blackonyyx Sep 18, 2020
c275aea
Merge branch 'master' of https://github.com/blackonyyx/ip
blackonyyx Sep 18, 2020
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
97 changes: 97 additions & 0 deletions src/main/java/ChatbotApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import exceptions.DukeException;
import exceptions.DukeIOException;
import exceptions.DukeUnknownException;

import java.util.Scanner;

/**
* Front End Facing Script for the UI of ChatbotApplication
*/
public class ChatbotApplication {
private final String linebreaker;
Duke dukeProgram;
boolean isChatbotRunning;

/**
* Constructor class of the ChatbotApplication
* @param linebreaker the display aesthetic of the output from Duke
* @param pth the path to read a file from.
*/
ChatbotApplication(String linebreaker, String pth){
dukeProgram = new Duke(pth);
isChatbotRunning = true;
this.linebreaker = linebreaker.repeat(50) + "\n";
}

/**
* Takes a scanner object as user input and initialises the dukeLoop
* @param sc UserInput for the Application.
*/
public void dukeLoop(Scanner sc) {
print("Please Enter your name");
String name = sc.nextLine();
print(dukeProgram.greeting(name));
String in = "";
String out = "";
while (this.isRunning()) {
in = sc.nextLine();
try {
out = dukeProgram.takeInput(in);
if (Boolean.parseBoolean(out)) {
this.setChatbotRunning(false);
} else {
print(out);
}
} catch (DukeUnknownException e) {
print(e.toString());
this.setChatbotRunning(false);
} catch (DukeException e) {
print(e.toString());
}
}
try {
dukeProgram.saveTasks();
} catch (DukeIOException e) {
print(e.toString());
}
sc.close();
print(dukeProgram.goodbye(name));
}

/**
* Running state of the Duke Application
* @return State of Duke running
*/
private boolean isRunning() {
return this.isChatbotRunning;
}

/**
* Wraps all text output and prints to the console
* @param s String output
*/
private void print(String s){
System.out.printf("%s%s\n%s%n",linebreaker,s,linebreaker);
}

/**
* Setter for the status of the Chatbot Object
* @param b toggle on or off for chatbot
*/
private void setChatbotRunning(boolean b){
this.isChatbotRunning = b;
}
/**
* Execution Class to contain main loop
* @param args args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//System.out.println("What is your name?");
String path = System.getProperty("user.dir");
ChatbotApplication d = new ChatbotApplication("##", path);
// To refactor ChatbotApplication to hold mainloop such that UI elements to be added in future
// can be interactive with the application through ChatbotApplication class directly.
d.dukeLoop(sc);
}
}
149 changes: 141 additions & 8 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,143 @@
public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
import exceptions.*;
import tasks.Command;
import tasks.TaskManager;
import tasks.TextParser;

/**
* Backend Object Class for the Duke Chatbot Interface
*/
class Duke {
private final TaskManager taskManager;
private final TextParser textParser;

/**
* Constructor for the Duke Chatbot, if is old initialisation, will read from txt file
* Eles it will initialise a new TaskManager class
* @param path The path of the home initialisation.
*/
public Duke(String path) {
TaskManager list1;
try {
list1 = new TaskManager(path);
} catch (DukeIOException e) {
list1 = new TaskManager(path, true);
}
this.textParser = new TextParser();
this.taskManager = list1;
}

/**
* Manages all internal dataflow from Main or textual interaction
* with the chatbot, by cleaning it
* @param input User Input from the UI
* @return String form of command to output to UI
* @throws DukeException when there is an exception thrown
*/
public String takeInput(String input) throws DukeException {
//To prevent an Security Concern or Code Injection Cleaning of text is first performed and authenticated
// by adding an ending token
//TODO eventually to convert the input -> Command with getter for task, deadline(if applicable)
String cleaned = cleanInput(input);
// There is minimally a sep
String[] words = cleaned.split(" ");
cleaned = cleaned.replace(" [sep]", "");
// Take out command from the words
String text_input = cleaned.replaceFirst(words[0], "");
//Sep token is added to prevent index errors
Command c = textParser.parseCommand(words[0]);

switch (c) {
case BYE:
return Boolean.TRUE.toString();
case HELP:
return this.help();
blackonyyx marked this conversation as resolved.
Show resolved Hide resolved
case DONE:
return taskManager.doTask(words[1]);
case DELETE:
return taskManager.deleteTask(words[1]);
case LIST:
return taskManager.parseoutput();
case SEARCH:
return taskManager.findTasks(words[1]);
case TODO:
return this.taskManager.addToDo(text_input);
case DEADLINE:
return this.taskManager.addDeadline(text_input);
case EVENT:
return this.taskManager.addEvent(text_input);
case BLANK:
throw new DukeBlankCommandException("''");
case ERROR:
throw new DukeCommandException(words[0]);
default:
throw new DukeUnknownException(text_input);

}
}


/**
* inputs string, processes and cleans the text for the chatbot
* via adding a ending token seperator
* @param userInput Direct user input of the string
* @return Cleaned user input
*/
private String cleanInput(String userInput) {
return userInput + " [sep]";
}

/**
* Returns a help message about all commands supported by Duke
* @return help message
*/
public String help() {
//eventually to add command help <command>
return "\t Need some help huh?\n" +
"\t Heres a list of my commands!\n" +
"\t- 'bye' to close the application\n" +
"\t- 'list' to list the current list of tasks and their statuses\n" +
"\t- 'done' to set a task as done\n" +
"\t- 'find' to find a task using regex or a query text string\n" +
"\t- 'todo' to list a untimed task\n" +
"\t- 'deadline' to list a timed deadline task, please structure with " +
"[deadline <task name> /by dd-MM-YYYY]\n" +
"\t- 'event' to list a timed event task, please structure with [event <task name> /at dd-MM-YYYY]\n" +
"\t- 'help' to list these commands again\n";
}

/**
* Greeting from Duke Bot
* @param name Name of the user
* @return Sends a greeting from dukebot to the user
*/
String greeting(String name) {

String logo = "\tHello from\n" +
" ____ _ \n" +
"| _ \\ _ _| | _____ \n" +
"| | | | | | | |/ / _ \\\n" +
"| |_| | |_| | < __/\n" +
"|____/ \\__,_|_|\\_\\___|\n" +
"\tHello! I'm Duke\n\tWhat can I do for you " +
name +
"\n";
return logo;
}

/**
* Goodbye from DukeBot
* @param name Name of the user
* @return Sends a goodbye message from dukebot to the user
*/
String goodbye(String name){
return "Bye " + name +"! Hope to see you again soon!";
}

/**
* Message passing from mainloop to save tasks.
* @throws DukeIOException if something goes wrong with the IO Savefiles
*/
void saveTasks() throws DukeIOException {
this.taskManager.saveTasks();
}
}
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: ChatbotApplication

14 changes: 14 additions & 0 deletions src/main/java/exceptions/DukeBlankCommandException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package exceptions;

/**
* Error Type of a Blank Command in Duke Application.
*/
public class DukeBlankCommandException extends DukeException{
/**
* Constructor for DukeBlankCommandException for a blank command
* @param s String form of the bad input
*/
public DukeBlankCommandException(String s){
super(s,4);
}
}
14 changes: 14 additions & 0 deletions src/main/java/exceptions/DukeCommandException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package exceptions;

/**
* Error Type of a Invalid Command in Duke Application.
*/
public class DukeCommandException extends DukeException {
/**
* Constructor class for DukeCommandException
* @param bad_cmd the command that is unrecognisable by Duke Application
*/
public DukeCommandException(String bad_cmd) {
blackonyyx marked this conversation as resolved.
Show resolved Hide resolved
super(bad_cmd, 1);
}
}
29 changes: 29 additions & 0 deletions src/main/java/exceptions/DukeDateTimeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package exceptions;

/**
* Error Type of a DateTimeError in Duke Application.
* This error is thrown if the DateTime does not match or is incompatible with the DateTimeFormatter
*/
public class DukeDateTimeException extends DukeException {
/**
* Constructor class for DukeDateTimeException
* @param cmd the invalid command
*/
public DukeDateTimeException(String cmd){
super(cmd,3);
}

/**
* Takes in the given bad input and the code
* @return String
*/
public String message(String s) {
StringBuilder b = new StringBuilder();
b.append("\t Oops you did not mark your datetime! Not sure what you mean by:\n");
b.append("\t ").append(bad_cmd).append("\n");
b.append("\t ").append(s);
b.append(": ").append(code.toString()).append("\n");
b.append("\t Heres a tip, use the 'help' command to learn about my commands!\n");
return b.toString();
}
}
48 changes: 48 additions & 0 deletions src/main/java/exceptions/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package exceptions;

/**
* DukeException is a classification of errors that pertain to any running problems within Duke Class applications
* Some errors that may occur in the hierarchy of data flow:
* 1. FileRead Error (WIP): For handling stored memory and I/O errors
* 2. Bad Command Given: When a Command that is unknown is given
* 3. No Input given: When in the flow for a given command, no description is detected
* 4. Bad Date Given: For handling datetime parsing errors.
* 5. Blank Command Given: For handling when a Blank command is given to a input.
* 6. Index Error: When a invalid index is given
* 7. UnknownException: For handling anything exceptionally unexpected
*/
blackonyyx marked this conversation as resolved.
Show resolved Hide resolved
public abstract class DukeException extends Exception {

String bad_cmd;
ErrorEncode code;
blackonyyx marked this conversation as resolved.
Show resolved Hide resolved

/**
* Constructor class for a Generic DukeException for any errortype encountered in Duke
blackonyyx marked this conversation as resolved.
Show resolved Hide resolved
* @param bad_cmd The command or user input that is causing the error
* @param code The enumeration to encode the error message.
*/
protected DukeException(String bad_cmd, int code){
this.bad_cmd = bad_cmd;
this.code = ErrorEncode.parseCode(code);
}

/**
* Returns the template user error message of the DukeException class
* @return String message to be printed out to player.
*/
public String message(String s) {
StringBuilder b = new StringBuilder();
b.append("\t Oops you used a invalid command! Not sure what you mean by:\n");
b.append("\t ").append(bad_cmd).append("\n");
b.append("\t ").append(s);
b.append(": ").append(code.toString()).append("\n");
b.append("\t Heres a tip, use the 'help' command to learn about my commands!\n");
return b.toString();
}

@Override
public String toString() {

return message(super.toString());
}
}
14 changes: 14 additions & 0 deletions src/main/java/exceptions/DukeIOException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package exceptions;

/**
* Error type for I/O that appear when trying to perform a read or write command.
*/
public class DukeIOException extends DukeException{
/**
* Constructor for I/O exception class.
* @param bad_cmd the part of the I/O process that is causing an error
*/
public DukeIOException(String bad_cmd){
super(bad_cmd, 0);
}
}
Loading