Nutritional information (classes/constructors) PYTHON ONLY Complete the FoodItem class by adding a constructor to initialize a food item. The constructor should initialize the name (a string) to "None" 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, 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 both food items. Ex: If the input is: M&M's 10.0 34.0 2.0 1.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 1.0 is the number of servings, the output is:   Nutritional information per serving of None: Fat: 0.00 g Carbohydrates: 0.00 g Protein: 0.00 g Number of calories for 1.00 serving(s): 0.00 Nutritional information per serving of M&M's: Fat: 10.00 g Carbohydrates: 34.00 g Protein: 2.00 g Number of calories for 1.00 serving(s): 234.00

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question

Nutritional information (classes/constructors) PYTHON ONLY

Complete the FoodItem class by adding a constructor to initialize a food item. The constructor should initialize the name (a string) to "None" 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, 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 both food items.

Ex: If the input is:

M&M's
10.0
34.0
2.0
1.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 1.0 is the number of servings, the output is:
 

Nutritional information per serving of None:

Fat: 0.00 g
Carbohydrates: 0.00 g
Protein: 0.00 g
Number of calories for 1.00 serving(s): 0.00

Nutritional information per serving of M&M's:

Fat: 10.00 g
Carbohydrates: 34.00 g
Protein: 2.00 g
Number of calories for 1.00 serving(s): 234.00

zy Section 9.10 - CSC 1110: Progran X
A learn.zybooks.com/zybook/CSMDCSC1110WhiteFall2021/chapter/9/section/10
= zyBooks My library > CSC 1110: Program Design and Development home > 9.10: LAB: Nutritional information (classes/constructors)
E zyBooks catalog
Help/FAQ
A Faith Holt -
9.10 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
"None' 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, 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 both food items.
Ex: If the input is:
M&M's
10.0
34.0
2.0
1.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 1.0 is the
number of servings, the output is:
Nutritional information per serving of None:
Fat: 0.00 g
Carbohydrates: 0.00 g
Protein: 0.00 g
Number of calories for 1.00 serving (s): 0.00
Nutritional information per serving of M&M's:
Fat: 10.00 g
Carbohydrates: 34.00 g
Protein: 2.00 g
Number of calories for 1.00 serving (s): 234.00
3275182101532 gx8zm7
1:17 PM
P Type here to search
Hi
9/26/2021
近
Transcribed Image Text:zy Section 9.10 - CSC 1110: Progran X A learn.zybooks.com/zybook/CSMDCSC1110WhiteFall2021/chapter/9/section/10 = zyBooks My library > CSC 1110: Program Design and Development home > 9.10: LAB: Nutritional information (classes/constructors) E zyBooks catalog Help/FAQ A Faith Holt - 9.10 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 "None' 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, 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 both food items. Ex: If the input is: M&M's 10.0 34.0 2.0 1.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 1.0 is the number of servings, the output is: Nutritional information per serving of None: Fat: 0.00 g Carbohydrates: 0.00 g Protein: 0.00 g Number of calories for 1.00 serving (s): 0.00 Nutritional information per serving of M&M's: Fat: 10.00 g Carbohydrates: 34.00 g Protein: 2.00 g Number of calories for 1.00 serving (s): 234.00 3275182101532 gx8zm7 1:17 PM P Type here to search Hi 9/26/2021 近
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT