Two Parts Final Project Need Fixed Uncommented Myrecipebox Red Squiggly Line Could Uncomme Q30001561

These two parts to my final project need fixed:

When uncommented myRecipeBox has a red squiggly line

/**
           * This couldshould be uncommented when using the
           *       public static main() method
           *
           * Comment outthis section when using the
           *       SteppingStone6_RecipeBox_tester.
                 
           if (input == 1){
                           myRecipeBox.newRecipe();
                       } else if (input == 2) {
                           System.out.println(“Which recipe?n”);
                           String selectedRecipeName = menuScnr.next();
                           myRecipeBox.printAllRecipeDetails(selectedRecipeName);
                       } else if (input == 3) {      
              for (int j = 0; j <myRecipeBox.listOfRecipes.size(); j++) {
                                   System.out.println((j + 1) + “: ” +myRecipeBox.listOfRecipes.get(j).getRecipeName());
              }
                           }else {
                               System.out.println(“nMenun” + “1. Add Recipen” + “2. PrintRecipen” + “3. Adjust Recipe Servingsn” + “nPlease select a menuitem:”);
                           }*/
            I need tofinish this as well:

Final Project Details:
For your final project submission, you should add a menu item and amethod
to access the custom method you developed for the Recipeclass
based on the Stepping Stone 5 Lab.

Here is the Recipe class code:

package recipe.collection;
import java.util.ArrayList;
import java.util.Scanner;

public class Recipe {
    private String recipeName;
    private int servings;
    privateArrayList<Ingredient>recipeIngredients;
    private double totalRecipeCalories;
  
    public Recipe() {
        this.recipeName =””;
        this.servings = 0;//<— assignment value with appropriate data type
        this.recipeIngredients =new ArrayList<Ingredient>(); //<– assignment value forempty ArrayList
        this.totalRecipeCalories= 0;
    }
    public static void main(String[] args){
        Recipe r =createNewRecipe();//constructor to create new recipe
       r.printRecipe();//Accessor for the printRecipe() method
      
    }
    //accessor that retrieves the recipe name
    public String getRecipeName() {
        return recipeName;
    }
    //mutator that sets the recipe name
    public void setRecipeName(StringrecipeName){
        this.recipeName =recipeName;
    }
    //accessor to retrieve the serving size
    public int getServing() {
        return servings;
    }
    //mutator to set the serving size
    public void setServing(int serving) {
        this.servings =serving;
    }
    // calls the Array that holds the recipeingredients
    public ArrayList<Ingredient>getRecipeIngredients() {
        returnrecipeIngredients;
    }
    //sets the ingredients held by the array
    public voidsetRecipeIngredients(ArrayList<Ingredient>recipeIngredients){
        this.recipeIngredients =recipeIngredients;
    }
    //accessor that calls the total recipecalories
    public double getTotalRecipeCalories(){
        returntotalRecipeCalories;
    }
    //mutator that sets the total recipecalories
    public void setTotalRecipeCalories(doubletotalRecipeCalories){
        this.totalRecipeCalories= totalRecipeCalories;
    }
    //Recipe class
    public Recipe(String recipeName, intservings,
    ArrayList<Ingredient> recipeIngredients,double totalRecipeCalories)
    //<– use appropriate data type for theArrayList and the servings arguments
    {
        this.recipeName =recipeName;
        this.servings =servings;
        this.recipeIngredients =recipeIngredients;
        this.totalRecipeCalories= totalRecipeCalories;
    }

    public void printRecipe() {
       //printRecipeWithDifferentServings(servings);
         doublesingleServingCalories = totalRecipeCalories / servings;
       System.out.println(“Recipe: ” + getRecipeName());
       System.out.println(“Yield: ” + getServing() + ” servings”);
       System.out.println(“Ingredients:”);
        for (int i = 0; i <recipeIngredients.size(); i++) {
           Ingredient currentIngredient = recipeIngredients.get(i);
           String currentIngredientName =currentIngredient.getNameOfIngredient();
           System.out.println(currentIngredientName);
        }
        System.out.print(“.Eachserving has ” + singleServingCalories + ” calories”);
    }
    //CUSTOM METHOD
    public static Recipe createNewRecipe(){
        doubletotalRecipeCalories = 0;
        ArrayList<Ingredient> recipeIngredients = new ArrayList();
        booleanaddMoreIngredients = true;
        String reply=””;
        Scanner scnr = newScanner(System.in);
       System.out.println(“Please enter the recipe name: “);
        String recipeName =scnr.nextLine();
       System.out.println(“Please enter the number of servings: “);
       @SuppressWarnings(“LocalVariableHidesMemberVariable”)
        int servings =scnr.nextInt();

        do {
           System.out.println(“Please enter the ingredient name or type end ifyou are finished entering ingredients: “);
           String ingredientName = scnr.next();
           if (ingredientName.toLowerCase().equals(“end”)) {
           addMoreIngredients = false;
           } else {
               Ingredient tempIngredient = new Ingredient().addIngredient();
               recipeIngredients.add(tempIngredient);
               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;
    }
}

Here is the collection box code:

/*
* To change this license header, choose License Headers in ProjectProperties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package recipe.collection;

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

public class RecipeBox {
  
    private ArrayList<Recipe>listOfRecipes;
   //Accessor Recipe Array
          publicArrayList<Recipe> getListOfRecipes(){
           return listOfRecipes;
          }
          //Mutatorfor Array List
          public voidsetListOfRecipes(ArrayList<Recipe> listOfRecipes){
            this.listOfRecipes = listOfRecipes;
          }
        //Constructor for recipebox
   void RecipeBox(){
           listOfRecipes = new ArrayList<Recipe>();
        }
        voidRecipeBox(ArrayList<Recipe> listOfRecipes)
        {
           this.listOfRecipes=listOfRecipes;
        }
      
        public voidprintAllRecipeDetails(String selectedRecipe)
        {
           for (int i = 0; i < listOfRecipes.size(); i++)
           { // traverse ArrayList
               // fetches the element at i position and compare its name with theaargument string
               if(listOfRecipes.get(i).getRecipeName().equals(selectedRecipe))
               {
                   listOfRecipes.get(i).printRecipe(); // if matches then printsRecipes detail
               }
           }  
        }
        public voidprintAllRecipeNames()
        {
           System.out.println(“List of Recipes are : “);
           for (int i = 0; i < listOfRecipes.size(); i++){
               System.out.println(listOfRecipes.get(i).getRecipeName()); // justprints Recipe names
           }
        }
        void addRecipe()
        {
           Recipe r= new Recipe();
           Recipe tmpRecipe = r.createNewRecipe(); // creates new Recipe
           listOfRecipes.add(tmpRecipe); // adds it to the ArrayList
        }
      
        public void menu(){
       // Create a Recipe Box
           Scanner menuScnr = new Scanner(System.in);
           System.out.println(“Menun” + “1. Add Recipen” + “2. Print AllRecipe Detailsn” + “3. Print All Recipe Namesn” + “nPleaseselect a menu item:”);
           while (menuScnr.hasNextInt() || menuScnr.hasNextLine()){
               System.out.println(“Menun” + “1. Add Recipen” + “2. Print AllRecipe Detailsn” + “3. Print All Recipe Namesn” + “nPleaseselect a menu item:”);
               int input = menuScnr.nextInt();
               if (input == 1) {
                   addRecipe();
               } else if (input == 2) {
                   System.out.println(“Which recipe?n”);
                   String selectedRecipeName = menuScnr.next();
                   printAllRecipeDetails(selectedRecipeName);
               } else if (input == 3) {
                   for (int j = 0; j < listOfRecipes.size(); j++) {
                       System.out.println((j + 1) + “: ” +listOfRecipes.get(j).getRecipeName());
                   }
               } else {
                   System.out.println(“nMenun” + “1. Add Recipen” + “2. PrintRecipen” + “3. Adjust Recipe Servingsn” + “nPlease select a menuitem:”);
               }
               }
          
          
          
           /**
           * This couldshould be uncommented when using the
           *       public static main() method
           *
           * Comment outthis section when using the
           *       SteppingStone6_RecipeBox_tester.
                 
           if (input == 1){
                           myRecipeBox.newRecipe();
                       } else if (input == 2) {
                           System.out.println(“Which recipe?n”);
                           String selectedRecipeName = menuScnr.next();
                           myRecipeBox.printAllRecipeDetails(selectedRecipeName);
                       } else if (input == 3) {      
              for (int j = 0; j <myRecipeBox.listOfRecipes.size(); j++) {
                                   System.out.println((j + 1) + “: ” +myRecipeBox.listOfRecipes.get(j).getRecipeName());
              }
                           }else {
                               System.out.println(“nMenun” + “1. Add Recipen” + “2. PrintRecipen” + “3. Adjust Recipe Servingsn” + “nPlease select a menuitem:”);
                           }*/
          
   }
      
    }

“We Offer Paper Writing Services on all Disciplines, Make an Order Now and we will be Glad to Help”

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published.