iven main(), complete the FoodItem class (in file Foodltem.java) with constructors to initialize each food item. The default constructor hould initialize the name to "Water" and all other fields to 0.0. The second constructor should have four parameters (food name, grams of at, grams of carbohydrates, and grams of protein) and should assign each private field with the appropriate parameter value. x: If the input is: Water he output is: Nutritional information per serving of Water: Fat: 0.00 g Carbohydrates: 0.00 g Protein: 0.00 g Number of calories for 1.00 serving (s): 0.00 x: If the input is: M&M's 10.0 34.0 2.0 3.0 here 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 umber of servings, the output is: 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 Number of calories for 3.00 serving (s): 234.00 serving (s): 702.00 ote: 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 utputs the calories for one serving of water. ublic class FoodItem private String name; private double fat; private double carbs; private double protein; // TODO: Define default constructor // TODO: Define second constructor with parameters to initialize private fields (name, fat, carbs, protein)

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter9: Using Classes And Objects
Section: Chapter Questions
Problem 11E: a. Write a FractionDemo program that instantiates several Fraction objects and demonstrates that...
icon
Related questions
Question

Java

Input the following constructors

Given main(), complete the Food Item 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.00 g
Carbohydrates: 0.00 g
Protein: 0.00 g
Number of calories for 1.00 serving (s): 0.00
Ex: If the input is:
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.00 g
Carbohydrates: 34.00 g
Protein: 2.00 g
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.
public class FoodItem {
private String name;
private double fat;
private double carbs;
private double protein;
// TODO: Define default constructor
// TODO: Define second constructor with parameters to initialize private fields (name, fat, carbs, protein)
Transcribed Image Text:Given main(), complete the Food Item 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.00 g Carbohydrates: 0.00 g Protein: 0.00 g Number of calories for 1.00 serving (s): 0.00 Ex: If the input is: 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.00 g Carbohydrates: 34.00 g Protein: 2.00 g 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. public class FoodItem { private String name; private double fat; private double carbs; private double protein; // TODO: Define default constructor // TODO: Define second constructor with parameters to initialize private fields (name, fat, carbs, protein)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,