Why pass a reference to a local variable: recipe to the calculateCostOfRecipe method. It does not need it to access the Map.
The constructor should use VarArgs and not expect exactly 3...
Type: Posts; User: Norm
Why pass a reference to a local variable: recipe to the calculateCostOfRecipe method. It does not need it to access the Map.
The constructor should use VarArgs and not expect exactly 3...
An Ingredient is not a Recipe. A Recipe has a list of Ingredients.
A SpicyRecipe could be a sub class of Recipe.
Can you post it so we can see if there are any other problems with it?
Go back and read that again. I didn't think he said that.
The fields in the classes should be private. Their values should be retrieved with a get method, not directly accessed.
Ok, so if the recipes are stored in a Map<name, ingredients> then
Use the entrySet method to iterate through all the entries in the Map giving access to each of the ingredient instances in the Map. ...
What is that loop supposed to do? Is it what I talked about in post#4?
Some comments on the code in post#1
Why is a reference to an instance of a Recipe passed to any method in the Recipe class?...
Is the above complete? Can you trying writing the code for it?
I think there needs to be a better definition of ingredient and the amount of the ingredient being used in the recipe.
For example: butter is an ingredient and 1/2 cup is the quantity being used. ...
How does the program need to access the ingredients?
Does it need to directly access one particular ingredient by name? If so use a Map<name, Ingredient>
If getting the ingredients one at a time...
When working with collections (and some other utility classes) it is better to use the interface instead of the class. For example use a Map to hold the <key, value> pairs. When initializing the...
Is this the logic:
The recipe has the list of ingredients and the amount needed of that ingredient.
Iterate through the list, get the type and amount of each ingredient,
lookup the unit cost of...
Look at using varargs. Here is an example:
public class TestVarArgs {
// a simple class to pass using varargs
static class Data {
String name;
int amt;
Data(String...