CookBook Class In this exercise, you are going to complete the CookBook class. public class CookBook { private ArrayList recipes; private String name; public CookBook(String name){ this.name = name; recipes = new ArrayList(); } /** * This method adds a recipe to the ArrayList of Recipes * @param recipe a recipe object to be added to the list */ public void addRecipe(Recipe recipe){ /* Implement this method */ } /** * This method removes all recipes from the * ArrayList of Recipes where the title matches the input * string * * @param title the title of the recipe to remove * @return the number of recipes removed */ public int removeRecipe(String title){ /* Implement this method */ } /** * This method lists the title of all the recipes in the * cook book * */ public void listAll(){ /* Implement this method */ } } The addRecipe method should take a recipe and add it to the end of the recipe ArrayList. The removeRecipe should take a recipe title and remove any recipe in the CookBook where the title matches the title that was passes in. If there is more than one title that matches the value passes, all should be removed. The method should then return the number of Recipe objects that were removed. Finally, complete the listAll method. This method should list the titles of all the recipes in the recipes ArrayList, each on a seperate line. import java.util.*; public class CookBook { private ArrayList recipes; private String name; public CookBook(String name){ this.name = name; recipes = new ArrayList(); } /** * This method adds a recipe to the ArrayList of Recipes * @param recipe a recipe object to be added to the list */ public void addRecipe(Recipe recipe){ /* Implement this method */ } /** * This method removes all recipes from the * ArrayList of Recipes where the title matches the input * string * * @param title the title of the recipe to remove * @return the number of recipes removed */ public int removeRecipe(String title){ /* Implement this method */ } /** * This method lists the title of all the recipes in the * cook book * */ public void listAll(){ /* Implement this method */ } } public class Recipe { private String title; public Recipe(String title){ this.title = title; } /** * This method returns the title of the recipe * @return the title of a recipe */ public String getTitle(){ return title; } } public class CookBookTester { public static void main(String[] args) { // Add code if you would like to test your methods } }
Use this exercise to test your code that you wrote in the previous exercise.
CookBook Class
In this exercise, you are going to complete the CookBook class.
public class CookBook { private ArrayList<Recipe> recipes; private String name; public CookBook(String name){ this.name = name; recipes = new ArrayList<Recipe>(); } /** * This method adds a recipe to the ArrayList of Recipes * @param recipe a recipe object to be added to the list */ public void addRecipe(Recipe recipe){ /* Implement this method */ } /** * This method removes all recipes from the * ArrayList of Recipes where the title matches the input * string * * @param title the title of the recipe to remove * @return the number of recipes removed */ public int removeRecipe(String title){ /* Implement this method */ } /** * This method lists the title of all the recipes in the * cook book * */ public void listAll(){ /* Implement this method */ } }The addRecipe method should take a recipe and add it to the end of the recipe ArrayList.
The removeRecipe should take a recipe title and remove any recipe in the CookBook where the title matches the title that was passes in. If there is more than one title that matches the value passes, all should be removed. The method should then return the number of Recipe objects that were removed.
Finally, complete the listAll method. This method should list the titles of all the recipes in the recipes ArrayList, each on a seperate line.
import java.util.*;
public class CookBook {
private ArrayList<Recipe> recipes;
private String name;
public CookBook(String name){
this.name = name;
recipes = new ArrayList<Recipe>();
}
/**
* This method adds a recipe to the ArrayList of Recipes
* @param recipe a recipe object to be added to the list
*/
public void addRecipe(Recipe recipe){
/* Implement this method */
}
/**
* This method removes all recipes from the
* ArrayList of Recipes where the title matches the input
* string
*
* @param title the title of the recipe to remove
* @return the number of recipes removed
*/
public int removeRecipe(String title){
/* Implement this method */
}
/**
* This method lists the title of all the recipes in the
* cook book
*
*/
public void listAll(){
/* Implement this method */
}
}
public class Recipe {
private String title;
public Recipe(String title){
this.title = title;
}
/**
* This method returns the title of the recipe
* @return the title of a recipe
*/
public String getTitle(){
return title;
}
}
public class CookBookTester
{
public static void main(String[] args)
{
// Add code if you would like to test your methods
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images