Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Advice on how to design a meal planner: classes

  1. #1
    Junior Member
    Join Date
    Jun 2021
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Advice on how to design a meal planner: classes

    Hi,
    I am beginning to program and as an exercise I want to convert a meal planner I made in excel (with vba) to a Java app.

    I want to have "ingredients" which have certain properties like: name, organic (true/false), cost purchased, unit as purchased, cost per unit (calculated field) etc.

    I want to have "recipes" which hold ingredients and the recipe (class I would imagine) would have to hold the I gredients and the amount required using the unit used with the cost per unit (I don't know how to do this) it would also be able to calculate the cost of the recipe based on the amount for each ingredient and access the cost per unit of that ingredient.

    I eventually would like to have each instance of recipe have a date so that I can have a calendar and I could repeat recipes in a period of time.

    My questions are how do I conceptualize this and how do I make it so that a recipe can hold the ingredients (class/subclass or inheritance etc) also if I create a recipe say baked potatoes and then I want to eat that again how do I create 2 instances of the same recipe but for different days.

    I don't have much code so I don't think posting it would make a difference.

    A secondary question would be. If I turn off the program it will "forget everything" I'm guessing so how can I store my meal plan somewhere where the program can "know it" when it gets turned back on.

    Thank you very much for your time.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Advice on how to design a meal planner: classes

    The "ingredients" and "recipes" sound like they should be classes with variables to hold values and get and set methods to access those variables.

    A simple way to save the contents of the classes would be to write them to a disk file. Later, when you have more experience, you would use a database to hold the data.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jun 2021
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Advice on how to design a meal planner: classes

    Norm,
    Thank you for your time.
    How would the "recipe" class instance hold a bunch of "ingredient" instances with the respective quantity per ingredient? Ideally you could add and delete ingredients from the recipe.

    Thank you again

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Advice on how to design a meal planner: classes

    hold a bunch of "ingredient" instances
    You could use an ArrayList to hold instances of the ingredient class.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jun 2021
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Advice on how to design a meal planner: classes

    Norm,

    Thank you for pointing me in the right direction.

    Ian

Similar Threads

  1. [SOLVED] Dorm and Meal Plan Calculator
    By Caffeine in forum Java Theory & Questions
    Replies: 5
    Last Post: July 3rd, 2014, 04:11 PM
  2. Replies: 4
    Last Post: April 4th, 2014, 12:10 PM
  3. classes design for Multithreading situation
    By harry7ster in forum Threads
    Replies: 2
    Last Post: October 9th, 2013, 08:12 AM
  4. How would you design the relationship between these two classes?
    By jrahhali in forum Object Oriented Programming
    Replies: 5
    Last Post: March 10th, 2012, 09:50 PM
  5. Social Planner-Arrays and Super and Sub Classes
    By Laxman2809 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 15th, 2011, 03:03 PM

Tags for this Thread