Question
I need help answering this question public class SteppingStone6_RecipeBox { /** * Declare instance variables: * a private ArrayList of the type SteppingStone5_Recipe named listOfRecipes
I need help answering this question
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:");
}
}
}
/**
*
* 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.
*
*/
here is stepping stone 5 lab
import java.util.ArrayList;
/**
* Ingredient class :
* items that will be stored in each recipe
*
*/
public class Ingredient {
//variables
private String ingredientName;
private double ingredientAmount;
private String unitMeasurement;
private double totalCalories;
public Ingredient() {
}
//constructor
public Ingredient(String ingredientName, double ingredientAmount, String unitMeasurement, double totalCalories) {
super();
this.ingredientName = ingredientName;
this.ingredientAmount = ingredientAmount;
this.unitMeasurement = unitMeasurement;
this.totalCalories = totalCalories;
}
//Seter and getter
public String getIngredientName() {
return ingredientName;
}
public void setIngredientName(String ingredientName) {
this.ingredientName = ingredientName;
}
public double getIngredientAmount() {
return ingredientAmount;
}
public void setIngredientAmount(double ingredientAmount) {
this.ingredientAmount = ingredientAmount;
}
public String getUnitMeasurement() {
return unitMeasurement;
}
public void setUnitMeasurement(String unitMeasurement) {
this.unitMeasurement = unitMeasurement;
}
public double getTotalCalories() {
return totalCalories;
}
public void setTotalCalories(double totalCalories) {
this.totalCalories = totalCalories;
}
//print item detail
public void printItemDetails() {
System.out.println("ingredientName " + this.ingredientName);
System.out.println("ingredientAmount " + this.ingredientAmount);
System.out.println("totalCalories " + this.totalCalories);
System.out.println("unitMeasurement " + this.unitMeasurement);
}
}
import java.util.ArrayList;
/**
* Recipe class :
* create one recipe
*
*/
public class Recipe {
//variables
private ArrayList
private ArrayList
private String recipeName;
private int servings;
private double totalRecipeCalories;
//constructor
public Recipe(String recipeName,int servings) {
this.recipeName = recipeName;
this.recipeIngredients = new ArrayList<>();
this.instructions = new ArrayList<>();
this.servings = servings;
this.totalRecipeCalories = 0;
}
//get IngredientList
public ArrayList
return recipeIngredients;
}
//set IngredientList
public void setIngredientList(ArrayList
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){
return new Recipe(recipeName,servings);
}
//insert instruction
public boolean insertInstruction(String instruction){
return this.instructions.add(instruction);
}
public void printInstruction(){
instructions.toString();
}
}
mport java.util.ArrayList;
/**
* SteppingStone5_Recipe_Test class :
* collection of recipe
*
*/
public class SteppingStone5_Recipe_Test {
private ArrayList
public SteppingStone5_Recipe_Test() {
this.recipes = new ArrayList<>();
}
//add a Recipe in collection
public void addItem(Recipe recipe){
recipes.add(recipe);
}
//delete a Recipe in collection
public void deleteItem(Recipe recipe){
recipes.remove(recipe);
}
//print all recipes
public void printAllRecipies(){
int i = 0;
for(Recipe rec: recipes){
i++;
System.out.println("Recipe " + i);
rec.printRecipe();
}
}
public static void main(String[] args) {
//create some demo recipes
Recipe recipe1 = Recipe.createNewRecipe("Pizza", 4);
Ingredient ingredient1 = new Ingredient("Onions",20,"gram",300);
recipe1.addIngredient(ingredient1);
Recipe recipe2 = Recipe.createNewRecipe("Bacon", 2);
Ingredient ingredient2 = new Ingredient("Noodles",50,"gram",200);
recipe2.addIngredient(ingredient2);
// add in box
SteppingStone5_Recipe_Test box = new SteppingStone5_Recipe_Test();
box.addItem(recipe1);
box.addItem(recipe2);
box.printAllRecipies();
}
}
Step 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