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

In your final project, you will create a program that will help you manage a col

ID: 3903828 • Letter: I

Question

In your final project, you will create a program that will help you manage a collection of recipes. The Recipe class you build for this milestone will hold all the details of the recipe, the methods to create a new recipe, and a method to print a recipe. In your final project submission, this class will also contain a custom method to add a new feature. In your submission for Milestone Two, you will include commented out pseudocode for this method. In this milestone, you submit the final project version of your Recipe class. Your submission should include the Recipe.java file and a Recipe_Test.java file. Your Recipe class should include the following items: Instance variables: recipeName, servings, recipeIngredients, and totalRecipeCalories Accessors and mutators for the instance variables Constructors A printRecipe() method A createNewRecipe() method to build a recipe from user input Pseudocode for the custom method selected from the list in Stepping Stone Lab Five Your Recipe_Test.java file containing a main() method that: Uses a constructor to create a new recipe Accesses the printRecipe() method to print the formatted recipe Invokes the createNewRecipe() method to accept user input. Specifics Here is the code so far that I've done for the Recipe Class. I'm getting red squiggly lines in a couple spots.

package recipe.collection;

import java.util.ArrayList;
import java.util.Scanner;

public class Recipe {
    private String recipeName;
    private int serving;
    private ArrayList<String>recipeIngredients;
    private double totalRecipeCalories;

   public void main(String[] args){
        Recipe r = createNewRecipe();
        r.printRecipe();
   }
   public Recipe() {
        this.recipeName = "";
        this.serving = 0; //<--- assignment value with appropriate data type
        this.recipeIngredients = new ArrayList<String>(); //<-- assignment value for empty ArrayList
        this.totalRecipeCalories = 0;
   }
   //accessor that retrieves the recipe name
    public String getRecipeName() {
        return recipeName;
    }
    //mutator that sets the recipe name
    public void setRecipeName(String recipeName){
        this.recipeName = recipeName;
    }
    //accessor to retrieve the serving size
    public int getServing() {
        return serving;
    }
    //mutator to set the serving size
    public void setServing(int serving) {
        this.serving = serving;
    }
    // calls the Array that holds the recipe ingredients
    public ArrayList<String> getRecipeIngredients() {
        return recipeIngredients;
    }
    //sets the ingredients held by the array
    public void setRecipeIngredients(ArrayList<String> recipeIngredients){
        this.recipeIngredients = recipeIngredients;
    }
    //accessor that calls the total recipe calories
    public double getTotalRecipeCalories(){
        return totalRecipeCalories;
    }
    //mutator that sets the total recipe calories
    public void setTotalRecipeCalories(double totalRecipeCalories){
        this.totalRecipeCalories = totalRecipeCalories;
    }
    //Recipe class
    public Recipe(String recipeName, int servings,
       ArrayList<String> recipeIngredients, double totalRecipeCalories)
    //<-- use appropriate data type for the ArrayList and the servings arguments
    {
        this.recipeName = recipeName;
        this.serving = serving;
        this.recipeIngredients = recipeIngredients;
        this.totalRecipeCalories = totalRecipeCalories;
    }
  
    public void printRecipe() {
        int singleServingCalories = (int) totalRecipeCalories / serving;
        System.out.println("Recipe:" + recipeName + " Serves: " + serving + " Ingredients: ");
      
        for (int i = 0; i < recipeIngredients.size(); i++) {
            System.out.print(recipeIngredients.get(i).getRecipeName() + " ");
            System.out.print(recipeIngredients.get(i).getServing() + " ");
            System.out.print(recipeIngredients.get(i).getTotalRecipeCalories());
        }
        System.out.print(".Each serving has " + singleServingCalories + " calories");
    }
    Recipe createNewRecipe(){
        double totalRecipeCalories = 0;
        ArrayList <String> recipeIngredients = new ArrayList();
        boolean addMoreIngredients = true;
        String reply="";
        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: ");
        int servings = scnr.nextInt();
      
        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 {
                recipeIngredients.add(ingredientName);
                System.out.println("Please enter the ingredient amount: ");
                float ingredientAmount = scnr.nextFloat();
                System.out.println("Please enter the ingredient Calories: ");
                int ingredientCalories = scnr.nextInt();
                totalRecipeCalories = ingredientCalories * ingredientAmount;
                System.out.println("Do you want to continue. Y/N");
                reply = scnr.nextLine();
            }
        } while (!reply.equals("n")) ;
        scnr.close();
        Recipe recipe1 = new Recipe(recipeName, servings, recipeIngredients, totalRecipeCalories);
        return recipe1;
    }
    public void printRecipeWithDifferentServings(int n){
       int singleServingCalories = (int) totalRecipeCalories / serving;
       for (int i = 0; i < recipeIngredients.size(); i++) {
            float diffamount = recipeIngredients.get(i).getServing()*((float)n/(float)serving);
            System.out.print(recipeIngredients.get(i).getRecipeName() + " ");
            System.out.print(diffamount + " ");
            System.out.println(recipeIngredients.get(i).getTotalRecipeCalories());
       }
       System.out.print(".Each serving has " + singleServingCalories + " calories");
}
  
}
/**
* 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
*
*/


For problem 4 I've chosen solution A.

public void printRecipe) int singleServingCalories = (int) totalRecipeCal ories / serving; Syeres.out.priatia( Recige eetpelane " Servess - "zin. Ingredients;, ",; for (int ? 0; í ? recipeIngredients.size(); ?++) { System.out.print (recipeIngredients.get (i) .getRecipeNam+ "") System.out.print (recipeIngredients.get (i) .getServing) + ) System.out.print (recipeIngredients.get (i) .getTotalRecipeCalories)) System.out.print (".Each serving has "singleServingCalories"calories") Recipe createNewRecipe)

Explanation / Answer


Given below is the fixed code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i

package recipe.collection;

import java.util.ArrayList;
import java.util.Scanner;

public class Recipe {
private String recipeName;
private int serving;
private ArrayList<String>recipeIngredients;
private double totalRecipeCalories;

public void main(String[] args){
Recipe r = createNewRecipe();
r.printRecipe();
}
public Recipe() {
this.recipeName = "";
this.serving = 0; //<--- assignment value with appropriate data type
this.recipeIngredients = new ArrayList<String>(); //<-- assignment value for empty ArrayList
this.totalRecipeCalories = 0;
}
//accessor that retrieves the recipe name
public String getRecipeName() {
return recipeName;
}
//mutator that sets the recipe name
public void setRecipeName(String recipeName){
this.recipeName = recipeName;
}
//accessor to retrieve the serving size
public int getServing() {
return serving;
}
//mutator to set the serving size
public void setServing(int serving) {
this.serving = serving;
}
// calls the Array that holds the recipe ingredients
public ArrayList<String> getRecipeIngredients() {
return recipeIngredients;
}
//sets the ingredients held by the array
public void setRecipeIngredients(ArrayList<String> recipeIngredients){
this.recipeIngredients = recipeIngredients;
}
//accessor that calls the total recipe calories
public double getTotalRecipeCalories(){
return totalRecipeCalories;
}
//mutator that sets the total recipe calories
public void setTotalRecipeCalories(double totalRecipeCalories){
this.totalRecipeCalories = totalRecipeCalories;
}
//Recipe class
public Recipe(String recipeName, int servings,
ArrayList<String> recipeIngredients, double totalRecipeCalories)
//<-- use appropriate data type for the ArrayList and the servings arguments
{
this.recipeName = recipeName;
this.serving = servings;
this.recipeIngredients = recipeIngredients;
this.totalRecipeCalories = totalRecipeCalories;
}

public void printRecipe() {
printRecipeWithDifferentServings(serving);
}

Recipe createNewRecipe(){
double totalRecipeCalories = 0;
ArrayList <String> recipeIngredients = new ArrayList();
boolean addMoreIngredients = true;
String reply="";
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: ");
int servings = scnr.nextInt();

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 {
recipeIngredients.add(ingredientName);
System.out.println("Please enter the ingredient amount: ");
float ingredientAmount = scnr.nextFloat();
System.out.println("Please enter the ingredient Calories: ");
int ingredientCalories = scnr.nextInt();
totalRecipeCalories = ingredientCalories * ingredientAmount;
System.out.println("Do you want to continue. Y/N");
reply = scnr.nextLine();
}
} while (!reply.equals("n")) ;
scnr.close();
Recipe recipe1 = new Recipe(recipeName, servings, recipeIngredients, totalRecipeCalories);
return recipe1;
}
public void printRecipeWithDifferentServings(int n){
int singleServingCalories = (int) totalRecipeCalories / n;
System.out.print("Recipe:" + recipeName + " Serves: " + serving + " Ingredients: ");

for (int i = 0; i < recipeIngredients.size(); i++) {
System.out.print(recipeIngredients.get(i) + " ");

}
System.out.println(". Each serving has " + singleServingCalories + " calories");

}

}
/**
* 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
*
*/