Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY1920S2#6 from gmuthu17/master
Browse files Browse the repository at this point in the history
mvp of menu with style fixed
  • Loading branch information
gmuthu17 authored Mar 10, 2020
2 parents 3e8f31d + 02f24f2 commit 46269b8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
17 changes: 16 additions & 1 deletion src/main/java/Dish.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,30 @@

public class Dish {

/**
* Arraylist of all ingredients for dish
*/
private ArrayList<String> ingredients;

/**
* Name of dish
*/
private String name;

public Dish(String name, ArrayList<String> ingredients ) {
/**
* Dish constructor
* @param name name of dish
* @param ingredients arraylist of ingredients in dish
*/
public Dish(String name, ArrayList<String> ingredients) {
this.name = name;
this.ingredients = ingredients;
}

/**
* Returns ingredients in dish
* @return arraylist of ingredients in dish
*/
public ArrayList<String> getIngredients() {
return ingredients;
}
Expand Down
40 changes: 34 additions & 6 deletions src/main/java/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,35 @@

public class Menu {

/**
* Hashmap of all dishes on menu
*/
private static HashMap<String, Dish> dishMap = new HashMap<String, Dish>();

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<String> 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<String> parseIngredients(String input) {
ArrayList<String> ingredients = new ArrayList<String>();
input = input.substring(input.indexOf("i/") + 2);
Expand All @@ -28,23 +44,35 @@ public static ArrayList<String> 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<String, Dish> getDishMap() {
return dishMap;
}
Expand Down

0 comments on commit 46269b8

Please sign in to comment.