diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index fb94957b3c..798a6e47d8 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -6,6 +6,21 @@ ## Design +### Ui +API: [Ui.java]({repoURL}src/main/java/seedu/cafectrl/ui/Ui.java) + +![Ui Class Diagram](images/class/Ui.png) +
*Figure 1: Ui Class Diagram* + +The `Ui` component is responsible for interacting with the user. Within CafeCtrl, `Ui` is instantiated by `Parser`, `Command`, `Main`, `Data`, and `Storage` components to access the print methods in `Ui.java`. + +In the Ui component, +- `Ui.java` consists of multiple methods that received the user input and prints messages to the system console for users to see +- `Messages.java` consists of multiple strings that contains greeting, command, and goodbye messages to be shown to user +- `ErrorMessages.java` consists of multiple strings that contain error messages to be shown to user when an incorrect command or exception has been returned + + + ### Parser API: [Parser.java]({repoURL}src/main/java/seedu/cafectrl/parser/Parser.java) diff --git a/docs/diagrams/class/Ui.puml b/docs/diagrams/class/Ui.puml new file mode 100644 index 0000000000..9e01deb3fb --- /dev/null +++ b/docs/diagrams/class/Ui.puml @@ -0,0 +1,32 @@ +@startuml +'https://plantuml.com/class-diagram + +class Ui { ++ OFFSET_LIST_INDEX: int +- scanner: Scanner ++ receiveUserInput(): String ++ showToUser(message: String) ++ printAddDishMessage(dish: Dish): void ++ printIngredients(selectedDish: Dish): void ++ printDeleteMessage(selectedDish: Dish): void ++ showEditPriceMessage(menuItem: String): void ++ showHelp(): void +} + +class Messages +class ErrorMessages +class Parser +class Command +class Main +class Data +class Storage + +Messages <. Ui : prints < +Ui .> ErrorMessages : prints > +Parser ..> Ui : uses > +Ui "1" <-- "*" Command : ui +Ui "1" <-- "1" Main : ui +Ui "1" <-- "*" Data : ui +Ui "1" <-- "*" Storage :ui + +@enduml \ No newline at end of file diff --git a/docs/images/class/Ui.png b/docs/images/class/Ui.png new file mode 100644 index 0000000000..2e4ba77722 Binary files /dev/null and b/docs/images/class/Ui.png differ diff --git a/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java b/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java index e013aa9e46..d8a4fefcdf 100644 --- a/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java +++ b/src/main/java/seedu/cafectrl/command/BuyIngredientCommand.java @@ -44,7 +44,7 @@ public BuyIngredientCommand(ArrayList ingredients, Ui ui, Pantry pan public void execute() { try { addIngredient(); - ui.showBuyIngredientHeader(); + ui.printBuyIngredientHeader(); ui.showToUser(ingredientString); } catch (RuntimeException e) { ui.showToUser(e.getMessage()); diff --git a/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java b/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java index 69754636fa..1e59594b06 100644 --- a/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java +++ b/src/main/java/seedu/cafectrl/command/DeleteDishCommand.java @@ -29,7 +29,7 @@ public void execute() { try { int dishIndexToBeDeleted = index - Ui.OFFSET_LIST_INDEX; Dish selectedDish = menu.getMenuItemsList().get(dishIndexToBeDeleted); - ui.showDeleteMessage(selectedDish); + ui.printDeleteMessage(selectedDish); menu.removeDish(dishIndexToBeDeleted); } catch (IndexOutOfBoundsException e) { ui.showToUser(ErrorMessages.INVALID_DISH_INDEX); diff --git a/src/main/java/seedu/cafectrl/ui/Ui.java b/src/main/java/seedu/cafectrl/ui/Ui.java index d3f6f3bb10..73bc8c55ba 100644 --- a/src/main/java/seedu/cafectrl/ui/Ui.java +++ b/src/main/java/seedu/cafectrl/ui/Ui.java @@ -93,26 +93,14 @@ public void printAddDishMessage(Dish dish) { * * @param selectedDish Dish to be deleted */ - public void showDeleteMessage(Dish selectedDish) { + public void printDeleteMessage(Dish selectedDish) { showToUser("Okay! " + selectedDish.getName() + " is deleted! :)"); } - public void showBuyIngredientHeader() { + public void printBuyIngredientHeader() { showToUser("Added to stock:"); } - /** - * Shows ingredient to buy message to user - * - * @param ingredient Ingredient to be bought - */ - public void showBuyIngredientMessage(Ingredient ingredient) { - String ingredientString = "Ingredient: " + ingredient.getName() - + "\t\tQty: " + ingredient.getQty() - + ingredient.getUnit(); - showToUser(ingredientString); - } - /** * Shows messages(s) to the user * @param message string(s) of messages to print