From 02f24f285b450235eb7f5fb5e5d10a9456725262 Mon Sep 17 00:00:00 2001 From: gmuthu17 Date: Tue, 10 Mar 2020 12:59:09 +0800 Subject: [PATCH] mvp of menu with style fixed --- src/main/java/Dish.java | 17 ++++++++++++++++- src/main/java/Menu.java | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/main/java/Dish.java b/src/main/java/Dish.java index f9da3d53f..e107a6db9 100644 --- a/src/main/java/Dish.java +++ b/src/main/java/Dish.java @@ -2,15 +2,30 @@ public class Dish { + /** + * Arraylist of all ingredients for dish + */ private ArrayList ingredients; + /** + * Name of dish + */ private String name; - public Dish(String name, ArrayList ingredients ) { + /** + * Dish constructor + * @param name name of dish + * @param ingredients arraylist of ingredients in dish + */ + public Dish(String name, ArrayList ingredients) { this.name = name; this.ingredients = ingredients; } + /** + * Returns ingredients in dish + * @return arraylist of ingredients in dish + */ public ArrayList getIngredients() { return ingredients; } diff --git a/src/main/java/Menu.java b/src/main/java/Menu.java index b2fa25367..1fe21ae24 100644 --- a/src/main/java/Menu.java +++ b/src/main/java/Menu.java @@ -4,19 +4,35 @@ public class Menu { + /** + * Hashmap of all dishes on menu + */ private static HashMap dishMap = new HashMap(); - public static void addDish (String input) { + /** + * Adds a dish to the menu based on the input string + * @param input input string that include dish name and ingredients in no specific order + */ + public static void addDish(String input) { ArrayList ingredients = parseIngredients(input); String name = parseName(input); Dish d = new Dish(name, ingredients); dishMap.put(name, d); } - public static void deleteDish (String name) { + /** + * Removes dish from menu + * @param name name of dish to remove + */ + public static void deleteDish(String name) { dishMap.remove(name); } + /** + * Parses ingredients from string + * @param input string of ingredients + * @return ArrayList of ingredients + */ public static ArrayList parseIngredients(String input) { ArrayList ingredients = new ArrayList(); input = input.substring(input.indexOf("i/") + 2); @@ -28,23 +44,35 @@ public static ArrayList parseIngredients(String input) { return ingredients; } + /** + * Parses name from input string + * @param input input string + * @return name of dish + */ public static String parseName(String input) { input = input.substring(input.indexOf("n/") + 2); input = input.substring(0, input.indexOf(";")); return input; } + /** + * Print's dishes out from dishMap + */ public static void printDishes() { for (String name: dishMap.keySet()) { - String iList = ""; + String ingredientList = ""; for (String str: dishMap.get(name).getIngredients()) { - iList += str + ","; + ingredientList += str + ","; } - iList = iList.substring(0, iList.length()-1); - System.out.println("Name: " + name + "; Ingredients: " + iList); + ingredientList = ingredientList.substring(0, ingredientList.length() - 1); + System.out.println("Name: " + name + "; Ingredients: " + ingredientList); } } + /** + * Return's dishMap hashmap + * @return dishmap hashmap + */ public static HashMap getDishMap() { return dishMap; }