Given main(), complete the FoodItem class (in file Food item.java) with constructors to initialize each food...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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\n", fat); System.out.printf(" Carbohydrates: %.2f g\n", carbs); System.out.printf(" Protein: %.2f g\n", 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\n", fat); System.out.printf(" Carbohydrates: %.2f g\n", carbs); System.out.printf(" Protein: %.2f g\n", 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\n", fat); System.out.printf(" Carbohydrates: %.2f g\n", carbs); System.out.printf(" Protein: %.2f g\n", 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\n", fat); System.out.printf(" Carbohydrates: %.2f g\n", carbs); System.out.printf(" Protein: %.2f g\n", 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
Expert Answer:
Answer rating: 100% (QA)
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 the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
On 1 July 2024, Babakin Ltd acquired all the issued shares of Moruya Ltd, paying $50 000 cash and transferring 100 000 of its own shares to Moruya Ltd's former shareholders. The fair value of Babakin...
-
Episode 1: A New War Begines Vanderbilt How did Vanderbilts upbringing affect his business attitudes? Which product Vanderbilt decided to sell, as he knew good entrepreneur find something that...
-
What is one common mistake that managers often make when evaluating their firm's capabilities?
-
The parabola y = x 2 + C is to be tangent to the line y = x. Find C.
-
Consider the following cash flow profile and assume MARR is 10 percent/year. a. What does Descartes' rule of signs tell us about the IRR(s) of this project? b. What does Norstrom's criterion tell us...
-
A production manager at Ultra Clean Dishwashing Company is monitoring the quality of the companys production process. There has been concern relative to the quality of the operation in accurately...
-
A figure skater spins at the end of her routine and slows down with an angular acceleration of "0.4" A per second squared. If she initially spun with a frequency of 2.35 Hz, how much time does it...
-
Problem 3 addressed the cross-sectional variation in the number of financial analysts who follow a company. In that problem, company size and debt-to-equity ratios were the independent variables. You...
-
You want to receive 5,000 per month in retirement. If you can earn 0.75% per month and you expect to need the income for 25 years, how much do you need to have in your account at retirement?
-
Nast Inc. is considering Projects S and L, whose cash flows are shown below. These projects are mutually exclusive, equally risky, and not repeatable. If the decision is made by choosing the project...
-
Fogelberg Corporation is a regional company which is an SEC registrant. The corporations securities are thinly traded on NASDAQ (National Association of Securities Dealers Quotes). Fogelberg has...
-
10. Bella Vita, Cucina Rustica, La Bottega Italiana, and Ristorante Veneto are only four of thousands of Italian restaurants in the United States. They all serve similar cuisine but each restaurant...
-
A Question of Motivation Alex and Stephanie have a few things in common. Both are students at their state's university, and both work full-time at a local supermarket to make ends meet and help pay...
-
Tesar Chemicals is considering Projects S and L, whose cash flows are shown below. These projects are mutually exclusive, equally risky, and not repeatable. The CEO believes the IRR is the best...
-
Wham Products, a maker of specialty products, is currently manufacturing and selling a product called Gory Goo. A discount department store, J-Mart, has made a one-time offer to purchase 53,000 units...
-
Borrowing costs should be recognised as an expense and charged to the profit and loss account of the period in which they are incurred : A. If the borrowing costs relate to qualifying asset B. If the...
-
While preparing Massie Miller's 2012 Schedule A, you review the following list of possible charitable deductions provided by Massie: Cash contribution to a family whose house burned...
-
Bev and Ken Hair have been married for 3 years. They live at 3567 River Street, Springfield, MO 63126. Ken is a full-time student at Southwest Missouri State University (SMSU) and Bev works as an...
-
Ken paid the following amounts for interest during 2012: Qualified interest on home mortgage...........................................$4,700 Auto loan...
-
Use the magnitudes (Richter scale) of the earthquakes listed in Data Set 16 in Appendix B. In 1989, the San Francisco Bay Area was struck with an earthquake that measured 7.0 on the Richter scale....
-
Based on data from Data Set 17 in Appendix B, the words spoken in a day by women have a mean of 16,215 words and a standard deviation of 7301 words. Consider the women with an unusual word count in a...
-
Measures of Location The values of P 50 , Q 2 , and the median are found for the net incomes reported on all individual 1040 tax forms filed last year. What do those values have in common?
Study smarter with the SolutionInn App