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

Task 174, Add UI Component to DG #213

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<br>*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)

Expand Down
32 changes: 32 additions & 0 deletions docs/diagrams/class/Ui.puml
Original file line number Diff line number Diff line change
@@ -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
Binary file added docs/images/class/Ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public BuyIngredientCommand(ArrayList<Ingredient> ingredients, Ui ui, Pantry pan
public void execute() {
try {
addIngredient();
ui.showBuyIngredientHeader();
ui.printBuyIngredientHeader();
ui.showToUser(ingredientString);
} catch (RuntimeException e) {
ui.showToUser(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 2 additions & 14 deletions src/main/java/seedu/cafectrl/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading