Question: Parent Class: Food Write a parent class called Food. A food is described by a name, the number of grams of sugar ( as a
Parent Class: Food
Write a parent class called Food. A food is described by a name, the number of grams of sugar as a whole number and the number of grams of sodium as a whole number
Core Class Components points
For the Food class, write:
the complete class header
the instance data variables
a constructor that sets the instance data variables based on parameters
getters and setters; use validity checking on the parameters where appropriate
a toString method that returns a text representation of a Food object that includes all three characteristics of the food
ClassSpecific Method points
Write a method that calculates what percent of the daily recommended amount of sugar is contained in a food. The daily recommended amount might change, so the method takes in the daily allowance and then calculates the percentage.
For example, let's say a food had grams of sugar. If the daily allowance was grams, the percent would be For that same food, if the daily allowance was grams, the percent would be
Flag question: Question
Question pts
Child Class: Vegetable
Write a child class called Vegetable. A vegetable is described by a name, the number of grams of sugar as a whole number the number of grams of sodium as a whole number and whether or not the vegetable is a starch.
Core Class Components
For the Vegetable class, write:
the complete class header
the instance data variables
a constructor that sets the instance data variables based on parameters
getters and setters; use instance data variables where appropriate
a toString method that returns a text representation of a Vegetable object that includes all four characteristics of the vegetable
Flag question: Question
Question pts
Driver Program
Write a driver program that contains a main method and two other methods.
Create an Array of Objects points
In the main method, create an array of Food that holds at least two foods and at least two vegetables. You can decide what data to use.
Method: Print points
Write a method that prints the text representation of the foods in the array in reverse order meaning from the end of the array to the beginning
Invoke this method from main.
Method: Highest Sugar Food points
Write a method that takes an array of Food objects and finds the Food that has the most sugar. Note that the method is finding the Food, not the grams of sugar.
Hint: in looping to find the food, keep track of both the current highest indexand value.
Invoke this method from main.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
