Question: public class Ingredient { private String kind = Salt; private double quantity = 0.2; private String name; public Ingredient() { kind = Salt; quantity =

public class Ingredient { private String kind = "Salt"; private double quantity = 0.2; private String name;

public Ingredient() { kind = "Salt"; quantity = 0.2; }

public Ingredient(String n, double q) { if (n != null && !n.equals("") && !n.equals(" ")) { name = n; } if (q > 0) { quantity = q; } }

public String getKind() { return kind; }

public void setKind(String kind) { if (kind != null && !kind.equals("") && !kind.equals(" ")) { this.kind = kind; } }

public double getQuantity() { return quantity; }

public void setQuantity(double quantity) { if (quantity > 0) { this.quantity = quantity; } }

public String getName() { return name; }

public void setName(String name) { if (name != null && !name.equals("") && !name.equals(" ")) { this.name = name; } } }

public class Recipe { private String name = "Lamb Sauce"; private int prepTime = 60; private int numServings = 8; private Ingredient[] ingredients = new Ingredient[1];

public Recipe() { name = "Lamb Sauce"; prepTime = 60; numServings = 8; ingredients[0] = new Ingredient(); }

public Recipe(String n, int p, int nS, Ingredient[] i) { if (n != null && !n.equals("") && !n.equals(" ")) { name = n; } if (p > 0) { prepTime = p; } if (nS > 0) { numServings = nS; } if (i == null) { ingredients[0] = new Ingredient(); } else { ingredients = i; } }

public String getName() { return name; }

public void setName(String name) { if (name != null && !name.equals("") && !name.equals(" ")) { this.name = name; } }

public int getPrepTime() { return prepTime; }

public void setPrepTime(int prepTime) { if (prepTime > 0) { this.prepTime = prepTime; } }

public int getNumServings() { return numServings; }

public void setNumServings(int numServings) { if (numServings > 0) { this.numServings = numServings; } }

public Ingredient[] getIngredients() { return ingredients; }

public void setIngredients(Ingredient[] ingredients) { if (ingredients == null) { this.ing redients[0] = new Ingredient(); } else { this.ingredients = ingredients; } }

public Ingredient dominantIngredient() { Ingredient max = ingredients[0]; for (int i = 0; i < ingredients.length; i++) { if (ingredients[i].getQuantity() > max.getQuantity()) { max = ingredients[i]; } } return max; }

public void scaleRecipe(int factor) { if (factor > 0) { prepTime *= factor; numServings *= factor; for (int i = 0; i < ingredients.length; i++) { ingredients[i].setQuantity(ingredients[i].getQuantity() * factor); } } } }

public class Chef { private String name = "Gordon Ramsay"; private String specialty = "Lamb Sauce"; private Recipe[] recipes = new Recipe[1];

public Chef() { recipes[0] = new Recipe(); }

public Chef(String n, String s, Recipe[] r) { if (n != null && !n.equals("") && !n.equals(" ")) { name = n; } if (s != null && !s.equals("") && !s.equals(" ")) { specialty = s; } if (r == null) { recipes[0] = new Recipe(); } else { recipes = r; } }

public String getName() { return name; }

public void setName(String name) { if (name != null && !name.equals("") && !name.equals(" ")) { this.name = name; } }

public String getSpecialty() { return specialty; }

public void setSpecialty(String specialty) { if (specialty != null && !specialty.equals("") && !specialty.equals(" ")) { this.specialty = specialty; } }

public Recipe[] getRecipes() { return recipes; }

public void setRecipes(Recipe[] recipes) { if (recipes == null) { this.recipes[0] = new Recipe(); } else { this.recipes = recipes; } }

public void cook(int recipeIndex) { if (recipeIndex < 0 || recipeIndex >= recipes.length) { System.out.println("What is this nonsense? Get out of my kitchen, I won't make that!"); } else { if (recipes[recipeIndex].getName().equals(specialty)) { recipes[recipeIndex].setPrepTime(recipes[recipeIndex].getPrepTime() / 2); } System.out.println("Bon Appetit! Using "); for (int i = 0; i < recipes[recipeIndex].getIngredients().length; i++) { System.out.println(recipes[recipeIndex].getIngredients()[i].getQuantity() + " grams of " + recipes[recipeIndex].getIngredients()[i].getName()); } System.out.println("I, " + name + ", finished cooking " + recipes[recipeIndex].getName() + " after " + recipes[recipeIndex].getPrepTime() + " minute(s). This can serve " + recipes[recipeIndex].getNumServings() + " people.");

} }

public void cater(int numPeople) { for (int i = 0; i < recipes.length; i++) { if (recipes[i].getNumServings() >= numPeople) { if (recipes[i].getName().equals(specialty)) { recipes[i].setPrepTime(recipes[i].getPrepTime() / 2); } System.out.println("Bon Appetit! Using "); for (int j = 0; j < recipes[i].getIngredients().length; j++) { System.out.println(recipes[i].getIngredients()[j].getQuantity() + " grams of " + recipes[i].getIngredients()[j].getName()); } System.out.println("I, " + name + ", finished cooking " + recipes[i].getName() + " after " + recipes[i].getPrepTime() + " minute(s). This can serve " + recipes[i].getNumServings() + " people."); } } System.out.println("My gran could do better... than me?!"); } }

public class Kitchen { public static void main(String[] args) { Ingredient[] ingredients = new Ingredient[1]; ingredients[0] = new Ingredient("Salt", 0.2); Recipe[] recipes = new Recipe[1]; recipes[0] = new Recipe("Lamb Sauce", 60, 8, ingredients); Chef chef = new Chef("Gordon Ramsay", "Lamb Sauce", recipes); chef.cook(0); chef.cater(100); } }

Test Failed! org.opentest4j.AssertionFailedError: The 2 compared Strings were different by a factor of 17 characters. The acceptable distance is 5 characters. Here is the expected String: Bon Appetit! Using

5.5 grams of Rice

2.2 grams of Peas

1.0 grams of Chicken

I, Lucas, finished cooking Arroz Con Pollo after 90 minute(s). This can serve 5 people., and here was the String from your output: Bon Appetit! Using

5.5 grams of null

2.2 grams of null

1.0 grams of null

I, Lucas, finished cooking Arroz Con Pollo after 90 minute(s). This can serve 5 people.

How to fix this error?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!