Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

jav 7 . 2 6 LAB: Nutritional information ( classes / constructors ) Given main ( ) , complete the Fooditem class ( in file

jav7.26 LAB: Nutritional information (classes/constructors)
Given main(), complete the Fooditem class (in file Foodltem.java) with constructors to initialize each food item. The default constructor
should initialize the name to "Water" and all other fields to 0.0. The second constructor should have four parameters (food name, grams of
fat, grams of carbohydrates, and grams of protein) and should assign each private field with the appropriate parameter value.
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
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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Entity Alignment Concepts Recent Advances And Novel Approaches

Authors: Xiang Zhao ,Weixin Zeng ,Jiuyang Tang

1st Edition

9819942527, 978-9819942527

More Books

Students also viewed these Databases questions

Question

Explain briefly the four functions of measuring QoL.

Answered: 1 week ago