Search:

Type: Posts; User: Ian_dude

Search: Search took 0.06 seconds.

  1. [SOLVED] Re: How to iterate through an array that contains null elements

    WOW!

    You are blowing my mind!

    So now if I leave the default constructor to build a 'recipe' and populate the array the program gives me a "null" when i ask for the name of a recipe entry that...
  2. [SOLVED] Re: How to iterate through an array that contains null elements

    Norm,

    Conceptually what you say I understand but I guess I dont since I dont know how to do what you mean.

    Where do I have to delete/or/modify?

    Thank you,

    Ian
  3. [SOLVED] Re: How to iterate through an array that contains null elements

    Norm,

    breakfastRecipes is not a variable, its a field in the Planner Class.

    I will post all the code ( I have a Main a, Ingredient, a Recipe, and a Planner class in the same package.
    I...
  4. [SOLVED] Re: How to iterate through an array that contains null elements

    Norm,


    I have created a planner called july5 and added a recipe called stirFry
    this is the code in main:


    Planner july5 = new Planner(6, 7, 2021);
    july5.addRecipe(stirFry, 0);
  5. [SOLVED] Re: How to iterate through an array that contains null elements

    Hi Norm,

    Yes:

    How come even when I use my default constructor and I populate the array completely with a "recipe" in each slot of he array I still get a "is null" error.

    Then I made a more...
  6. [SOLVED] Re: How to iterate through an array that contains null elements

    Norm,

    That totally worked! I cant understand why this wasn't easier to find online.

    I have kind of the same issue still although for sure I am doing something wrong.

    This is my meal...
  7. [SOLVED] How to iterate through an array that contains null elements

    I have a bunch of code that works.
    The program is giving me an error wen I run it and it says:

    Cannot read field "costOf" because "array[1]" is null

    I have done this with a for each loop and...
  8. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    Thanks for the class/subclass answer.
    The loop code is in a post above (post 21)

    But here is the code and I added a add1Ingredient() method to the recipe which updates the cost as well.
    I also...
  9. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    Norm,

    Post 5 "I think you need to establish your abstractions and classes properly. An Ingredient certainly doesn't extend Recipe. A Recipe is composed of ingredients. You might consider...
  10. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    I am so happy Norm:

    public static double calculateCostOfRecipe(HashMap<Ingredient, Double> recipe){
    // loops through the hashmap and multiplies the amount and unit price
    double...
  11. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    Norm,

    Yes it is what you are talking about in post #4.
    You may as well ignore the code I have for the 2 attempts at creating the method called "calculateRecipeCost"
    since they don't work and I...
  12. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    Gozzy,

    I am not very experienced with Java as you can tell but I though I had it well specked out. But obviously not.
    I acually have 2 enums in my Ingredient Class
    public enum UnitPurchased {...
  13. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    Norm,

    In my original post above I copied the code for the Ingredient Class and for the Recipe Class and for the Main which uses the classes for now. I tried to write a for each loop in several...
  14. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    I though I had the design figured out but I am new at this and most likely my design has some serious flaws.

    Right now as it stands the ingredient lets call it avocado (since I have it in the...
  15. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    Norm,
    The program should be able to add ingredients.
    The program will need to "know" if the ingredient exists and if it does then it does need to access the ingredient by name (I think that's the...
  16. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    I will look at the interface vs class (since I don't understand that very well).

    So the hashmap is an element of the recipe instance which holds the ingredient (so I'm guessing I could access all...
  17. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    Norm,

    Yes, although when you say "get the type and amount of each ingredient"
    I would say get the costPerUnit (since the Ingredient instance has a costPerUnit) and amount needed for the recipe...
  18. [SOLVED] Re: Trying to iterate through hashmap of objects from a class I created

    Norm,
    Thank you for the answer.

    I will look into the varargs for sure.
    Do you have any input on the question on how to get to the ingredient say for example "avocado.costPerUnit" from having...
  19. [SOLVED] Trying to iterate through hashmap of objects from a class I created

    I am trying to calculate the cost of a "Recipe" object which contains a hashmap<Ingredient, Double>
    I have created the Ingredient class which contains pricePerUnit as one of its values.
    The Double...
Results 1 to 19 of 19