Question

I'm getting a few errors still under RecipeBox. Would you be able to see what's wrong?...

I'm getting a few errors still under RecipeBox. Would you be able to see what's wrong? Thanks

------------

package recipecollection;

import java.util.ArrayList;

public class SteppingStone5_RecipeTest {
public static void main(String[] args) {
ArrayList<String> recipeIngredients = new ArrayList<>();
recipeIngredients.add("Peanut butter");
recipeIngredients.add("Jelly");
recipeIngredients.add("Bread");
SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe("Peanut butter & jelly sandwich", 2, recipeIngredients, 300, 10.0);

System.out.println("RECIPE 1");
recipe1.printRecipe();
System.out.println();
recipe1.setRecipeName("Turkey sandwich");
recipe1.setServings(5);

recipe1.setTotalRecipeCalories(500);
System.out.println();
System.out.println("RECIPE 1 (Modified)");
recipe1.printRecipe();

System.out.println();
System.out.println("RECIPE 2");
SteppingStone5_Recipe recipe2 = SteppingStone5_Recipe.createNewRecipe();
recipe2.printRecipe();
}

}

/////////////////

package recipecollection;

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


public class SteppingStone5_Recipe {
private String recipeName = "";

double servings = 0.0;

ArrayList<String> recipeIngredients = new ArrayList<String>();
private double totalRecipeCalories = 0.0;
public SteppingStone5_Recipe() {

this.recipeName = "";

this.servings = 0.0;

this.recipeIngredients = (null); //

this.totalRecipeCalories = totalRecipeCalories;

}

public SteppingStone5_Recipe(String recipeName, double servings, ArrayList<String> recipeIngredients,
double totalRecipeCalories) {

this.recipeName = recipeName;

this.servings = servings;

this.totalRecipeCalories = totalRecipeCalories;

this.recipeIngredients = recipeIngredients;

}

SteppingStone5_Recipe(String peanut_butter__jelly_sandwich, int i, ArrayList<String> recipeIngredients, int i0, double d) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public String getrecipeName() {

return recipeName;

}

public void setRecipeName(String recipeName) {

this.recipeName = recipeName;

}

public double getservings() {

return servings;

}

public void setServings(int servings) {

this.servings = servings;

}
public ArrayList<String> getrecipeIngredients() {

return recipeIngredients;

}
public void setrecipeIngredients(ArrayList<String> recipeIngredients) {

this.recipeIngredients = recipeIngredients;
}

public double getTotalRecipeCalories() {

return totalRecipeCalories;

}

public void setTotalRecipeCalories(double totalRecipeCalories) {

this.totalRecipeCalories = totalRecipeCalories;

}

public SteppingStone5_Recipe(String recipeName, int servings, ArrayList<String> recipeIngredients,
double totalRecipeCalories) {

this.recipeName = recipeName;

this.servings = servings;

this.recipeIngredients = recipeIngredients;

this.totalRecipeCalories = totalRecipeCalories;

}

public void printRecipe() {
int singleServingCalories;

singleServingCalories = (int) 0.0;

singleServingCalories = (int) (totalRecipeCalories / servings);

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

System.out.println("single serving calories: " + singleServingCalories);

}

public static SteppingStone5_Recipe createNewRecipe() {

double totalRecipeCalories = 0.0;

ArrayList<String> recipeIngredients = new ArrayList<String>();

boolean addMoreIngredients = true;

double servings = 0.0;

String ingredientName = "";

int ingredientCalories = 0;

double ingredientAmount = 0.0;

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: ");

servings = scnr.nextFloat();

do {

System.out.println("Enter the ingredient name or type end if you are finished entering ingredients: ");

ingredientName = scnr.next();

if (ingredientName.toLowerCase().equals("end")) {

addMoreIngredients = false;

} else {

recipeIngredients.add(ingredientName);

System.out.println("Please enter the ingredient amount: ");

ingredientAmount = scnr.nextFloat();

System.out.println("Please enter the ingredient Calories: ");

ingredientCalories = scnr.nextInt();

totalRecipeCalories += (ingredientCalories * ingredientAmount);

}

} while (addMoreIngredients);

SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe(recipeName, servings, recipeIngredients,

totalRecipeCalories);

scnr.close();

return recipe1;

}

}

///////////////////

package recipecollection;

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

public class SteppingStone6_RecipeBox {
private ArrayList<SteppingStone5_Recipe> listOfRecipes;
public ArrayList<SteppingStone5_Recipe> getListOfRecipes() {
return listOfRecipes;
}

public void setListOfRecipes(ArrayList<SteppingStone5_Recipe> listOfRecipes) {
this.listOfRecipes = listOfRecipes;
}
public SteppingStone6_RecipeBox(
ArrayList<SteppingStone5_Recipe> listOfRecipes) {
this.listOfRecipes = listOfRecipes;
}

public SteppingStone6_RecipeBox() {
this.listOfRecipes = new ArrayList<>();

}
public void printAllRecipeDetails(String selectedRecipe) {
for (SteppingStone5_Recipe recipe1 : listOfRecipes) {
if (recipe1.getRecipeName().equalsIgnoreCase(selectedRecipe)) {
recipe1.printRecipe();
return;
}
}
System.out.println("No Recipe found with name: " + selectedRecipe);
}

public void printAllRecipeNames() {
for (SteppingStone5_Recipe selectedRecipe : listOfRecipes) {
System.out.println(selectedRecipe.getRecipeName());
}
}
public void addRecipe(SteppingStone5_Recipe tmpRecipe) {
listOfRecipes.add(tmpRecipe);
}

public static void main(String[] args) {
SteppingStone6_RecipeBox myRecipeBox = new SteppingStone6_RecipeBox(); //Uncomment for main method
Scanner menuScnr = new Scanner(System.in);

System.out.println("Menu\n" + "1. Add Recipe\n" + "2. Print All Recipe Details\n" + "3. Print All Recipe Names\n" + "\nPlease select a menu item:");
while (menuScnr.hasNextInt() || menuScnr.hasNextLine()) {
System.out.println("Menu\n" + "1. Add Recipe\n" + "2. Print All Recipe Details\n" + "3. Print All Recipe Names\n" + "\nPlease select a menu item:");
int input = menuScnr.nextInt();

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("\nMenu\n" + "1. Add Recipe\n" + "2. Print Recipe\n" + "3. Adjust Recipe Servings\n" + "\nPlease select a menu item:");
}

System.out.println("Menu\n" + "1. Add Recipe\n" + "2. Print All Recipe Details\n" + "3. Print All Recipe Names\n" + "\nPlease select a menu item:");
}
}
}
///////////////////

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. Errors were due to the name of the method in class SteppingStone5_Recipe was wrong. Change the method name

getrecipeName() to getRecipeName().

2. Another error is due to the class SteppingStone6_RecipeBox in the main method when the input for the menu is 1 you have to add a new recipe, so call to the addRecipe() should be there. If the user is providing all the input then call the method with appropriate parameters.

SteppingStone5_Recipe temp = new SteppingStone5_Recipe();
myRecipeBox.addRecipe(temp);

Please find below updated code for all the files:

SteppingStone5_Recipe.java
package recipecollection;

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


public class SteppingStone5_Recipe {
    private String recipeName = "";

    double servings = 0.0;

    ArrayList<String> recipeIngredients = new ArrayList<String>();
    private double totalRecipeCalories = 0.0;
    public SteppingStone5_Recipe() {

        this.recipeName = "";

        this.servings = 0.0;

        this.recipeIngredients = (null); //

        this.totalRecipeCalories = totalRecipeCalories;

    }

    public SteppingStone5_Recipe(String recipeName, double servings, ArrayList<String> recipeIngredients,
                                 double totalRecipeCalories) {

        this.recipeName = recipeName;

        this.servings = servings;

        this.totalRecipeCalories = totalRecipeCalories;

        this.recipeIngredients = recipeIngredients;

    }

    SteppingStone5_Recipe(String peanut_butter__jelly_sandwich, int i, ArrayList<String> recipeIngredients, int i0, double d) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    public String getRecipeName() {

        return recipeName;

    }

    public void setRecipeName(String recipeName) {

        this.recipeName = recipeName;

    }

    public double getservings() {

        return servings;

    }

    public void setServings(int servings) {

        this.servings = servings;

    }
    public ArrayList<String> getrecipeIngredients() {

        return recipeIngredients;

    }
    public void setrecipeIngredients(ArrayList<String> recipeIngredients) {

        this.recipeIngredients = recipeIngredients;
    }

    public double getTotalRecipeCalories() {

        return totalRecipeCalories;

    }

    public void setTotalRecipeCalories(double totalRecipeCalories) {

        this.totalRecipeCalories = totalRecipeCalories;

    }

    public SteppingStone5_Recipe(String recipeName, int servings, ArrayList<String> recipeIngredients,
                                 double totalRecipeCalories) {

        this.recipeName = recipeName;

        this.servings = servings;

        this.recipeIngredients = recipeIngredients;

        this.totalRecipeCalories = totalRecipeCalories;

    }

    public void printRecipe() {
        int singleServingCalories;

        singleServingCalories = (int) 0.0;

        singleServingCalories = (int) (totalRecipeCalories / servings);

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

        System.out.println("single serving calories: " + singleServingCalories);

    }

    public static SteppingStone5_Recipe createNewRecipe() {

        double totalRecipeCalories = 0.0;

        ArrayList<String> recipeIngredients = new ArrayList<String>();

        boolean addMoreIngredients = true;

        double servings = 0.0;

        String ingredientName = "";

        int ingredientCalories = 0;

        double ingredientAmount = 0.0;

        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: ");

        servings = scnr.nextFloat();

        do {

            System.out.println("Enter the ingredient name or type end if you are finished entering ingredients: ");

            ingredientName = scnr.next();

            if (ingredientName.toLowerCase().equals("end")) {

                addMoreIngredients = false;

            } else {

                recipeIngredients.add(ingredientName);

                System.out.println("Please enter the ingredient amount: ");

                ingredientAmount = scnr.nextFloat();

                System.out.println("Please enter the ingredient Calories: ");

                ingredientCalories = scnr.nextInt();

                totalRecipeCalories += (ingredientCalories * ingredientAmount);

            }

        } while (addMoreIngredients);

        SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe(recipeName, servings, recipeIngredients,

                totalRecipeCalories);

        scnr.close();

        return recipe1;

    }

}


SteppingStone6_RecipeBox.java
package recipecollection;

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

    public class SteppingStone6_RecipeBox {
    private ArrayList<SteppingStone5_Recipe> listOfRecipes;

    public ArrayList<SteppingStone5_Recipe> getListOfRecipes() {
        return listOfRecipes;
    }

    public void setListOfRecipes(ArrayList<SteppingStone5_Recipe> listOfRecipes) {
        this.listOfRecipes = listOfRecipes;
    }
    public SteppingStone6_RecipeBox(ArrayList<SteppingStone5_Recipe> listOfRecipes) {
        this.listOfRecipes = listOfRecipes;
    }

    public SteppingStone6_RecipeBox() {
        this.listOfRecipes = new ArrayList<>();

    }
    public void printAllRecipeDetails(String selectedRecipe) {
        for (SteppingStone5_Recipe recipe1 : listOfRecipes) {
            if (recipe1.getRecipeName().equalsIgnoreCase(selectedRecipe)) {
                recipe1.printRecipe();
                return;
            }
        }
        System.out.println("No Recipe found with name: " + selectedRecipe);
    }

    public void printAllRecipeNames() {
        for (SteppingStone5_Recipe selectedRecipe : listOfRecipes) {
            System.out.println(selectedRecipe.getRecipeName());
        }
    }
    public void addRecipe(SteppingStone5_Recipe tmpRecipe) {
        listOfRecipes.add(tmpRecipe);
    }

    public static void main(String[] args) {
        SteppingStone6_RecipeBox myRecipeBox = new SteppingStone6_RecipeBox(); //Uncomment for main method
        Scanner menuScnr = new Scanner(System.in);

        System.out.println("Menu\n" + "1. Add Recipe\n" + "2. Print All Recipe Details\n" + "3. Print All Recipe Names\n" + "\nPlease select a menu item:");
        while (menuScnr.hasNextInt() || menuScnr.hasNextLine()) {
            System.out.println("Menu\n" + "1. Add Recipe\n" + "2. Print All Recipe Details\n" + "3. Print All Recipe Names\n" + "\nPlease select a menu item:");
            int input = menuScnr.nextInt();

            if (input == 1) {
                SteppingStone5_Recipe temp = new SteppingStone5_Recipe();
                myRecipeBox.addRecipe(temp);
            } 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("\nMenu\n" + "1. Add Recipe\n" + "2. Print Recipe\n" + "3. Adjust Recipe Servings\n" + "\nPlease select a menu item:");
            }

            System.out.println("Menu\n" + "1. Add Recipe\n" + "2. Print All Recipe Details\n" + "3. Print All Recipe Names\n" + "\nPlease select a menu item:");
        }
    }
}
SteppingStone5_RecipeTest.java
package recipecollection;

import java.util.ArrayList;

public class SteppingStone5_RecipeTest {
    public static void main(String[] args) {
        ArrayList<String> recipeIngredients = new ArrayList<>();
        recipeIngredients.add("Peanut butter");
        recipeIngredients.add("Jelly");
        recipeIngredients.add("Bread");
        SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe("Peanut butter & jelly sandwich", 2, recipeIngredients, 300, 10.0);

        System.out.println("RECIPE 1");
        recipe1.printRecipe();
        System.out.println();
        recipe1.setRecipeName("Turkey sandwich");
        recipe1.setServings(5);

        recipe1.setTotalRecipeCalories(500);
        System.out.println();
        System.out.println("RECIPE 1 (Modified)");
        recipe1.printRecipe();

        System.out.println();
        System.out.println("RECIPE 2");
        SteppingStone5_Recipe recipe2 = SteppingStone5_Recipe.createNewRecipe();
        recipe2.printRecipe();
    }

}
Add a comment
Know the answer?
Add Answer to:
I'm getting a few errors still under RecipeBox. Would you be able to see what's wrong?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can someone help me with my code.. I cant get an output. It says I do...

    Can someone help me with my code.. I cant get an output. It says I do not have a main method. HELP PLEASE. The instruction are in bold on the bottom of the code. package SteppingStones; //Denisse.Carbo import java.util.Scanner; import java.util.ArrayList; import java.util.List; public class SteppingStone5_Recipe { private String recipeName; private int servings; private List<String> recipeIngredients; private double totalRecipeCalories; public String getRecipeName() { return recipeName; } public void setRecipeName (string recipeName){ this.recipeName = recipeName; } public int getServings() { return...

  • How to build Java test class? I am supposed to create both a recipe class, and...

    How to build Java test class? I am supposed to create both a recipe class, and then a class tester to test the recipe class. Below is what I have for the recipe class, but I have no idea what/or how I am supposed to go about creating the test class. Am I supposed to somehow call the recipe class within the test class? if so, how? Thanks in advance! This is my recipe class: package steppingstone5_recipe; /** * *...

  • Prompt: In this stepping stone lab assignment, you will build a Recipe class, getting user input...

    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. Specifically, you will need to create the following:  The instance variables for the class (recipeName, serving size, and...

  • I would like someone to check my code and help with my for loop to print...

    I would like someone to check my code and help with my for loop to print the recipe. It is incorrect. package SteppingStones; import java.util.Scanner; //Scanner class// import java.util.ArrayList; //ArrayList// import ingredients.Ingredient; /**Gets from package ingredients and class Ingredient * * @author kimbe */ public class SteppingStone5_Recipe {    //Instance Variables// private ArrayList recipeIngredients; private String recipeName; private int servings; private double totalRecipeCalories;                   //Setter and Getters//    public ArrayList getrecipeIngredients() { return recipeIngredients; }...

  • Hi. Could you help me with the code below? I need to validate the code below, using expressions that can carry out the actions or that make appropriate changes to the program’s state, using conditiona...

    Hi. Could you help me with the code below? I need to validate the code below, using expressions that can carry out the actions or that make appropriate changes to the program’s state, using conditional and iterative control structures that repeat actions as needed. The unit measurement is missing from the final output and I need it to offer options to lbs, oz, grams, tbsp, tsp, qt, pt, and gal. & fl. oz. Can this be added? The final output...

  • *Please Add Inline Comments Directed toward software engineers about design decisions to facilitate the programs ongoing...

    *Please Add Inline Comments Directed toward software engineers about design decisions to facilitate the programs ongoing maintenance* import java.util.ArrayList; import java.util.Scanner; /** * * @author Eli Mishkit */ public class SteppingStone6_RecipeBox { /** * Declare instance variables: * a private ArrayList of the type SteppingStone5_Recipe named listOfRecipes * */ private ArrayList<SteppingStone5_Recipe> listOfRecipes; /** * Add accessor and mutator for listOfRecipes * */ public ArrayList<SteppingStone5_Recipe> getListOfRecipes() { return listOfRecipes; } public void setListOfRecipes(ArrayList<SteppingStone5_Recipe> listOfRecipes) { this.listOfRecipes = listOfRecipes; } /** *...

  • I cannot submit my entire project due to the word count limit. I think my project...

    I cannot submit my entire project due to the word count limit. I think my project looks ok, but my recipe box class and recipe test class is running errors and it may have something to do with the menu portion of the recipe box. Please take a look: "You will create a program that will help you manage a collection of recipes. You will implement three classes: one for the main recipe items, one for the ingredients that are...

  • Currently, I'm getting this as my output: "Exception in thread "main" java.lang.NullPointerException    at InfixExpression.execute(InfixExpression.java:98)   ...

    Currently, I'm getting this as my output: "Exception in thread "main" java.lang.NullPointerException    at InfixExpression.execute(InfixExpression.java:98)    at InfixExpression.Evaluate(InfixExpression.java:65)    at InfixExpression.setWholeExpr(InfixExpression.java:24)    at InfixExpression.<init>(InfixExpression.java:17)    at Main.testHW1(Main.java:17)    at Main.main(Main.java:6)" I need to get this as my output: "Testing InfixExpression: When passing null, the String and double = Infix String: , result: 0.0 When passing a valid String, the String and double = Infix String: ( 234.5 * ( 5.6 + 7.0 ) ) / 100.2, result: 29.488023952095805 ..." I...

  • Can you help me rearrange my code to make it look cleaner but still give the...

    Can you help me rearrange my code to make it look cleaner but still give the same output? Also kindly add an in-line comment on what changes and rearrangement you've done so I can understand what's going on. import java.util.ArrayList; import java.util.Scanner; public class Bank { /** * Add and read bank information to the user. * @param arg A string, double and int array containing * the command line arguments. * @exception Any exception * @return an arraylsit of...

  • Can you help me rearrange my code by incorporating switch I'm not really sure how to...

    Can you help me rearrange my code by incorporating switch I'm not really sure how to do it and it makes the code look cleaner. Can you help me do it but still give the same output? Also kindly add an in-line comment on what changes and rearrangement you've done so I can understand what's going on. import java.util.ArrayList; import java.util.Scanner; public class Bank { /** * Add and read bank information to the user. * @param arg A string,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT