Question: 9 . 1 2 LAB: Nutritional information ( classes / constructors ) Complete the Fooditem class by adding a constructor to initialize a food item.

9.12 LAB: Nutritional information (classes/constructors)
Complete the Fooditem class by adding a constructor to initialize a food item. The constructor should initialize the name (a string) to
"Water" and all other instance attributes to 0.0 by default. If the constructor is called with a food name, grams of fat, grams of
carbohydrates, and grams of protein, the constructor should assign each instance attribute with the appropriate parameter value.
The given program accepts as input a food item name, amount of fat, carbs, and protein, and the number of servings. The program creates
a food item using the constructor parameters' default values and a food item using the input values. The program outputs the nutritional
information and calories per serving for a food item.
Ex: If the input is:
Water
the output is:
Nutritional information per serving of Water:
Fat: 0.00g
Carbohydrates: 0.00g
Protein: 0.00g
Number of calories for 1.00 serving(s): 0.00
E
M&M's
10.0
34.0
2.0
3.0
where M&M's is the food name, 10.0 is the grams of fat, 34.0 is the grams of carbohydrates, 2.0 is the grams of protein, and 3.0 is the
number of servings, the output is:
Nutritional information per serving of M&M's:
Fat: 10.00g
Carbohydrates: 34.00g
Protein: 2.00g
Number of calories for 1.00 serving(s): 234.00
Number of calories for 3.00 serving(s): 702.00
Note: The program outputs the number of calories for one serving of a food and for the input number of servings as well. The program only
outputs the calories for one serving of water.
 9.12 LAB: Nutritional information (classes/constructors) Complete the Fooditem class by adding

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!