Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help cleaning up Java code. I have put together the following classes, but I keep receiving errors for the Recipe.java class. Below is my

Need help cleaning up Java code. I have put together the following classes, but I keep receiving errors for the Recipe.java class. Below is my code, and the errors I am receiving. Thanks in advance for any help you can provide!

package recipecollection;

import java.util.Scanner;

import java.util.ArrayList;

/**

*

* @author

*/

public class Recipe {

private String recipeName;

private int servings;

private ArrayList recipeIngredients;

private double totalRecipeCalories;

/**

* @return the recipeName

*/

public String getRecipeName() {

return recipeName;

}

/**

* @param recipeName the recipeName to set

*/

public void setRecipeName(String recipeName) {

this.recipeName = recipeName;

}

/**

* @return the servings

*/

public int getServings() {

return servings;

}

/**

* @param servings the servings to set

*/

public void setServings(int servings) {

this.servings = servings;

}

/**

* @return the recipeIngredients

*/

public ArrayList getRecipeIngredients() {

return recipeIngredients;

}

/**

* @param recipeIngredients the recipeIngredients to set

*/

public void setRecipeIngredients(ArrayList recipeIngredients) {

this.recipeIngredients = recipeIngredients;

}

/**

* @return the totalRecipeCalories

*/

public double getTotalRecipeCalories() {

return totalRecipeCalories;

}

/**

* @param totalRecipeCalories the totalRecipeCalories to set

*/

public void setTotalRecipeCalories(double totalRecipeCalories) {

this.totalRecipeCalories = totalRecipeCalories;

}

public Recipe() {

this.recipeName = "";

this.servings = 0;

this.recipeIngredients = new ArrayList();

this.totalRecipeCalories = 0;

}

public Recipe(String recipeName, int servings, ArrayList recipeIngredients, double totalRecipeCalories) {

this.recipeName = recipeName;

this.servings = servings;

this.recipeIngredients = recipeIngredients;

this.totalRecipeCalories = totalRecipeCalories;

}

public void printRecipe() {

double singleServingCalories = totalRecipeCalories / servings;

System.out.println("Recipe: " + getRecipeName());

System.out.println("Yield: " + getServings() + " servings");

System.out.println("Ingredients:");

/*

for (Ingredient currentIngredient: recipeIngredients)

System.out.println(currentIngredient.getIngredientName());

*/

for (int i = 0; i

Ingredient currentIngredient = recipeIngredients.get(i);

String currentIngredientName = currentIngredient.getIngredientName();

System.out.println(currentIngredientName);

}

System.out.println("Total Calories per serving: " + singleServingCalories);

}

public Recipe createNewRecipe() { //Comment out for Stepping Stone 6

//public SteppingStone5_Recipe createNewRecipe() { //uncomment for Stepping Stone 6

double totalRecipeCalories = 0;

ArrayList recipeIngredients = new ArrayList();

boolean addMoreIngredients = true;

Scanner scnr = new Scanner(System.in);

System.out.println("Please enter the recipe name: ");

String recipeName = scnr.nextLine();

System.out.println("How many servings: ");

int servings = scnr.nextInt();

do {

System.out.println("Please enter the ingredient name or type 'end' if you are done: ");

String ingredientName = scnr.next();

if (ingredientName.toLowerCase().equals("end")) {

addMoreIngredients = false;

}

else {

Ingredient tempIngredient = new Ingredient().addIngredient(ingredientName);

recipeIngredients.add(tempIngredient);

}

} while (addMoreIngredients);

for (int i = 0; i

Ingredient currentIngredient = recipeIngredients.get(i);

float ingredientAmount = currentIngredient.getIngredientAmount();

int ingredientCalories = currentIngredient.getIngredientCalories();

double ingredientTotalCalories = ingredientAmount * ingredientCalories;

totalRecipeCalories += ingredientTotalCalories;

}

Recipe newRecipe = new Recipe(recipeName, servings, recipeIngredients, totalRecipeCalories);

/ewRecipe.printRecipe();//comment out for Stepping Stone 6

return newRecipe; //uncomment for Stepping Stone 6

}

}

On this one I keep receiving the following errors:

image text in transcribed

image text in transcribed

116 no suitable method found for add(lngredient) 119 120 121 122 123 124 125 126 127 128 method Collection.add(String) is not applicable (argument mismatch; Ingredient cannot be converted to String) method List.add(String) is not applicable (argument mismatch; Ingredient cannot be converted to String) method AbstractCollection.addString) is not applicable (argument mismatch; Ingredient cannot be converted to String) method AbstractList.add(String) is not applicable (argument mismatch; Ingredient cannot be converted to String) method ArrayList.add(String) is not applicable (argument mismatch; Ingredient cannot be converted to String) he ingredient name or type 'end' if you quals ("end" Alt-Enter shows hints w Ingredient ) addIngredient (ingredient recipeIngredients.add (tempIngredient 130 131 132 133 while (addMoreIngredients) for (int 1 0;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

which of the following is an example of financial incentive?

Answered: 1 week ago