Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help with this project. The requirements are: Developing your own driver cl

ID: 3875272 • Letter: N

Question

Need help with this project. The requirements are:

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

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package SteppingStones;

import java.util.ArrayList;

/**

*

* @author snhu.edu

*/

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 " + "1. Add Recipe " + "2. Print All Recipe Details " + "3. Print All Recipe Names " + " Please select a menu item:");

while (menuScnr.hasNextInt() || menuScnr.hasNextLine()) {

System.out.println("Menu " + "1. Add Recipe " + "2. Print All Recipe Details " + "3. Print All Recipe Names " + " Please 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? ");

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(" Menu " + "1. Add Recipe " + "2. Print Recipe " + "3. Adjust Recipe Servings " + " Please 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? ");

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(" Menu " + "1. Add Recipe " + "2. Print Recipe " + "3. Adjust Recipe Servings " + " Please select a menu item:");

}

*

*/

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

}

  

}

}

Explanation / Answer

SteppingStone5_Recipe.java:

import java.util.Scanner;

import java.util.ArrayList;

/**

*

* @author

*/

public 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 static void main(String[] args) {

double totalRecipeCalories = 0;

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

boolean addMoreIngredients = true;

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

int servings = scnr.nextInt();

do {

System.out.println("Please enter the ingredient name"

+ " or type end if you are finished entering ingredients: ");

String ingredientName = scnr.next();

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

addMoreIngredients = false;

} else {

recipeIngredients.add(ingredientName);

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

float ingredientAmount = scnr.nextFloat();

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

int ingredientCalories = scnr.nextInt();

totalRecipeCalories += (ingredientCalories * ingredientAmount);

}   

} while(addMoreIngredients);

SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe(recipeName,

servings, recipeIngredients, totalRecipeCalories);

recipe1.printRecipe();

  

scnr.close();

}

}

SteppingStone6_RecipeBox.java:

import java.util.ArrayList;

import java.util.Scanner;

/**

*

* @author

*/

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) {

this.listOfRecipes = listOfRecipes;

}

  

public SteppingStone6_RecipeBox() {

this.listOfRecipes = new ArrayList<>();

}

/**

* 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

*

*/

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

}

  

void printAllRecipeNames(){

for(SteppingStone5_Recipe selectedRecipe: listOfRecipes) {

System.out.println(selectedRecipe.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 recipeBox = new SteppingStone6_RecipeBox();

  

//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 " + "1. Add Recipe " + "2. Print All Recipe Details " + "3. Print All Recipe Names " + " Please select a menu item:");

while (menuScnr.hasNextInt() || menuScnr.hasNextLine()) {

System.out.println("Menu " + "1. Add Recipe " + "2. Print All Recipe Details " + "3. Print All Recipe Names " + " Please 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 code 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? ");

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(" Menu " + "1. Add Recipe " + "2. Print Recipe " + "3. Adjust Recipe Servings " + " Please 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? ");

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(" Menu " + "1. Add Recipe " + "2. Print Recipe " + "3. Adjust Recipe Servings " + " Please select a menu item:");

}

  

*

*/

  

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

}   

}

}

Please hit upvote, if you liked the solution. Thanks!