Question
Can't get code to run. Please Help! Any help would be much appreciated! Thank you in advance! Below is the code I am trying to
Can't get code to run. Please Help! Any help would be much appreciated! Thank you in advance!
Below is the code I am trying to run but I keep getting the following error:
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */
package SteppingStones;
import java.util.Scanner; import java.util.ArrayList;
/** * * @author */
public class SteppingStone5_Recipe { private String recipeName; double totalRecipeCalories = 0.0; ArrayList recipeIngredients = new ArrayList(); boolean addMoreIngredients = true; int servings;
public String getRecipeName() { return recipeName; }
public double getTotalRecipeCalories() { return totalRecipeCalories; }
public ArrayList getRecipeIngredients() { return recipeIngredients; }
public boolean isAddMoreIngredients() { return addMoreIngredients; }
public int getServings() { return servings; }
public void setRecipeName(String recipeName) { this.recipeName = recipeName; }
public void setTotalRecipeCalories(double totalRecipeCalories) { this.totalRecipeCalories = totalRecipeCalories; }
public void setRecipeIngredients(ArrayList recipeIngredients) { this.recipeIngredients = recipeIngredients; }
public void setAddMoreIngredients(boolean addMoreIngredients) { this.addMoreIngredients = addMoreIngredients; }
public void setServings(int servings) { this.servings = servings; } public SteppingStone5_Recipe() { this.recipeName = ""; this.servings = 0; //
this.totalRecipeCalories = 0; } public SteppingStone5_Recipe(String recipeName, int servings, ArrayList recipeIngredients, double totalRecipeCalories) // system.out.println("Recipe Name" + this.recipeName); * Serves: * Ingredients: * * * ... * * * Each serving has Calories. * * HINT --> Use a for loop to iterate through the ingredients */ System.out.println("Recipe Name" + this.recipeName); System.out.println("Serves" + this.servings); System.out.println("Ingredients"); for(String m:recipeIngredients) { System.out.println(m); } System.out.println("Each serving has"+ singleServingCalories+ "Calories"); } public static void main(String[] args) { double totalRecipeCalories = 0.0; ArrayList 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(); String ingredientName ; do { System.out.println("Please enter the ingredient name or type end if you are finished entering ingredients: "); 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 (!ingredientName.equals("n")) ; SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe(recipeName,servings, recipeIngredients, totalRecipeCalories); recipe1.printRecipe(); } }
Scanner scnr - new Scanner (System.in); 112 113System.out.println ("Please enter the recipe name: " 114 115 116System.out.println ("Please enter the number of servings: ) 117//correct data type &Scanner assignment method for servings variable 118 119 120 121do 122System.out.println ("Please enter the ingredient name or type end if you are finished entering ingr 123ingredientName - scnr.next) 124 125 126 127 128 String recipeNamescnr.nextLine) int servings scnr . next!nt ( ) ; String ingredientName; if (ingredientName.toLowerCase ).equals ("end")) addMoreIngredientsfalse; else Add the ingredient name to recipeIngredients 130 131/ 132 133System.out.println ("Please enter the ingredient amount: ") 134 135 136System.out.println ("Please enter the ingredient Calories: ) 137 | | int ingredientCalories = s cnr . next Int ( ) ; 138 139 float ingredientAmount scnr.nextFloatO; steppingstone5recipe.SteppingStone5Recipe > main > do while (lingredientName .equals("n")) Output SteppingStone5_Recipe (run) X java.lang. NoClassDefFoundError ArrayList at java.lang.Class.getDeclaredMethodso (Native Method) at java.lang.Class-privateGetDeclaredMethods (Class- java:2701) at java.lang-Class-privateGetMethodRecursive (Class java:3048) at java.lang.Class.getMethodo(Class.java:3018) at java.lang.Class.getMethod (Class.java 1784) at sun.launcher.LauncherHelper.validateMainClass (LauncherHelper.java 544) at sun.launche. LauncherHelper.checkAndLoadMain (LauncherHelper-java:526) Caused by: java.lang ClassNotFoundException: ArrayList at java.net.URLClassLoader.findClass (URLClassLoader.java 382) at java.lang ClassLoader.loadclass (ClassLoader.java:424) at sun.misc.LaunchersAppClassLoader.loadclass (Launcher.java:349) at java.lang ClassLoader.loadclass (ClassLoader.java:357)
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