Click here to Skip to main content
15,867,972 members
Please Sign up or sign in to vote.
2.65/5 (3 votes)
See more:
I am writing a program that will display the calorie and protein totals for selections from a school lunch menu! I'm trying to find a way to print a full table of the calorie + protein information of all the foods on the menu and determine the combo that is lowest in calories and highest in proteins! **Edit: I've resolved my issue, thanks everyone!
Posted
Updated 16-Nov-15 17:56pm
v10
Comments
Richard MacCutchan 11-Nov-15 15:42pm    
That is a question of simple logic. Iterate through the list of meals printing the relevant details. As you do so keep a running total of the various values and their associated foods. Once you have all the lists it is a simple matter to sort them into order and find the lowest and highest combinations.
gettysburggal63 11-Nov-15 19:47pm    
Thank you for your suggestion! I tried out making a JTable that would run through the values with the code under NutritionInformationPressed in my original post, but it doesn't print all the values like I wanted. Can you take a look?
Richard MacCutchan 12-Nov-15 3:05am    
You are using a single variable for both calorietotal and proteintotal so it is impossible to get the values for individual items.
gettysburggal63 12-Nov-15 20:59pm    
Hi, after looking up how to import an array into a JTable, it seems that using vectors worked for a lot of people. I tried it out and after modifying my code it works out perfect! :) Thanks so much for your help. The only thing I'm now stuck on is finding the best option, do you have suggestions for this?
Richard MacCutchan 13-Nov-15 3:29am    
You first have to decide what the best option is, e.g. low fat + high protein, high fruit + high grains etc. Then to find the combination you just go through each set looking for the value that meets the selection criteria. Once you have the values you can list the matching foods for the best meal choice.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900