I would like some assistance with correcting the errors in this code. Please let me know if any additional information is needed.
I would like some assistance with correcting the errors in this code. Please let me know if any additional information is needed.
package Final;
import java.util.ArrayList;
/**
*
* @author rijackson
*/
public class RecipeBox {
//Single private instance field
private ArrayList<Recipe> listOfRecipes;
//Constructors
/**
*
*/
public RecipeBox() {
this.setListOfRecipes(new ArrayList<>());
}
/**
*
* @param listOfRecipes
*/
public RecipeBox(ArrayList<Recipe> listOfRecipes) {
this.setListOfRecipes(listOfRecipes);
}
//Accessor and mutator for list of recipes
/**
*
* @return list of recipes
*/
public ArrayList<Recipe> getListOfRecipes() {
return listOfRecipes;
}
/**
*
* @param listOfRecipes the list of recipes
*/
public void setListOfRecipes(ArrayList<Recipe> listOfRecipes) {
this.listOfRecipes = listOfRecipes;
}
//Method to add a new recipe to the list
/**
* method to add new recipe to the collection
*/
public void addNewRecipe() {
//call into static method on recipe class
this.listOfRecipes.add(Recipe.addNewRecipe());
}
//print all recipe names
/**
*
*/
public void printAllRecipeNames() {
for(Recipe r : listOfRecipes) { //iterate over list
System.out.println(r.getRecipeName()); //print the name
}
}
/**
*
* @param name
*/
public void printRecipeDetails(String name) {
Recipe r = findRecipe(name); //look for recipe
if(r == null) { //if none found, notify user
System.out.println(“Recipe not found”);
} else {
r.printRecipe();//print full details
}
}
/**
*
* @param name
*/
public void deleteRecipe(String name) {
Recipe r = findRecipe(name); //find recipe by name
if(r == null) { //if no match, notify user
System.out.println(“Recipe not found”);
} else {
listOfRecipes.remove(r); //remove recipe from list
}
}
//helper to find a recipe by name
//Returns null if no match is found
private Recipe findRecipe(String name) {
for(Recipe r : listOfRecipes) {
if(r.getRecipeName().equals(name)) {
return r;
}
}
return null;
}
}