Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need some help!! public class SteppingStone5_Recipe { private String recipeNam

ID: 3876069 • Letter: I

Question

I need some help!!

public class SteppingStone5_Recipe {

  

private String recipeName;

  

/**

* Add three variables:

*

* 1. a variable 'servings' to store how many people the recipe will feed;

*

* 2. an ArrayList variable 'recipeIngredients' to store the text for the

* names (recipeName) each recipe ingredient added

*

* 3. a variable totalRecipeCalories

*

*/

  

  

/**

* Add mutators and accessors for the class variable.

*

*/

  

public SteppingStone5_Recipe() {

this.recipeName = "";

this.servings = ??? //<--- assignment value with appropriate data type

this.recipeIngredients = ???; //<-- assignment value for empty ArrayList

this.totalRecipeCalories = 0;

  

}

public SteppingStone5_Recipe(String recipeName, ??? servings,

ArrayList<????> recipeIngredients, double totalRecipeCalories)

//<-- use appropriate data type for the ArrayList and the servings arguments

{

this.recipeName = recipeName;

this.servings = servings;

this.recipeIngredients = recipeIngredients

this.totalRecipeCalories = totalRecipeCalories;

}

  

public void printRecipe() {

/**

* Declare an int variable singleServingCalories.

* Assign singleServingCalories to

* the totalRecipeCalories divided by the servings

*

*/

/**

* Print the following recipe information:

* Recipe: <<recipeName>>

* Serves: <<servings>>

* Ingredients:

* <<Ingredient1>>

* <<Ingredient2>>

* ...

* <<Last Ingredient>>

*   

* Each serving has <<singleServingCalories>> Calories.

*

* HINT --> Use a for loop to iterate through the ingredients

*/

}

  

  

public static void main(String[] args) {

??? totalRecipeCalories = ???;

ArrayList <String> recipeIngredients = new ArrayList();

boolean addMoreIngredients = true;

  

Scanner scnr = new Scanner(System.in);

  

System.out.println("Please enter the recipe name: ");

String recipeName = scnr.nextLine();

  

System.out.println("Please enter the number of servings: ");

//correct data type & Scanner assignment method for servings variable

???? servings = ????

  

  

do {

System.out.println("Please enter the ingredient name

or type end if you are finished entering ingredients: ");

String ingredientName = scnr.next();

if (ingredientName.toLowerCase().equals("end")) {

addMoreIngredients = false;

} else {

/**

* Add the ingredient name to recipeIngredients

*

*/

  

System.out.println("Please enter the ingredient amount: ");

float ingredientAmount = scnr.nextFloat();

  

System.out.println("Please enter the ingredient Calories: ");

int ingredientCalories = scnr.nextInt();

  

/**

* Add the total Calories from this ingredient

* (ingredientCalories * ingredientAmount)

* to the totalRecipeCalories

*

*/

  

}

} while (!reply.equals("n") ;

  

SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe(recipeName,

servings, recipeIngredients, totalRecipeCalories);

recipe1.printRecipe();

}

}

/**

* Final Project

*

* For your Final Project:

*

* 1. Modify this code to develop a Recipe class:

* a. change the void main method createNewRecipe() that returns a Recipe

*

* 2. FOR FINAL SUBMISSION ONLY:Change the ArrayList type to an

* Ingredient object. When a user adds an ingredient to the recipe,

* instead of adding just the ingredient name, you will be adding the

* actual ingredient including name, amount, measurement type, calories.

* For the Milestone Two submission, the recipeIngredients ArrayList can

* remain as a String type.

*

* 3. Adapt the printRecipe() method to print the amount and measurement

* type as well as the ingredient name.

*

* 4. Create a custom method in the Recipe class.

* Choose one of the following options:

*

* a. print out a recipe with amounts adjusted for a different

* number of servings

*

* b. create an additional list or ArrayList that allow users to

* insert step-by-step recipe instructions

*

* c. conversion of ingredient amounts from

* English to metric (or vice versa)

*

* d. calculate select nutritional information

*

* e. calculate recipe cost

*

* f. propose a suitable alternative to your instructor

*

*/

Explanation / Answer

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<Ingredient> recipeIngredients;

   private ArrayList<String> instructions;

   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<Ingredient> getIngredientList() {

       return recipeIngredients;

   }

  

   //set IngredientList

   public void setIngredientList(ArrayList<Ingredient> recipeIngredients) {

       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<Recipe> recipes;

   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();

   }

}