Question: Hello guys, Please run the following JAVA file and please explain why is not running proper. I have attached both codes required- please help: package

Hello guys,

Please run the following JAVA file and please explain why is not running proper. I have attached both codes required- please help:

package steppingstone_labs;

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

public class SteppingStone6_RecipeBox { private ArrayList listOfRecipes = new ArrayList(); * @param listOfRecipes public void setListOfRecipes(ArrayList listOfRecipes){ this.listOfRecipes = listOfRecipes; } public ArrayList getlistOfRecipes(){ return listOfRecipes; } public void SteppingStone6_Recipe(){ this.listOfRecipes = new ArrayList<>(); } public void SteppingStone6_RecipeBox(ArrayList listOfRecipes){ this.listOfRecipes = listOfRecipes; } public void printAllRecipeDetails(){ SteppingStone5_Recipe tmpRecipe = new SteppingStone5_Recipe(); int i = 0; for (i = 0; i< listOfRecipes.size(); i++){ tmpRecipe.printRecipe(); } } public void printAllRecipeNames(){ int i = 0; for (i=0; i < listOfRecipes.size(); i++){ System.out.println(listOfRecipes.get(i)); } } public void addNewRecipe(){ SteppingStone5_Recipe tmpRecipe2 = new SteppingStone5_Recipe(); tmpRecipe2.addNewRecipe(); } public void menu() { // Creation of a Recipe Box //SteppingStone6_RecipeBox myRecipeBox = new SteppingStone6_RecipeBox(); //Uncomment for main method Scanner menuScnr = new Scanner(System.in); System.out.println("Menu " + "1. Add Recipe " + "2. Print All Recipe Details " + "3. Print All Recipe Names " + " Please select a menu item:"); while (menuScnr.hasNextInt() || menuScnr.hasNextLine()) { System.out.println("Menu " + "1. Add Recipe " + "2. Print All Recipe Details " + "3. Print All Recipe Names " + " Please select a menu item:"); int input = menuScnr.nextInt(); switch (input) { case 1: addNewRecipe(); break; case 2: System.out.println("Which recipe? "); String selectedRecipeName = menuScnr.next(); printAllRecipeDetails(selectedRecipeName); break; case 3: for (int j = 0; j < listOfRecipes.size(); j++) { System.out.println((j + 1) + ": " + listOfRecipes.get(j).getRecipeName()); } break; default: System.out.println(" Menu " + "1. Add Recipe " + "2. Print Recipe " + "3. Adjust Recipe Servings " + " Please select a menu item:"); break; } System.out.println("Menu " + "1. Add Recipe " + "2. Print All Recipe Details " + "3. Print All Recipe Names " + " Please select a menu item:"); } }

private String getRecipeName() { throw new UnsupportedOperationException("Not supported yet."); }

private void printAllRecipeDetails(String selectedRecipeName) { throw new UnsupportedOperationException("Not supported yet."); }

}

SECOND JAVA FILE CALLED IN THE ONE ABOVE:

SteppingStone5_Recipe:

package steppingstone_labs;

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

public class SteppingStone5_Recipe { private String recipeName; private int servings; ArrayList recipeIngredients = new ArrayList(); private int totalRecipeCalories; public void setRecipeName(String recipeName){ this.recipeName = recipeName; } public String getRecipeName(){ return recipeName; } public void setServings(int servings){ this.servings = servings; } public int getServings(){ return servings; } public void setRecipeIngredients(ArrayList recipeIngredients){ this.recipeIngredients = recipeIngredients; } public ArrayList getRecipeIngredients(){ return recipeIngredients; } public void setTotalRecipeCalories(int totalRecipeCalories){ this.totalRecipeCalories = totalRecipeCalories; } public int getTotalRecipeCalories(){ return totalRecipeCalories; } //constructor public SteppingStone5_Recipe() { this.recipeName = ""; this.servings = 0; this.recipeIngredients = new ArrayList<>(); this.totalRecipeCalories = 0; } public SteppingStone5_Recipe(String recipeName, int servings, ArrayList recipeIngredients, double totalRecipeCalories) { this.recipeName = recipeName; this.servings = servings; this.recipeIngredients = recipeIngredients; this.totalRecipeCalories = (int) totalRecipeCalories; } public void printRecipe() { int singleServingCalories = (totalRecipeCalories / servings); System.out.println("Recipe: " + recipeName); System.out.println("Serves: " + servings); System.out.println("Ingredients: "); for (int i = 0; i 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 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; break; } else { recipeIngredients.add(ingredientName); addMoreIngredients = true; 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 = (int) (ingredientCalories * ingredientAmount); } } while (addMoreIngredients == true) ; SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe(recipeName, servings, recipeIngredients, totalRecipeCalories); recipe1.printRecipe(); }

void addNewRecipe() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!