Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm developing a class in java, but can't get it to run. Please Help! I need to build a custom class. The instructions say to

I'm developing a class in java, but can't get it to run. Please Help!

I need to build a custom class. The instructions say to replace the main method public static void main(String[] args) with public SteppingStone5_Recipe createNewRecipe(). But every time I delete that portion and replace with my class the IDE says class definition found. But if I add my below code under main, it says that I have an illegal start of expression. I assume that I am not starting the class correctly (every other project I have done is just code entered under main. I have no idea how to get this code to run.

This is the prompt:

Prompt: In this stepping stone lab assignment, you will build a Recipe class, getting user input to collect the recipe name and serving size, using the ingredient entry code from Stepping Stone Lab Four to add ingredients to the recipe, and calculating the calories per serving. Additionally, you will build your first custom method to print the recipe to the screen.

This is when I try to run with main:

image text in transcribed

This is what I get when I replace main as the instructions tell me to:

image text in transcribed

Or when I replace main I get this:

image text in transcribed

And this is the code that I have wrote for the recipe in txt. But when I go to copy into the IDE I get the above errors:

// import statements

import java.util.Scanner;

import java.util.ArrayList;

// Create a class named 'SteppingStone5_Recipe'

public class SteppingStone5_Recipe

{

// Declare the variables

private String recipeName;

private double totalRecipeCalories;

private ArrayList recipeIngredients;

private int servings;

// Create a default constructor.

public SteppingStone5_Recipe()

{

this.recipeName = "";

this.servings = 0;

this.recipeIngredients = new ArrayList();

this.totalRecipeCalories = 0;

}

// Create a parameter constructor

public SteppingStone5_Recipe(String recipeName, int servings,

ArrayList recipeIngredients, double totalRecipeCalories)

{

this.recipeName = recipeName;

this.servings = servings;

this.recipeIngredients = recipeIngredients;

this.totalRecipeCalories = totalRecipeCalories;

}

// Create an accessor.

public String getRecipeName()

{

return recipeName;

}

// Create a mutator.

public void setRecipeName(String recipeName)

{

this.recipeName = recipeName;

}

// Create an accessor for total recipe calories

public double getTotalRecipeCalories()

{

return totalRecipeCalories;

}

// Create a mutator method for total recipe calories

public void setTotalRecipeCalories(double totalRecipeCalories)

{

this.totalRecipeCalories = totalRecipeCalories;

}

public ArrayList getRecipeIngredients()

{

return recipeIngredients;

}

public void setRecipeIngredients(ArrayList recipeIngredients)

{

this.recipeIngredients = recipeIngredients;

}

public int getServings()

{

return servings;

}

public void setServings(int servings)

{

this.servings = servings;

}

// Create a method named 'printRecipe'

public void printRecipe()

{

int singleServingCalories = (int)(totalRecipeCalories / servings);

System.out.println("Recipe: " + recipeName);

System.out.println("Serves: " + servings);

System.out.println("Ingredients:");

for (String ingredient : recipeIngredients)

{

System.out.println(ingredient);

}

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

}

}

run.xml xla steppingStone6Recipe.java x Source History To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools I Templates and open the template in the editor package steppingstone6 recipe,: import java.util.Scanner: import java.util.ArrayList; 10/ 12 13 @author public class SteppingStone6 Recipe 16 17 private String recipeName; private double totalRecipeCalories: private ArrayList recipe Ingredients; private int servings: 21 public static void main (String [] args) ublic SteppingStone5 Reci 27 this.recipeName ""; this.servings0 steppingstoneb_recipe.SteppingStone6_Recipe > D main > Output SteppingStone6_Recipe (run) X Exception in thread "main" java.lang. RuntieException: Uncompilable source code-illegal start of expression steppingstoneczcipe. Steppingstonet Receipe zsns at steppingstone6_recipe.SteppingStone_Recipe main (SteppingStone6 Recipe. java:23) C:NUsers\Timothy AppData\Local\NetBeans Cache\8.2 executor-snippets un.xml: 53 Java returned: 1 BUILD FAILED (total time: 1 second) run.xml XSteppingStone6_Recipe.java X * change this license header, choose License Headers in Project Properties. * change this template file, choose Tools | Templates and open the template in the editor. package steppingstone6 recipe import java.util.Scanner: import java.util.ArrayList 10 12 13 14 15 16 17 18 19 *Cauthor public class SteppingStone6 Recipe private String recipeName; private double totalRecipeCalories; private ArrayList recipe Ingredients; private int servings public SteppingStone5 Recipe createNewRecipe) this.recipeName ""; 27 this.servings0 steppingstoneb_recipe.SteppingStone6_Reaipe > O createNewRecipe Output SteppingStone6_Recipe (run) X java.lang. NoClassDefFoundError: SteppingStone5_Recipe 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-getHethodo (Class.java:3018) at java.lang.Class.getMethod (Class java 1784) at sun.launcher.LauncherHelper.validateMainClass (LauncherHelper.java: 544) at sun.launcher.LauncherHelper.checkAndLoadMain (LauncherHelper.java: 526) Caused by: java.lang ClassNotFoundException: SteppingStone5_Recipe at java.net.URLClassLoader.findClass (URLClassLoader.java 382) at java.lang . ClassLoader.1oadClass (ClassLoader.java: 424) at sunmi s c. Launcher$AppClassLoader.loadClass (Launcher.java: 349) at java.lang.ClassLoader.loadClass (ClassLoader.java : 357) SteppingStone6_Recipe.java X 10 /*x 12 13 @author public class SteppingStone6 Recipe 15 16 17 18 va eName: Run Project steppingstone6_recipe.SteppingStone6_Recpe dass wasn't found in SteppingStone6_Recipe project. 21 Select the main dass: No main classes found> 27 31 32 35 37 40 41 42 43 OK Cancel this. recipeName = recipelame ; 45 46 47 48 49 this. servings-servings; this. recipe Ingredients recipe Ingredients; = this.totalRecipeCalories- totalRecipeCalories; 51 52

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions