Search:

Type: Posts; User: Norm

Search: Search took 0.20 seconds.

  1. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    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...
  2. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    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?
  3. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    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.
  4. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    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. ...
  5. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    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?...
  6. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    Is the above complete? Can you trying writing the code for it?
  7. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    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. ...
  8. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    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...
  9. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    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...
  10. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    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...
  11. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    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...
Results 1 to 11 of 11