Question
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:
This is what I get when I replace main as the instructions tell me to:
Or when I replace main I get this:
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 ArrayListStep 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