Question: Given main(), complete the FoodItem class (in file Food item.java) with constructors to initialize each food item. The default constructor should initialize the name

Given main(), complete the FoodItem class (in file Food item.java) with constructors to initialize each food item. The default constructor should initialize the nameto "Water" and all other fields to 0.0. The second constructor shouldhave four parameters (food name, grams of fat, grams of carbohydrates, andgrams of protein) and should assign each private field with the appropriate

Given main(), complete the FoodItem class (in file Food item.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'a 10.0 34.0 2.0 3.0 where M&M's is the food name, 10.0 is the grams of fat, 340 is the grams of carbohydrates, 2.0 is the grams of protein, and 2.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 learn.zybooks.com NM Home - LookingGlass =zyBooks My library > CS 172: Computer Science I home > 7.26: LAB: Nutritional information (classes/constructors) 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: zy Section 7.26 - CS 172: Computer Science I zyBooks catalog ? Help/FAQ Katie 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. 423062.2712980.qx3zqy7 LAB ACTIVITY 7.26.1: LAB: Nutritional information (classes/constructors) 0/10 Current file: FoodItem.java Load default template... 1 public class FoodItem { learn.zybooks.com my Home - LookingGlass zyBooks My library > CS 172: Computer Science I home > 7.26: LAB: Nutritional information (classes/constructors) zy Section 7.26 - CS 172: Computer Science ! zyBooks catalog ? Help/FAQ e Katie Aleman LAB ACTIVITY 7.26.1: LAB: Nutritional information (classes/constructors) 1 public class FoodItem { Current file: FoodItem.java 0/10 Load default template... // TODO: Define default constructor 2 private String name; 3 private double fat; 4 private double carbs; 5 private double protein; 6 7 8 9 10 11 12 return name; 13 } 14 15 // TODO: Define second constructor with parameters to initialize private fields (name, fat, carbs, prote public String getName() { public double get Fat() { Develop mode Submit mode Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box. Enter program input (optional) If your code requires input values, provide them here. Run program Input (from above) -> FoodItem.java (Your program) Output (shown below) Program output displayed here MacBook Air learn.zybooks.com my NM Home LookingGlass yBooks My library > CS 172: Computer Science I home > 7.26: LAB: Nutritional information (classes/constructors) zy Section 7.26 - CS 172: Computer Science | EzyBooks catalog ? Help/FAQ Current file: FoodItem.java 13 } 14 15 public double get Fat() { 16 return fat; 17 } 18 19 20 public double getCarbs() { return carbs; 21 } 22 23 24 25 } 26 27 28 public double getProtein() { . return protein; public double getCalories(double numServings) { // Calorie formula Develop mode Submit mode Load default template... Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box. Enter program input (optional) If your code requires input values, provide them here. FoodItem.java Run program Input (from above) Output (shown below) (Your program) Program output displayed here learn.zybooks.com my NM Home - Looking Glass =zyBooks My library > CS 172: Computer Science I home > 7.26: LAB: Nutritional information (classes/constructors) zy Section 7.26 - CS 172: Computer Science ! zyBooks catalog ? Help/FAQ Current file: FoodItem.java V Load default template... 24 return protein; 25 } 26 27 28 29 30 public double getCalories (double numServings) { // Calorie formula double calories = ((fat * 9) + (carbs *4) + (protein * 4)) * numServings; return calories; 31 } 32 33 34 35 36 37 public void printInfo() { " System.out.println("Nutritional information per serving of + name + ":"); System.out.printf(" Fat: %.2f g ", fat); System.out.printf(" Carbohydrates: %.2f g ", carbs); System.out.printf(" Protein: %.2f g ", protein); 38 } 39} Develop mode Submit mode Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box. Enter program input (optional) If your code requires input values, provide them here. FoodItem.java Run program Input (from above) Output (shown below) (Your program) Program output displayed here Given main(), complete the FoodItem class (in file Food item.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'a 10.0 34.0 2.0 3.0 where M&M's is the food name, 10.0 is the grams of fat, 340 is the grams of carbohydrates, 2.0 is the grams of protein, and 2.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 learn.zybooks.com NM Home - LookingGlass =zyBooks My library > CS 172: Computer Science I home > 7.26: LAB: Nutritional information (classes/constructors) 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: zy Section 7.26 - CS 172: Computer Science I zyBooks catalog ? Help/FAQ Katie 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. 423062.2712980.qx3zqy7 LAB ACTIVITY 7.26.1: LAB: Nutritional information (classes/constructors) 0/10 Current file: FoodItem.java Load default template... 1 public class FoodItem { learn.zybooks.com my Home - LookingGlass zyBooks My library > CS 172: Computer Science I home > 7.26: LAB: Nutritional information (classes/constructors) zy Section 7.26 - CS 172: Computer Science ! zyBooks catalog ? Help/FAQ e Katie Aleman LAB ACTIVITY 7.26.1: LAB: Nutritional information (classes/constructors) 1 public class FoodItem { Current file: FoodItem.java 0/10 Load default template... // TODO: Define default constructor 2 private String name; 3 private double fat; 4 private double carbs; 5 private double protein; 6 7 8 9 10 11 12 return name; 13 } 14 15 // TODO: Define second constructor with parameters to initialize private fields (name, fat, carbs, prote public String getName() { public double get Fat() { Develop mode Submit mode Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box. Enter program input (optional) If your code requires input values, provide them here. Run program Input (from above) -> FoodItem.java (Your program) Output (shown below) Program output displayed here MacBook Air learn.zybooks.com my NM Home LookingGlass yBooks My library > CS 172: Computer Science I home > 7.26: LAB: Nutritional information (classes/constructors) zy Section 7.26 - CS 172: Computer Science | EzyBooks catalog ? Help/FAQ Current file: FoodItem.java 13 } 14 15 public double get Fat() { 16 return fat; 17 } 18 19 20 public double getCarbs() { return carbs; 21 } 22 23 24 25 } 26 27 28 public double getProtein() { . return protein; public double getCalories(double numServings) { // Calorie formula Develop mode Submit mode Load default template... Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box. Enter program input (optional) If your code requires input values, provide them here. FoodItem.java Run program Input (from above) Output (shown below) (Your program) Program output displayed here learn.zybooks.com my NM Home - Looking Glass =zyBooks My library > CS 172: Computer Science I home > 7.26: LAB: Nutritional information (classes/constructors) zy Section 7.26 - CS 172: Computer Science ! zyBooks catalog ? Help/FAQ Current file: FoodItem.java V Load default template... 24 return protein; 25 } 26 27 28 29 30 public double getCalories (double numServings) { // Calorie formula double calories = ((fat * 9) + (carbs *4) + (protein * 4)) * numServings; return calories; 31 } 32 33 34 35 36 37 public void printInfo() { " System.out.println("Nutritional information per serving of + name + ":"); System.out.printf(" Fat: %.2f g ", fat); System.out.printf(" Carbohydrates: %.2f g ", carbs); System.out.printf(" Protein: %.2f g ", protein); 38 } 39} Develop mode Submit mode Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box. Enter program input (optional) If your code requires input values, provide them here. FoodItem.java Run program Input (from above) Output (shown below) (Your program) Program output displayed here

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Image 1 Decision Tree This image doesnt directly relate to membership management but decision trees are a type of machine learning algorithm that can ... View full answer

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 Programming Questions!