Created
July 10, 2015 22:28
-
-
Save EduardoVaca/49d11f2dfc419ca74708 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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