Skip to content

Instantly share code, notes, and snippets.

@EduardoVaca
Created July 10, 2015 22:28
Show Gist options
  • Save EduardoVaca/49d11f2dfc419ca74708 to your computer and use it in GitHub Desktop.
Save EduardoVaca/49d11f2dfc419ca74708 to your computer and use it in GitHub Desktop.
public class Ingredient{
public enum Units {ML, CUPS, SPOONS, QUARTS, GRAMS};
private String name;
private double quantity;
private Units unit;
public Ingredient(String name, double quantity, Units unit){
this.name = name;
this.quantity = quantity;
this.unit = unit;
}
public String getName(){
return name;
}
public double getQuantity(){
return quantity;
}
public Units getUnits(){
return unit;
}
}
import java.util.LinkedList;
public class Recipe{
private String name;
private LinkedList<Ingredient> ingredients;
private String instructions;
public Recipe(String name, LinkedList<Ingredient> ingredients, String instructions){
this.name = name;
this.ingredients = ingredients;
this.instructions = instructions;
}
//Constructor in case it recieves an array instead of list of ingredients
public Recipe(String name, Ingredient[] ing, String instructions){
this.name = name;
this.instructions = instructions;
ingredients = new LinkedList<Ingredient>();
for(int i = 0; i < ing.length; i++){
ingredients.add(ing[i]);
}
}
public String getName(){
return name;
}
public LinkedList<Ingredient> getIngredients(){
return ingredients;
}
public String getInstructions(){
return instructions;
}
public boolean hasIngredient(String name_ingredient){
for(Ingredient ing : ingredients){
if(ing.getName().equals(name_ingredient))
return true;
}
return false;
}
public String getStringOfIngredients(){
String sIngredients = "";
for(Ingredient ing : ingredients)
sIngredients += "- " + ing.getName() + " " + ing.getQuantity() + " " + ing.getUnits() + "\n";
return sIngredients;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment