Skip to content

Commit

Permalink
Merge pull request #3 from Haris-Irfan/branch-A-CodeQuality
Browse files Browse the repository at this point in the history
Improve code quality

Include the exception thrown in the default case of the switch statement
in the parse method. Ensures that by default any invalid inputs will
display an "Invalid input" in the chatbot.

Include missing Java Documentation for some methods
  • Loading branch information
Haris-Irfan authored Sep 19, 2024
2 parents 298bc46 + 3657837 commit 22fcc86
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/main/java/kietwoforone/gui/DialogBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,26 @@ private void flip() {
setAlignment(Pos.TOP_LEFT);
}

/**
* Returns a DialogBox instance when for the user's inputs.
*
* @param text
* @param img
* @return
*/
public static DialogBox getUserDialog(String text, Image img) {
assert text != null: "Text cannot be null.";
assert img != null: "Image cannot be null.";
return new DialogBox(text, img);
}

/**
* Returns a DialogBox instance when the chatbot responds to the user's input.
*
* @param text
* @param img
* @return
*/
public static DialogBox getKieDialog(String text, Image img) {
assert text != null: "Text cannot be null.";
assert img != null: "Image cannot be null.";
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/kietwoforone/gui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ public class Main extends Application {

private KieTwoForOne kie = new KieTwoForOne();

/**
* Sets up the primary stage and initializes the user interface when the application is launched.
*
* @param stage the primary stage for this application, onto which
* the application scene can be set.
* Applications may create other stages, if needed, but they will not be
* primary stages.
*/
@Override
public void start(Stage stage) {
assert stage != null: "Stage cannot be null";
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/kietwoforone/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,8 @@ public static Command parse(String command) throws KieTwoForOneException {
case FIND:
return new FindWordCommand(instruction[1]);
default:
break;
throw new KieTwoForOneException("Invalid input!");
}

return new ByeCommand();
}

}
5 changes: 5 additions & 0 deletions src/main/java/kietwoforone/ui/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ public void showBye() {
System.out.println(response);
}

/**
* Returns the chatbot response to the user's input.
*
* @return
*/
public String getResponse() {
return response;
}
Expand Down

0 comments on commit 22fcc86

Please sign in to comment.