Question

*Please Add Inline Comments Directed toward software engineers about design decisions to facilitate the programs ongoing...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1
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:");
        }
    }
}
Add a comment
Know the answer?
Add Answer to:
*Please Add Inline Comments Directed toward software engineers about design decisions to facilitate the programs ongoing...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I cannot submit my entire project due to the word count limit. I think my project...

    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...

  • Prompt: In this stepping stone lab assignment, you will build a Recipe class, getting user input...

    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...

    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...

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

  • 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 sh...

    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...

  • 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 conditiona...

    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...

  • Can you help me rearrange my code by incorporating switch I'm not really sure how to...

    Can you help me rearrange my code by incorporating switch I'm not really sure how to do it and it makes the code look cleaner. Can you help me do it but still give the same output? Also kindly add an in-line comment on what changes and rearrangement you've done so I can understand what's going on. import java.util.ArrayList; import java.util.Scanner; public class Bank { /** * Add and read bank information to the user. * @param arg A string,...

  • A teacher wants to create a list of students in her class. Using the existing Student...

    A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...

  • Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class...

    Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class Delete extends Info { String name; int Id; int del; public Delete() { } public void display() { Scanner key = new Scanner(System.in); System.out.println("Input Customer Name: "); name = key.nextLine(); System.out.println("Enter ID Number: "); Id = key.nextInt(); System.out.println("Would you like to Delete? Enter 1 for yes or 2 for no. "); del = key.nextInt(); if (del == 1) { int flag = 0; //learned...

  • Grocery shopping list (LinkedList)

    Given a ListItem class, complete main() using the built-in LinkedList type to create a linked list called shoppingList. The program should read items from input (ending with -1), adding each item to shoppingList, and output each item in shoppingList using the printNodeData() method.Ex. If the input is:the output is:--ShoppingList.java:import java.util.Scanner;import java.util.LinkedList;public class ShoppingList {   public static void main (String[] args) {      Scanner scnr = new Scanner(System.in);      // TODO: Declare a LinkedList called shoppingList of type ListItem      String...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT