来自Ingredients HashMaps的食谱

时间:2017-02-11 03:06:41

标签: java hashmap recipe

我的大学项目存在很大问题。

我必须编写Coffe Machine的简单API。

我有HashMap的类成分(名​​称和值) 我想创建类Recipe,同时使用HashMap和Name和Ingredients。如何合并这些HashMaps?

这是我的代码:

public class Ingredient {

Scanner scan = new Scanner(System.in);


public HashMap<String, Integer> Ingredients = new HashMap<String, Integer>();

private String Name;
private int Value;

public void addIngredient(){
    Ingredients.put(scan.nextLine(), scan.nextInt());
}

Ingredient(String Name, int Value){
    this.Name = Name;
    this.Value = Value;
   }
}



public class Recipe{

private String name;
private Ingredient ingredient;

public HashMap<String, Ingredient> Drink = new HashMap<String, Ingredient>();

Recipe(String name, Ingredient ingredient){
    this.name = name;
    this.ingredient = ingredient;
  }
}

例如,我想添加成分,咖啡,牛奶,水,糖。 然后我想和这些igredients一起喝酒

0 个答案:

没有答案