*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;
}
/**
* 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() {
//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 code should remain uncommented when using the
* SteppingStone6_RecipeBox_tester.
*
* Comment out this section when using the
* public static main() method
*/
if (input == 1) {
//new Recipe();
} 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:");
}
}
}
import java.util.ArrayList;
import java.util.Scanner;
public class SteppingStone6_RecipeBox {
// as there can be multiple recipes in a box, we are taking it as arraylist
// because arraylist gives us option of random access.
private ArrayList<SteppingStone5_Recipe> listOfRecipes;
// Parameterized Constructors
public SteppingStone6_RecipeBox(
ArrayList<SteppingStone5_Recipe> listOfRecipes) {
this.listOfRecipes = listOfRecipes;
}
// Default constructor
public SteppingStone6_RecipeBox() {
// create new arraylist, as none is passed from user side
this.listOfRecipes = new ArrayList<>();
}
// Getter methods
public ArrayList<SteppingStone5_Recipe> getListOfRecipes() {
return listOfRecipes;
}
// Setter methods
public void setListOfRecipes(ArrayList<SteppingStone5_Recipe> listOfRecipes) {
this.listOfRecipes = listOfRecipes;
}
// This method prints a selected recipe details
// If recipe is not found in the box, we return a error message.
void printAllRecipeDetails(String selectedRecipe){
// iterate on all recipes
for(SteppingStone5_Recipe recipe: listOfRecipes) {
// if found matching one
if(recipe.getRecipeName().equalsIgnoreCase(selectedRecipe)) {
recipe.printRecipe();
return;
}
}
System.out.println("No Recipe found with name: " + selectedRecipe);
}
// this method iterates on list of recipes and print their details
void printAllRecipeNames(){
for(SteppingStone5_Recipe selectedRecipe: listOfRecipes) {
System.out.println(selectedRecipe.getRecipeName());
}
}
// this method is used to add a new recipe into the box
public void addRecipe(SteppingStone5_Recipe tmpRecipe) {
listOfRecipes.add(tmpRecipe);
}
public void menu() {
// Scanner to take user choices as input
Scanner menuScnr = new Scanner(System.in);
// show menu choices to user
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:");
// Till the time user input is available, keep working
while (menuScnr.hasNextInt() || menuScnr.hasNextLine()) {
// take user choice
int input = menuScnr.nextInt();
// If user wants to create a new Recipe
if (input == 1) {
//new Recipe();
} else if (input == 2) {
// if user wants to see the details of some recipe
System.out.println("Which recipe?\n");
String selectedRecipeName = menuScnr.next();
printAllRecipeDetails(selectedRecipeName);
} else if (input == 3) {
// if user wants to see the names of all recipes in the box
for (int j = 0; j < listOfRecipes.size(); j++) {
System.out.println((j + 1) + ": " + listOfRecipes.get(j).getRecipeName());
}
} else {
// user selected choice is invalid.
System.out.println("Invalid choice.");
}
// show menu for next round
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:");
}
}
}
*Please Add Inline Comments Directed toward software engineers about design decisions to facilitate the programs ongoing...
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...
I'm getting a few errors still under RecipeBox. Would you be able to see what's wrong? Thanks ------------ package recipecollection; import java.util.ArrayList; public class SteppingStone5_RecipeTest { public static void main(String[] args) { ArrayList<String> recipeIngredients = new ArrayList<>(); recipeIngredients.add("Peanut butter"); recipeIngredients.add("Jelly"); recipeIngredients.add("Bread"); SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe("Peanut butter & jelly sandwich", 2, recipeIngredients, 300, 10.0); System.out.println("RECIPE 1"); recipe1.printRecipe(); System.out.println(); recipe1.setRecipeName("Turkey sandwich"); recipe1.setServings(5); recipe1.setTotalRecipeCalories(500); System.out.println(); System.out.println("RECIPE 1 (Modified)"); recipe1.printRecipe(); System.out.println(); System.out.println("RECIPE 2"); SteppingStone5_Recipe recipe2 = SteppingStone5_Recipe.createNewRecipe(); recipe2.printRecipe(); } } ///////////////// package recipecollection;...
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...
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 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; /** * *...
I would like someone to check my code and help with my for loop to print the recipe. It is incorrect. package SteppingStones; import java.util.Scanner; //Scanner class// import java.util.ArrayList; //ArrayList// import ingredients.Ingredient; /**Gets from package ingredients and class Ingredient * * @author kimbe */ public class SteppingStone5_Recipe { //Instance Variables// private ArrayList recipeIngredients; private String recipeName; private int servings; private double totalRecipeCalories; //Setter and Getters// public ArrayList getrecipeIngredients() { return recipeIngredients; }...
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...
To do: Now add code to Pet and PetPlay to complete the comments in the code. import java.util.ArrayList; public class PetPlay { //----------------------------------------------------------------- // Stores and modifies a list of pets //----------------------------------------------------------------- public static void main (String[] args) { // always make your array lists generic ArrayList pets = new ArrayList(); pets.add(new Pet("dog", "Bella")); pets.add(new Pet("cat","Blackie")); pets.add(new Pet("bird", "Babs")); pets.add(new Pet("dog", "Lassie")); pets.add(new Pet("horse", "Sam")); pets.add(new Pet("dog", "Blackie")); pets.add(new Pet("turtle", "Joe")); pets.add(new Pet("bird","Annie")); pets.add(new Pet("bird", "Alex"));...
Add another method public static void displayObject(ArrayList list, int n) that will display then information on the nth object of list. If n is not a valid index, the method should generate and throw and exception that the main can then process. You get to decide what exception (one built into Java or a custom exception) and how you would like to “handle” the exception (terminate the program, prompt for more input, etc). Here is the program so far: import...
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...