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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Question
100%

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

 
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education