diff --git a/src/main/java/seedu/duke/command/DeleteDishCommand.java b/src/main/java/seedu/duke/command/DeleteDishCommand.java index 0f965242f6..265fb3ca46 100644 --- a/src/main/java/seedu/duke/command/DeleteDishCommand.java +++ b/src/main/java/seedu/duke/command/DeleteDishCommand.java @@ -1,19 +1,37 @@ package seedu.duke.command; import seedu.duke.data.Menu; +import seedu.duke.data.dish.Dish; import seedu.duke.ui.Ui; /** * Deletes a menu item identified using it's last displayed index from the menu. */ public class DeleteDishCommand extends Command { + public static final String COMMAND_WORD = "delete"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes the menu item identified by the index number used in the last menu listing.\n" + "Parameters: INDEX\n" + "Example: " + COMMAND_WORD + " 1"; + + /** + * Constructor for DeleteDishCommand + * + * @param index index of menu item to be deleted + */ + public DeleteDishCommand(int index) { + this.index = index; + } + @Override public void execute(Menu menu, Ui ui) { - - }; + Dish selectedDish = menu.getMenuItemsList().get(index - Ui.OFFSET_LIST_INDEX); + if (selectedDish != null) { + ui.showDeleteMessage(selectedDish); + } else { + ui.showToUser("Please select a valid dish index :)"); + } + menu.removeDish(index); + } } diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java index a16a388c93..1307009dd2 100644 --- a/src/main/java/seedu/duke/parser/Parser.java +++ b/src/main/java/seedu/duke/parser/Parser.java @@ -30,8 +30,8 @@ public static Command parseCommand(Menu menu, String userInput) { return new ListMenuCommand(); case ListIngredientCommand.COMMAND_WORD: return prepareListIngredient(userInput); - /*case DeleteDishCommand.COMMAND_WORD: - return prepareDelete(menu,userInput);*/ + case DeleteDishCommand.COMMAND_WORD: + return prepareDelete(userInput); case ExitCommand.COMMAND_WORD: return new ExitCommand(); case AddDishCommand.COMMAND_WORD: @@ -59,11 +59,16 @@ private static Command prepareListIngredient(String userInput) { } } - private static Command prepareDelete(Menu menu, String userInput) { + /** + * Parses arguments in the context of the Delete command. + * + * @param userInput Input from the user + * @return Command to be executed + */ + private static Command prepareDelete(String userInput) { try { final int listIndex = parseArgsAsDisplayedIndex(userInput, DeleteDishCommand.COMMAND_WORD); - //return new DeleteDishCommand(listIndex); - return new IncorrectCommand("SHANICE DO YOUR WORK"); + return new DeleteDishCommand(listIndex); } catch (ParseException e) { return new IncorrectCommand("MESSAGE_INVALID_COMMAND_FORMAT" + DeleteDishCommand.MESSAGE_USAGE); } catch (NumberFormatException nfe) { diff --git a/src/main/java/seedu/duke/ui/Ui.java b/src/main/java/seedu/duke/ui/Ui.java index bbb54ed939..7b497f6a25 100644 --- a/src/main/java/seedu/duke/ui/Ui.java +++ b/src/main/java/seedu/duke/ui/Ui.java @@ -66,10 +66,10 @@ public void printAddDishMessage(Dish dish) { /** * Shows delete message to user * - * @param menuItem String of menu item deleted + * @param selectedDish Dish to be deleted */ - public void showDeleteMessage(String menuItem) { - showToUser("Okies! " + menuItem + " deleted! :)"); + public void showDeleteMessage(Dish selectedDish) { + showToUser("Okay! " + selectedDish.getName() + " is deleted! :)"); }