I was looking fo some Java help with the highlighted sections below:
package SteppingStones; import java.util.ArrayList; /** * * @author */ 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("Menun" + "1. Add Recipen" + "2. Print All Recipe Detailsn" + "3. Print All Recipe Namesn" + "nPlease select a menu item:"); while (menuScnr.hasNextInt() || menuScnr.hasNextLine()) { System.out.println("Menun" + "1. Add Recipen" + "2. Print All Recipe Detailsn" + "3. Print All Recipe Namesn" + "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("nMenun" + "1. Add Recipen" + "2. Print Recipen" + "3. Adjust Recipe Servingsn" + "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("nMenun" + "1. Add Recipen" + "2. Print Recipen" + "3. Adjust Recipe Servingsn" + "nPlease select a menu item:"); } * */ System.out.println("Menun" + "1. Add Recipen" + "2. Print All Recipe Detailsn" + "3. Print All Recipe Namesn" + "nPlease select a menu item:"); } } }
Expert Answer
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(“Menun” + “1. Add Recipen” + “2. Print All Recipe Detailsn” + “3. Print All Recipe Namesn” + “nPlease select a menu item:”);
while (menuScnr.hasNextInt() || menuScnr.hasNextLine()) {
System.out.println(“Menun” + “1. Add Recipen” + “2. Print All Recipe Detailsn” + “3. Print All Recipe Namesn” + “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 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?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(“nMenun” + “1. Add Recipen” + “2. Print Recipen” + “3. Adjust Recipe Servingsn” + “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(“nMenun” + “1. Add Recipen” + “2. Print Recipen” + “3. Adjust Recipe Servingsn” + “nPlease select a menu item:”);
}
*
*/
System.out.println(“Menun” + “1. Add Recipen” + “2. Print All Recipe Detailsn” + “3. Print All Recipe Namesn” + “nPlease select a menu item:”);
}
}
}