Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

When I run the following code I get chicken as an ingredient under my mac and cheese recipe and also get macaroni as an ingredient

When I run the following code I get chicken as an ingredient under my mac and cheese recipe and also get macaroni as an ingredient for my fried chicken recipe.  I need help in reversing this order, what am I not seeing here?  Thanks!

 

package SteppingStones;

 

import java.util.ArrayList;

 

public class RecipeTest {

/**
 * @param args the command line arguments --- in case you use
 */
public static void main(String[] args) {

 

/* Creating first recipe object for Recipe class */
 Recipe myFirstRecipe = new Recipe();

 

/* Creating array lists for first recipe ingredients */
 ArrayList recipeIngredientsOne = new ArrayList<>();

 

 /* Ingeredients that will be added */
 String ingredientName = "Macaroni";

 

 /* Adding ingredients for first recipe */
 recipeIngredientsOne.add(ingredientName);

 

/* Creating second recipe object for Recipe class with parameters */
 Recipe mySecondRecipe = new Recipe("Fried Chicken", 2, recipeIngredientsOne, 700);

 

/* Creating array lists for second recipe ingredients */
 ArrayList recipeIngredientsTwo = new ArrayList<>();

 

/* Ingeredients that will be added */
 String ingredientName2 = "Chicken";

 

/* Adding ingredients for second recipe */
 recipeIngredientsTwo.add(ingredientName2);

 

 /* Calling mutators with the first recipe object */
 myFirstRecipe.setRecipeName("Mac and Cheese");
 myFirstRecipe.setServings(3);
 myFirstRecipe.setRecipeIngredients(recipeIngredientsTwo);
 myFirstRecipe.setTotalRecipeCalories(400);

 

// Print details of both recipes
 myFirstRecipe.printRecipe();
 mySecondRecipe.printRecipe();
}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Answer In your code you are mistakenly setting the same recipeIngredients list for both recipes This ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Statistics And Data Analysis For Financial Engineering

Authors: David Ruppert

1st Edition

1461427495, 978-1461427490

More Books

Students also viewed these Programming questions