Question
Your Recipe class should include the following items: 1.Instance variables: recipeName, servings, recipeIngredients, and totalRecipeCalories 2.Accessors and mutators for the instance variables 3.Constructors 4. printRecipe()
Your Recipe class should include the following items:
1.Instance variables: recipeName, servings, recipeIngredients, and totalRecipeCalories
2.Accessors and mutators for the instance variables
3.Constructors
4. printRecipe() method
5 createNewRecipe() method to build a recipe from user input
6.Pseudocode for the custom method selected from the list in Stepping Stone Lab Five
Your Recipe_Test.java file containing a main() method that:
1. Uses a constructor to create a new recipe
2.Accesses the printRecipe() method to print the formatted recipe
3.Invokes the createNewRecipe() method to accept user inpu
Specifically, the following critical elements of the final project are addressed:
I. Data Types: Your Recipe class should properly employ each of the following data types that meet the scenarios requirements where necessary:
A. Utilize appropriate numerical and string data types to represent values for variables and attributes in your program.
B. Populate a list or array that allows the management of a set of values as a single unit in your program.
II. Algorithms and Control Structure: Your Recipe class should properly employ each of the following control structures as required or defined by the scenario where necessary:
A. Utilize expressions or statements that carry out appropriate actions or that make appropriate changes to your programs state as represented in your programs variables.
B. Employ the appropriate conditional control structures that enable choosing between options in your program.
C. Utilize iterative control structures that repeat actions as needed to achieve the programs goal.
III. Methods: Your Recipe class should properly employ each of the following aspects of method definition as determined by the scenarios requirements where necessary:
A. Use formal parameters that provide local variables in a functions definition.
B. Use actual parameters that send data as arguments in function calls.
C. Create both value-returning and void functions to be parts of expressions or stand-alone statements in your program.
D. Invoke methods that access the services provided by an object.
E. Describe a user-defined method that provides custom services for an object.
F. Create unit tests that ensure validity of the methods.
IV. Classes: Construct classes for your program that include the following as required by the scenario where necessary:
A. Include attributes that allow for encapsulation and information hiding in your program.
B. Include appropriate methods that provide an objects behaviors.
V. Documentation: Utilize inline comments directed toward software engineers for the ongoing maintenance of your program that explain the decisions you made in the construction of the classes in your program.
Stepping Stone five Recipe
import java.util.ArrayList;
/**
* Ingredient class :
* items that will be stored in each recipe
*
*/
public class Ingredient {
//variables
private String ingredientName;
private double ingredientAmount;
private String unitMeasurement;
private double totalCalories;
public Ingredient() {
}
//constructor
public Ingredient(String ingredientName, double ingredientAmount, String unitMeasurement, double totalCalories) {
super();
this.ingredientName = ingredientName;
this.ingredientAmount = ingredientAmount;
this.unitMeasurement = unitMeasurement;
this.totalCalories = totalCalories;
}
//Seter and getter
public String getIngredientName() {
return ingredientName;
}
public void setIngredientName(String ingredientName) {
this.ingredientName = ingredientName;
}
public double getIngredientAmount() {
return ingredientAmount;
}
public void setIngredientAmount(double ingredientAmount) {
this.ingredientAmount = ingredientAmount;
}
public String getUnitMeasurement() {
return unitMeasurement;
}
public void setUnitMeasurement(String unitMeasurement) {
this.unitMeasurement = unitMeasurement;
}
public double getTotalCalories() {
return totalCalories;
}
public void setTotalCalories(double totalCalories) {
this.totalCalories = totalCalories;
}
//print item detail
public void printItemDetails() {
System.out.println("ingredientName " + this.ingredientName);
System.out.println("ingredientAmount " + this.ingredientAmount);
System.out.println("totalCalories " + this.totalCalories);
System.out.println("unitMeasurement " + this.unitMeasurement);
}
}
import java.util.ArrayList;
/**
* Recipe class :
* create one recipe
*
*/
public class Recipe {
//variables
private ArrayList
private ArrayList
private String recipeName;
private int servings;
private double totalRecipeCalories;
//constructor
public Recipe(String recipeName,int servings) {
this.recipeName = recipeName;
this.recipeIngredients = new ArrayList<>();
this.instructions = new ArrayList<>();
this.servings = servings;
this.totalRecipeCalories = 0;
}
//get IngredientList
public ArrayList
return recipeIngredients;
}
//set IngredientList
public void setIngredientList(ArrayList
this.recipeIngredients = recipeIngredients;
}
/**
* @return the recipeName
*/
public String getRecipeName() {
return recipeName;
}
/**
* @param recipeName the recipeName to set
*/
public void setRecipeName(String recipeName) {
this.recipeName = recipeName;
}
/**
* @return the servings
*/
public int getServings() {
return servings;
}
/**
* @param servings the servings to set
*/
public void setServings(int servings) {
this.servings = servings;
}
/**
* @return the totalRecipeCalories
*/
public double getTotalRecipeCalories() {
return totalRecipeCalories;
}
/**
* @param totalRecipeCalories the totalRecipeCalories to set
*/
public void setTotalRecipeCalories(double totalRecipeCalories) {
this.totalRecipeCalories = totalRecipeCalories;
}
// add Ingredient in recipe
public boolean addIngredient(Ingredient ingredient){
this.totalRecipeCalories = this.totalRecipeCalories + ingredient.getTotalCalories();
return this.recipeIngredients.add(ingredient);
}
// remove Ingredient in recipe
public boolean removeIngredient(Ingredient ingredient){
if (this.recipeIngredients.remove(ingredient)){
this.totalRecipeCalories = this.totalRecipeCalories - ingredient.getTotalCalories();
return true;
}
else
return false;
}
// remove all Ingredient in recipe
public boolean removeAllIngredient(){
return this.recipeIngredients.removeAll(recipeIngredients);
}
// print Ingredients in recipe
public void printRecipe(){
int singleServingCalories = (int) (totalRecipeCalories/servings);
System.out.println("Recipe: " + recipeName);
System.out.println("Serves: " + servings);
System.out.println("Ingredients:");
for(Ingredient ingredient: recipeIngredients) {
ingredient.printItemDetails();
}
System.out.println("Each serving has " + singleServingCalories + " Calories.");
}
//create new recipe
public static Recipe createNewRecipe(String recipeName,int servings){
return new Recipe(recipeName,servings);
}
//insert instruction
public boolean insertInstruction(String instruction){
return this.instructions.add(instruction);
}
public void printInstruction(){
instructions.toString();
}
}
mport java.util.ArrayList;
/**
* SteppingStone5_Recipe_Test class :
* collection of recipe
*
*/
public class SteppingStone5_Recipe_Test {
private ArrayList
public SteppingStone5_Recipe_Test() {
this.recipes = new ArrayList<>();
}
//add a Recipe in collection
public void addItem(Recipe recipe){
recipes.add(recipe);
}
//delete a Recipe in collection
public void deleteItem(Recipe recipe){
recipes.remove(recipe);
}
//print all recipes
public void printAllRecipies(){
int i = 0;
for(Recipe rec: recipes){
i++;
System.out.println("Recipe " + i);
rec.printRecipe();
}
}
public static void main(String[] args) {
//create some demo recipes
Recipe recipe1 = Recipe.createNewRecipe("Pizza", 4);
Ingredient ingredient1 = new Ingredient("Anchovies",20,"gram",300);
recipe1.addIngredient(ingredient1);
Recipe recipe2 = Recipe.createNewRecipe("Ramen", 2);
Ingredient ingredient2 = new Ingredient("Noodles",50,"gram",200);
recipe2.addIngredient(ingredient2);
// add in box
SteppingStone5_Recipe_Test box = new SteppingStone5_Recipe_Test();
box.addItem(recipe1);
box.addItem(recipe2);
box.printAllRecipies();
}
}
Stepping Stone Recipe Test
public class SteppingStone5_RecipeTest {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// Create two recipe objects first
SteppingStone5_Recipe myFirstRecipe = new SteppingStone5_Recipe();
ArrayList
ArrayList
String ingredientName = "Anchovies";
Ingredient tempIngredient = new Ingredient().addNewIngredient(ingredientName);
recipeIngredients.add(tempIngredient);
SteppingStone5_Recipe mySecondRecipe = new SteppingStone5_Recipe("Pizza", 2, recipeIngredients, 300);
// Initialize first recipe
String ingredientNameTwo = "Noodles";
Ingredient tempIngredientTwo = new Ingredient().addNewIngredient(ingredientNameTwo);
recipeIngredientsTwo.add(tempIngredientTwo);
myFirstRecipe.setRecipeName("Ramen");
myFirstRecipe.setServings(2);
myFirstRecipe.setRecipeIngredients(recipeIngredientsTwo);
myFirstRecipe.setTotalRecipeCalories(150);
// Print details of both recipes
myFirstRecipe.printRecipe();
mySecondRecipe.printRecipe();
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started