Question

In: Computer Science

Looking for code to this stepping stone lab 6 Prompt: In Stepping Stone Lab Five, you...

Looking for code to this stepping stone lab 6

Prompt:

In Stepping Stone Lab Five, you created a Recipe Class. Now, in Stepping Stone Lab Six, you will focus your skills on developing your own driver class including custom methods to access elements of the Ingredient and Recipe classes.

Specifically, you will need to create the following:

 The instance variables for the class (listOfRecipes) 

Accessors and mutators for the instance variable 

Constructors 

Three custom methods: printAllRecipeDetails(), printAllRecipeNames, and addNewRecipe

Guidelines for Submission: This assignment should be submitted as a Java file.

  


Extending This Lab for Your Final Project For your final project submission, you should add a menu item and a method to access the custom method you developed for the Recipe class based on the Steppcing Stone Lab Five.

Code given:

package SteppingStones;

import java.util.ArrayList;

public class SteppingStone6_RecipeBox {
  
   /**
   * Declare instance variables:
   * a private ArrayList of the type SteppingStone5_Recipe named listOfRecipes
   *
   */
  
   /**
   * Add accessor and mutator for listOfRecipes
   *
   */

   /**
   * Add constructors for the SteppingStone6_RecipeBox()
   *
   */
     
   /**
   * Add the following custom methods:
   *
   * //printAllRecipeDetails(SteppingStone5_Recipe selectedRecipe)
   *        This method should accept a recipe from the listOfRecipes ArrayList
   *        recipeName and use the SteppingStone5_Recipe.printRecipe() method
   *        to print the recipe
   *       
   * //printAllRecipeNames() <-- This method should print just the recipe
   *        names of each of the recipes in the listOfRecipes ArrayList
   *
   * //addRecipe(SteppingStone5_Recipe tmpRecipe) <-- This method should use
   *        the SteppingStone5_Recipe.addRecipe() method to add a new
   *        SteppingStone5_Recipe to the listOfRecipes
   *
   */
  
  
   /**
   * 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
   *
   */
  
   public void menu() {
   // Create a Recipe Box
      
       //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:
       *
       */
      
       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) {
newRecipe();
} 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.
           *      
          
          
           if (input == 1) {
myRecipeBox.newRecipe();
} else if (input == 2) {
System.out.println("Which recipe?\n");
String selectedRecipeName = menuScnr.next();
myRecipesBox.printAllRecipeDetails(selectedRecipeName);
} else if (input == 3) {      
               for (int j = 0; j < myRecipesBox.listOfRecipes.size(); j++) {
System.out.println((j + 1) + ": " + myRecipesBox.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:");
       }
      
  
   }

}


/**
*
* Final Project Details:
*
* For your final project submission, you should add a menu item and a method
*       to access the custom method you developed for the Recipe class
*        based on the Stepping Stone 5 Lab.
*
*/

Solutions

Expert Solution

/***************************************SteppingStone6_RecipeBox.java*************************/

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

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;
   }

   /**
   * Add constructors for the SteppingStone6_RecipeBox()
   *
   */
   public SteppingStone6_RecipeBox(ArrayList<SteppingStone5_Recipe> listOfRecipes) {
       super();
       this.listOfRecipes = listOfRecipes;
   }

   /**
   * Add the following custom methods:
   *
   * //printAllRecipeDetails(SteppingStone5_Recipe selectedRecipe) This method
   * should accept a recipe from the listOfRecipes ArrayList recipeName and use
   * the SteppingStone5_Recipe.printRecipe() method to print the recipe
   *
   * //printAllRecipeNames() <-- This method should print just the recipe names of
   * each of the recipes in the listOfRecipes ArrayList
   *
   * //addRecipe(SteppingStone5_Recipe tmpRecipe) <-- This method should use the
   * SteppingStone5_Recipe.addRecipe() method to add a new SteppingStone5_Recipe
   * to the listOfRecipes
   *
   */
   public void printAllRecipeDetails(String selectedRecipe) {

       for (SteppingStone5_Recipe steppingStone5_Recipe : listOfRecipes) {

           if (steppingStone5_Recipe.getRecipeName().equalsIgnoreCase(selectedRecipe)) {

               steppingStone5_Recipe.printRecipe();
           }
       }
   }

   public void printAllRecipeNames() {

       for (SteppingStone5_Recipe steppingStone5_Recipe : listOfRecipes) {

           System.out.println(steppingStone5_Recipe.getRecipeName());
       }
   }

   public void addRecipe(SteppingStone5_Recipe tmpRecipe) {

       listOfRecipes.add(tmpRecipe);
   }

   /**
   * 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
   *
   */

   public void menu() {
       // Create a Recipe Box

       // 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:
       *
       */

       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) {
               newRecipe();
           } 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.
           *
           *
           *
           * if (input == 1) { myRecipeBox.newRecipe(); } else if (input == 2) {
           * System.out.println("Which recipe?\n"); String selectedRecipeName =
           * menuScnr.next(); myRecipesBox.printAllRecipeDetails(selectedRecipeName); }
           * else if (input == 3) { for (int j = 0; j < myRecipesBox.listOfRecipes.size();
           * j++) { System.out.println((j + 1) + ": " +
           * myRecipesBox.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:");
       }

   }

   public void newRecipe() {

       double totalRecipeCalories = 0;
       Scanner scnr = new Scanner(System.in);
       ArrayList<Ingredient> recipeIngredients = new ArrayList<>();
       System.out.print("Please enter the recipe name: ");
       String recipeName = scnr.nextLine();
       System.out.print("Please enter the number of servings: ");
       int servings = scnr.nextInt();
       System.out.print("How many ingredients you want to add: ");
       int numberOfIngredient = scnr.nextInt();
       scnr.nextLine();
       for (int i = 0; i < numberOfIngredient; i++) {

           System.out.println("Enter details of ingredient " + (i + 1));
           System.out.print("Enter Ingredient name: ");
           String name = scnr.nextLine();
           System.out.print("Enter Ingredient Amount: ");
           double amount = scnr.nextDouble();
           scnr.nextLine();
           System.out.print("Enter UnitMeasurement: ");
           String unit = scnr.nextLine();
           System.out.print("Enter total calories of Ingredient: ");
           double totalCalories = scnr.nextDouble();
           scnr.nextLine();
           totalRecipeCalories += totalCalories;
           recipeIngredients.add(new Ingredient(name, amount, unit, totalCalories));
       }

       SteppingStone5_Recipe myRecipe = new SteppingStone5_Recipe(recipeName, servings, recipeIngredients,
               totalRecipeCalories);
       addRecipe(myRecipe);
   }

}

/*********************************SteppingStone5_Recipe.java*************************/

import java.util.ArrayList;

/**
*
* Recipe class :
*
* create one recipe
*
*
*
*/

public class SteppingStone5_Recipe {

   // variables

   private ArrayList<Ingredient> recipeIngredients;

   private ArrayList<String> instructions;

   private String recipeName;

   private int servings;

   private double totalRecipeCalories;

   // constructor

   public SteppingStone5_Recipe() {
       this.recipeName = "";

       this.recipeIngredients = new ArrayList<>();

       this.instructions = new ArrayList<>();

       this.servings = 0;

       this.totalRecipeCalories = 0.0;
   }

   public SteppingStone5_Recipe(String recipeName, int servings, ArrayList<Ingredient> ingredients,
           double totalRecipeCalories2) {

       this.recipeName = recipeName;

       this.recipeIngredients = ingredients;

       this.instructions = new ArrayList<>();

       this.servings = servings;

       this.totalRecipeCalories = totalRecipeCalories2;

   }

   // get IngredientList

   public ArrayList<Ingredient> getIngredientList() {

       return recipeIngredients;

   }

   // set IngredientList

   public void setIngredientList(ArrayList<Ingredient> recipeIngredients) {

       this.recipeIngredients = recipeIngredients;

   }

   /**
   *
   * @return the recipeName
   *
   */

   public String getRecipeName() {

       return recipeName;

   }

   /**
   *
   * @param recipeName the recipeName to set
   *
   */

   public void setRecipeName(String recipeName) {

       this.recipeName = recipeName;

   }

   /**
   *
   * @return the servings
   *
   */

   public int getServings() {

       return servings;

   }

   /**
   *
   * @param servings the servings to set
   *
   */

   public void setServings(int servings) {

       this.servings = servings;

   }

   /**
   *
   * @return the totalRecipeCalories
   *
   */

   public double getTotalRecipeCalories() {

       return totalRecipeCalories;

   }

   /**
   *
   * @param totalRecipeCalories the totalRecipeCalories to set
   *
   */

   public void setTotalRecipeCalories(double totalRecipeCalories) {

       this.totalRecipeCalories = totalRecipeCalories;

   }

   // add Ingredient in recipe

   public boolean addIngredient(Ingredient ingredient) {

       this.totalRecipeCalories = this.totalRecipeCalories + ingredient.getTotalCalories();

       return this.recipeIngredients.add(ingredient);

   }

   // remove Ingredient in recipe

   public boolean removeIngredient(Ingredient ingredient) {

       if (this.recipeIngredients.remove(ingredient)) {

           this.totalRecipeCalories = this.totalRecipeCalories - ingredient.getTotalCalories();

           return true;

       }

       else

           return false;

   }

   // remove all Ingredient in recipe

   public boolean removeAllIngredient() {

       return this.recipeIngredients.removeAll(recipeIngredients);

   }

   // print Ingredients in recipe

   public void printRecipe() {

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

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

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

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

       for (Ingredient ingredient : recipeIngredients) {

           ingredient.printItemDetails();

       }

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

   }

   // create new recipe

   public static Recipe createNewRecipe(String recipeName, int servings, ArrayList<Ingredient> ingredients,
           double totalRecipeCalories) {

       return new Recipe(recipeName, servings, ingredients, totalRecipeCalories);

   }

   // insert instruction

   public boolean insertInstruction(String instruction) {

       return this.instructions.add(instruction);

   }

   public void printInstruction() {

       instructions.toString();

   }

}

/********************************************Ingredient.java*******************/


/**
* Ingredient class :
*
* items that will be stored in each recipe.
*/

public class Ingredient {

   // variables

   /** The ingredient name. */
   private String ingredientName;

   /** The ingredient amount. */
   private double ingredientAmount;

   /** The unit measurement. */
   private String unitMeasurement;

   /** The total calories. */
   private double totalCalories;

   /**
   * Instantiates a new ingredient.
   */
   public Ingredient() {

       this.ingredientName = "";
       this.ingredientAmount = 0;
       this.unitMeasurement = "";
       this.totalCalories = 0;
   }

   // constructor

   /**
   * Instantiates a new ingredient.
   *
   * @param ingredientName the ingredient name
   * @param ingredientAmount the ingredient amount
   * @param unitMeasurement the unit measurement
   * @param totalCalories the total calories
   */
   public Ingredient(String ingredientName, double ingredientAmount, String unitMeasurement, double totalCalories) {

       super();

       this.ingredientName = ingredientName;

       this.ingredientAmount = ingredientAmount;

       this.unitMeasurement = unitMeasurement;

       this.totalCalories = totalCalories;

   }

   // getter and setter

   /**
   * Gets the ingredient name.
   *
   * @return the ingredient name
   */
   public String getIngredientName() {

       return ingredientName;

   }

   /**
   * Sets the ingredient name.
   *
   * @param ingredientName the new ingredient name
   */
   public void setIngredientName(String ingredientName) {

       this.ingredientName = ingredientName;

   }

   /**
   * Gets the ingredient amount.
   *
   * @return the ingredient amount
   */
   public double getIngredientAmount() {

       return ingredientAmount;

   }

   /**
   * Sets the ingredient amount.
   *
   * @param ingredientAmount the new ingredient amount
   */
   public void setIngredientAmount(double ingredientAmount) {

       this.ingredientAmount = ingredientAmount;

   }

   /**
   * Gets the unit measurement.
   *
   * @return the unit measurement
   */
   public String getUnitMeasurement() {

       return unitMeasurement;

   }

   /**
   * Sets the unit measurement.
   *
   * @param unitMeasurement the new unit measurement
   */
   public void setUnitMeasurement(String unitMeasurement) {

       this.unitMeasurement = unitMeasurement;

   }

   /**
   * Gets the total calories.
   *
   * @return the total calories
   */
   public double getTotalCalories() {

       return totalCalories;

   }

   /**
   * Sets the total calories.
   *
   * @param totalCalories the new total calories
   */
   public void setTotalCalories(double totalCalories) {

       this.totalCalories = totalCalories;

   }

   /**
   * Change measuremt.
   */
   public void changeMeasuremt() {

       if (this.unitMeasurement.equalsIgnoreCase("English")) {

           ingredientAmount = 0.035 * ingredientAmount;
       } else {

           ingredientAmount = ingredientAmount / 0.035;
       }

   }
   // print item detail

   /**
   * Prints the item details.
   */
   public void printItemDetails() {
      
      
       if(unitMeasurement.equalsIgnoreCase("English")) {
       System.out.println("ingredientName " + this.ingredientName);

       System.out.println("ingredientAmount " + this.ingredientAmount+" Grams");

       System.out.println("totalCalories " + this.totalCalories);

       System.out.println("unitMeasurement " + this.unitMeasurement);
       }
       else {
          
           System.out.println("ingredientName " + this.ingredientName);

           System.out.println("ingredientAmount " + this.ingredientAmount+" Ounces");

           System.out.println("totalCalories " + this.totalCalories);

           System.out.println("unitMeasurement " + this.unitMeasurement);
       }

   }

}

Please let me know if you have any doubt or modify the answer, Thanks:)


Related Solutions

For any project, planning is the key stepping stone to success. For many projects that fail...
For any project, planning is the key stepping stone to success. For many projects that fail around the world, failure is attributed to lack of detailed planning. In some instances, planning is done but not to the level of detail required. Part of the planning involves the creation of motivated teams. Discuss FIVE (5) tools and techniques that Amber could use to enhance team development and their contribution to the project goal of hosting a successful anniversary celebration.
A stone is dropped at t = 0. A second stone, with 6 times the mass...
A stone is dropped at t = 0. A second stone, with 6 times the mass of the first, is dropped from the same point at t = 130 ms. (a) How far below the release point is the center of mass of the two stones at t = 350 ms? (Neither stone has yet reached the ground.) (b) How fast is the center of mass of the two-stone system moving at that time?
Into to PythonInstructions: • In this lab you are to debug the code found at...
Into to PythonInstructions: • In this lab you are to debug the code found at the end of these instructions: Find and correct all problems found in the code. Create comments in the code explaining what you found and how you corrected it • The purpose of this program is to calculate car insurance rates using the following rules: The base rate of insurance is $50 a month, Males pay a 25% premium over the base rate, Drivers in Michigan...
Prompt You are the Operations Manager for a technology company. Your company is looking to expand...
Prompt You are the Operations Manager for a technology company. Your company is looking to expand its product line and in doing so it will need a larger or even second location. What considerations are taken into account for determining which solution is best? When you decide the solution how do you secure the property? Would any other item needed to expand the product line be considered real property?  
Imagine you work in a hospital and as you are stepping off of the elevator, you...
Imagine you work in a hospital and as you are stepping off of the elevator, you notice a piece of paper on the floor. You pick it up and see the above information on Susan Bowers. Understanding the importance of a person’s private health information confidentiality, you immediately take this information to the hospital’s IT Security Officer who monitors the EHR and its users. After tracking the “footprints” left behind when the users accessed Susan Bowers’ chart, the Security Officer...
How do you write this code in JavaScript inside the head? Prompt the user for their...
How do you write this code in JavaScript inside the head? Prompt the user for their first name. Remember you must save the value that the user enters so that you can use that value, therefore the prompt must be in an assignment statement. Prompt the user for their last name. Have an alert box pop up that contains the first name followed by a space and then the last name followed by a short message that you make up....
a java code In this lab you will implement an inorder traversal, and a search for...
a java code In this lab you will implement an inorder traversal, and a search for a 2-3-4 tree. The inorder traversal will print the contents (integers) of the tree, and the search method will return a boolean, indicating whether a given key was found in the tree. Examine the provided template. The main method is provided for you, as well as a template of the Node and 2-3-4 classes. The main method will read either "inorder" or an integer...
7.14 LAB: Temperature conversion In this lab, you will implement a temperature converter. Five UI elements...
7.14 LAB: Temperature conversion In this lab, you will implement a temperature converter. Five UI elements are declared for you in the template: Element's ID Element description cInput Text input field for Celsius temperature fInput Text input field for Fahrenheit temperature convertButton Button that, when clicked, converts from one temperature to the other errorMessage Div for displaying an error message when temperature cannot be converted weatherImage Image corresponding to the temperature Implement the conversion functions (2 points) Implement the convertCtoF()...
Lab 11 C++ Download the attached program and run it - as is. It will prompt...
Lab 11 C++ Download the attached program and run it - as is. It will prompt for a Fibonacci number then calculate the result using a recursive algorithm. Enter a number less then 40 unless you want to wait for a very long time. Find a number that takes between 10 and 20 seconds. (10,000 - 20,000 milliseconds). Modify the program to use the static array of values to "remember" previous results. Then when the function is called again with...
Prompt: Explain the five types of budget authority
Prompt: Explain the five types of budget authority
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT