Question

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 part of the recipe, and one for the entire collection of recipes. The collection should use a list data structure to store the individual items. Your collection class should include methods like addItem(), printItem(), and deleteItem() that allow you to add, print, or delete items from your collection of items. Your Ingredient class will model the items that will be stored in each recipe in your collection. You will give it some basic attributes (of numeric or string types) and some basic methods (accessors/mutators, printItemDetails(), etc.). Your Recipe class will start off similar to your Ingredient class, but you will increase its functionality by modifying it to accept the Ingredient objects, containing all the details stored in an Ingredient class object. You will also expand the Recipe class by adding recipe-specific methods to your Recipe class."

package SteppingStone;

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

public class SteppingStone6_RecipeBox {


  
// private ArrayList of the listOfRecipes
  
private ArrayList<SteppingStone5_Recipe> listOfRecipes;   

// accessor and mutator for listOfRecipes
public ArrayList<SteppingStone5_Recipe> getListOfRecipes() {
return listOfRecipes;
}

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

// constructors for the SteppingStone6_RecipeBox()
public SteppingStone6_RecipeBox() {
this.listOfRecipes = new ArrayList<>();
}

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

void printAllRecipeDetails(String selectedRecipe) { // accepts a recipe from listOfRecipes and prints the recipe
for (SteppingStone5_Recipe recipe : listOfRecipes) {
if (recipe.getRecipeName().equalsIgnoreCase(selectedRecipe)) {
recipe.printRecipe();
return;
}
}
System.out.println("No Recipe found with name: " + selectedRecipe);
}

void printAllRecipeNames() { // prints the recipe name of each recipe in listOfRecipes
for (SteppingStone5_Recipe selectedRecipe : listOfRecipes) {
System.out.println(selectedRecipe.getRecipeName());
}
}

public void addRecipe(SteppingStone5_Recipe tempRecipe) { // adds a new recipe to listOfRecipes
listOfRecipes.add(tempRecipe);

// listOfRecipes.add(new SteppingStone5_Recipe().createNewRecipe());
}

/**
*
* A variation of following menu method should be used as the actual main
* once you are ready to submit your final application. For this submission
* and for using it to do stand-alone tests, replace the public void menu()
* with the standard public static main(String[] args) method
*
*/
// creates recipe box
public void menu() {
  
//public SteppingStone5_Recipe newRecipe()
// public static void main(String[] args) { comment out when using public void menu
//SteppingStone6_RecipeBox myRecipeBox = new SteppingStone6_RecipeBox(); // uncomment for main method
Scanner menuScnr = new Scanner(System.in);

/**
* Print a menu for the user to select one of the three options:
*
*/
// prints a menu for the user to select one of the three options:
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();

/**
* The code below has two variations: 1. Code used with the
* SteppingStone6_RecipeBox_tester. 2. Code used with the public
* static main() method
*
* One of the sections should be commented out depending on the use.
*/
/**
* This could should remain uncommented when using the
* SteppingStone6_RecipeBox_tester.
*
* Comment out this section when using the public static main()
* method
*/
if (input == 1) { //add recipe();
SteppingStone5_Recipe recipe = new SteppingStone5_Recipe();
this.addRecipe(recipe.addRecipe());
} else if (input == 2) {
System.out.println("Which recipe?\n");
String selectedRecipe = menuScnr.next();
printAllRecipeDetails(selectedRecipe);
} else if (input == 3) {
printAllRecipeNames();

for (int j = 0; j < listOfRecipes.size(); j++) {
System.out.println((j + 1) + ": "
+ 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:");
}
  
  
  

/**
* This could should be uncommented when using the public static
* main() method
*
* Comment out this section when using the
* SteppingStone6_RecipeBox_tester.
*
*/
  
/**
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:");
}

}

}

// newRecipe()

/**
public void addNewRecipe() {

//SteppingStone5_Recipe recipe1 = new Recipe();

}
CODE IS HERE--UNABLE TO POST IT
  
//Recipe newRecipe = new Recipe(getRecipeName(), getServings(), recipeIngredients,
// getTotalRecipeCalories(), recipeInstructions);
//System.out.println("Recipe for " + getRecipeName() + " saved.");
// Return the object to the calling method
// return newRecipe;
// }

// addRecipe(recipe);

public class SteppingStone5_RecipeTest {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
       // Create two recipe objects first
       SteppingStone5_Recipe myFirstRecipe = new SteppingStone5_Recipe();

CODE IS HERE--UNABLE TO POST IT
  

myRecipeBox.menu(); --error message is here on "menu"!!!!
  

   }
  
}


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

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

class SteppingStone5_Recipe {

        private String recipeName;
        private double totalRecipeCalories;
        private ArrayList<String> recipeIngredients;
        private int servings;

        public SteppingStone5_Recipe() {
                this.recipeName = "";
                this.servings = 0;
                this.recipeIngredients = new ArrayList<>();
                this.totalRecipeCalories = 0;
        }

        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 String getRecipeName() {
                return recipeName;
        }

        public void setRecipeName(String recipeName) {
                this.recipeName = recipeName;
        }

        public double getTotalRecipeCalories() {
                return totalRecipeCalories;
        }

        public void setTotalRecipeCalories(double totalRecipeCalories) {
                this.totalRecipeCalories = totalRecipeCalories;
        }

        public ArrayList<String> getRecipeIngredients() {
                return recipeIngredients;
        }

        public void setRecipeIngredients(ArrayList<String> recipeIngredients) {
                this.recipeIngredients = recipeIngredients;
        }

        public int getServings() {
                return servings;
        }

        public void setServings(int servings) {
                this.servings = servings;
        }

        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.");
        }

}


public class SteppingStone6_RecipeBox {

    //Declaring instance variables private ArrayList of the type SteppingStone5_Recipe
    private ArrayList<SteppingStone5_Recipe> listOfRecipes; 

    //Accessors and Mutators for listOfRecipes
    /**
     * @return the listOfRecipes
     */
    public ArrayList<SteppingStone5_Recipe> getListOfRecipes() {
        return listOfRecipes;
    } 

    /**
     * @param listOfRecipes the listOfRecipes to set
     */
    public void setListOfRecipes(ArrayList<SteppingStone5_Recipe> listOfRecipes) {
        this.listOfRecipes = listOfRecipes;
    }

    /**
        * @param listOfRecipes
        **/
    //Contstructors fo SteppingStone6_RecipeBox()
    public SteppingStone6_RecipeBox(ArrayList<SteppingStone5_Recipe> listOfRecipes) {
        this.listOfRecipes = listOfRecipes;
    }   

    public SteppingStone6_RecipeBox() {
        this.listOfRecipes = new ArrayList<>();
    }
 
    //Custom method to printAllRecipeDetails
    void printAllRecipeDetails(String selectedRecipe){
        for (SteppingStone5_Recipe recipe : listOfRecipes) {
            if(recipe.getRecipeName().equalsIgnoreCase(selectedRecipe)) {
                recipe.printRecipe();
                return;
            }
        }

        System.out.println("No Recipe found with name: " + selectedRecipe);
    }

    //Custom method for PrintAllRecipeNames
    void printAllRecipeNames(){
        for (SteppingStone5_Recipe selectedRecipe : listOfRecipes) {
            System.out.println(selectedRecipe.getRecipeName());
        }
    }


    //Custom method to AddRecipe
    public void addRecipe(SteppingStone5_Recipe tempRecipe) {
        listOfRecipes.add(tempRecipe);
    }
    
    //Custom method to AddRecipe
    public void deleteRecipe(String receipe) {
        int index = -1;
        for(int i=0; i<listOfRecipes.size(); i++) {
                if(listOfRecipes.get(i).getRecipeName().equalsIgnoreCase(receipe)) {
                        index = i;
                        break;
                }
        }
        
        if(index != -1) {
                listOfRecipes.remove(index);                    
        }
    }

    /**
        * A variation of following menu method should be used as the actual main        
        * once you are ready to submit your final application.  For this        
        * submission and for using it to do stand-alone tests, replace the      
        * public void menu() with the standard  
        * public static main(String[] args)     
        * method        
        */

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
            // Create a Recipe Box
            SteppingStone6_RecipeBox myRecipeBox = new SteppingStone6_RecipeBox(); 
        Scanner menuScnr = new Scanner(System.in);

        //Printing mennu for user to select the available options
        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()) {
            int input = menuScnr.nextInt();
                        /**
                        * The code below has two variations:
                        * 1. Code used with the SteppingStone6_RecipeBox_tester.
                        * 2. Code used with the public static main() method
                        *
                        * One of the sections should be commented out depending on the use. 
                        */
                        
                        /**
                        * This could should remain uncommented when using the
                        * SteppingStone6_RecipeBox_tester.
                        * 
                        * Comment out this section when using the
                        * public static main() method
                        */

            /** if (input == 1) {
                recipe1();

            } else if (input == 2) {
                System.out.println("Which recipe?\n");
                String selectedRecipeName = menuScnr.next();
                printAllRecipeDetails(selectedRecipeName);

            } else if (input == 3) {
                for (int j = 0; j < listOfRecipes.size(); j++) { 
                    System.out.println((j + 1) + ": " + 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:");
            }
            **/

                        /**
                        * This could should be uncommented when using the
                        * public static main() method
                        * 
                        * Comment out this section when using the
                        * SteppingStone6_RecipeBox_tester.
                        *
                        **/

            //Using if-else to select three custom methods.
            if (input == 1) {
                myRecipeBox.menu();
            } 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 if (input == 4) {
                String selectedRecipeName = menuScnr.next();
                myRecipeBox.deleteRecipe(selectedRecipeName);
            } 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:");
        }
    }

    public void menu() {

        double totalRecipeCalories = 0.0;
        ArrayList <String> recipeIngredients = new ArrayList();
        boolean addMoreIngredients = true;
        Scanner scnr = new Scanner(System.in);        

        System.out.println("Please enter the recipe name: "); //prompt user to enter recipe name.
        String recipeName = scnr.nextLine(); //checks if valid input was entered.             

        System.out.println("Please enter the number of servings: ");  //prompt user to enter number of servings for recipe.
        int servings = scnr.nextInt();  //checks if valid input was entered.

        do {
            //prompt user to enter ingredients or type end to finish loop.
            System.out.println("Please enter the ingredient name or type end if you are finished entering ingredients: ");
            String ingredientName = scnr.next().toLowerCase();

            //if user type end loop will end and print the recipe with ingredient, serving and calories.
            if (ingredientName.toLowerCase().equals("end")) {  
                addMoreIngredients = false;
            } else {

                //if user enter the ingredient loop will start ask for ingredient details.
                recipeIngredients.add(ingredientName);  //creating array list for recipe ingredients.

                //prompt user to enter ingredient amount
                System.out.println("Please enter an ingredient amount: ");  
                float ingredientAmount = scnr.nextFloat();

                //prompt user to enter measuring unit of ingredient
                System.out.println("Please enter the measurement unit for an ingredient: ");  
                String unitMeasurement = scnr.next();

                //promt user to enter ingredient calories
                System.out.println("Please enter ingredient calories: ");
                int ingredientCalories = scnr.nextInt();

                //Expression to calculate total calories
                totalRecipeCalories = (ingredientCalories * ingredientAmount);                   

                //prints the ingredient name with required amount, measuring unit and total calories.
                System.out.println(ingredientName + " uses " + ingredientAmount + " " + unitMeasurement + " and has " + totalRecipeCalories + " calories.");
            } //end else loop.          

       } while (addMoreIngredients);
        
       // Now create a recipe object and add it to the list
        SteppingStone5_Recipe recipe = new SteppingStone5_Recipe(recipeName, servings, recipeIngredients, totalRecipeCalories);
        addRecipe(recipe);
    }
}

please upvote. Thanks!

Add a comment
Answer #2

English language,  West Germanic language of the Indo-European language family that is closely related to the Frisian, German, and Dutch (in Belgium called Flemish) languages. English originated in England and is the dominant language of the United States, the United Kingdom, Canada, Australia, Ireland, New Zealand, and various island nations in the Caribbean Sea and the Pacific Ocean. It is also an official language of India, the Philippines, Singapore, and many countries in sub-Saharan Africa, including South Africa. English is the first choice of foreign language in most other countries of the world, and it is that status that has given it the position of a global lingua franca. It is estimated that about a third of the world’s population, some two billion persons, now use English.

answered by: Gamesome Goshawk
Add a comment
Know the answer?
Add Answer to:
I cannot submit my entire project due to the word count limit. I think my project...
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
  • *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; } /** *...

  • 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...

  • (How do I remove the STATIC ArrayList from the public class Accounts, and move it to...

    (How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in);    public static void main(String[] args) { Scanner scanner = new Scanner(System.in);    int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...

  • 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...

  • java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and sh...

    java programming how would i modify the code below to add a GUI (with a main menu with graphics and buttons, etc...) and include an option to print a list of all students added in a grid format and short by name, course, instructor, and location. ///main public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<Student>students = new ArrayList<>(); int choice; while(true) { displayMenu(); choice = in.nextInt(); switch(choice) { case 1: in.nextLine(); System.out.println("Enter Student Name"); String name...

  • 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,...

  • Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class...

    Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class Delete extends Info { String name; int Id; int del; public Delete() { } public void display() { Scanner key = new Scanner(System.in); System.out.println("Input Customer Name: "); name = key.nextLine(); System.out.println("Enter ID Number: "); Id = key.nextInt(); System.out.println("Would you like to Delete? Enter 1 for yes or 2 for no. "); del = key.nextInt(); if (del == 1) { int flag = 0; //learned...

  • THIS IS MY CODE ALL I NEED IS THE SECTIONS TO BE FILLED IN AND CODE...

    THIS IS MY CODE ALL I NEED IS THE SECTIONS TO BE FILLED IN AND CODE SHOULD RUN. FILL IN THE CODE PLEASE. package p02; import static java.lang.System.*; import java.io.*; import java.util.*; public class P02 {    public static Vector<Double> wallet=new Vector<Double>();    public static void addMoneyToWallet(){    }    public static void removeMoneyFromWallet(){    }    public static void displayMoneyInWallet(){    }    public static void emptyWallet(){    }    public static void main(String[] args){ int choice=0; String menu="Wallet...

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
ADVERTISEMENT