Question
*Please do not import anything and use java* Please do not copy from other experts a) Create a class called HealthyEating23 b) Create an enum
*Please do not import anything and use java*
Please do not copy from other experts
a) Create a class called HealthyEating23 b) Create an enum called Food Inside Enum (separate from HealthyEating23): JUNK_FOOD, DAIRY, GRAIN, PROTEIN, FRUIT, and VEGETABLE c) In HealthyEating23, create a public static method called mealPrep that takes in an integer named numFoods and returns a Food array. Create a Food array of size numFoods called foodArray At each index of foodArray, place a random value of Food HINT: EnumName.values() returns an array of the values inside an enum. Use it along with Math.random() to get random values of type Food? Must not just return EnumName.values() Each time this method is called a different array should be returned. Return the foodArray d) In HealthyEating23, create a public static method called followRecipe that takes in a string named recipe and returns a Food array. A recipe is a string of enum names separated by spaces For example, a recipe may look like: PROTEIN GRAIN FRUIT VEGETABLE and the returned Food array would look like: [PROTEIN, GRAIN, FRUIT, VEGETABLE] HINT: The String API provides a method named split(...) that can help you separate the individual foods so you can place them in an appropriately-sized array. You may assume that the provided string will only contain valid names of foods from the enum you created. e) In HealthyEating23, create a public, static method called mealAnalyzer that takes in a variable named foodArray , which is an array of Food, and does not return anything.
Print the following statement once: The following types of food are in your meal: For each type of Food, count how many are present in foodArray. Then, print out a new line with the string representation of each Food and the total number of that type of food. For example, given the following array as a parameter: [JUNK_FOOD, JUNK_FOOD, JUNK_FOOD, JUNK_FOOD, VEGETABLE, GRAIN] you should print out JUNK_FOOD 4 DAIRY 0 GRAIN 1 PROTEIN 0 FRUIT 0 VEGETABLE 1 Make sure that this method works for any size foodArray it receives. f) In HealthyEating23, create a public static method called healthyChoice that takes in two variables named meal1 and meal2 (in that order and both of type Food[]) and does not return anything. Calculate the score of each meal by finding the ordinal position of each Food in the group and adding them together. Note that EnumValue.ordinal() will return the ordinal of EnumValue, the position in which EnumValue was originally declared in the enum. For example, the score of this array: [JUNK_FOOD, JUNK_FOOD, JUNK_FOOD, JUNK_FOOD, VEGETABLE, GRAIN] would be 7 because there are 4 JUNK_FOODs which are located at position 0 in the enum, there is 1 GRAIN which is located at position 2 in the enum, and there is 1 VEGETABLE which is located at position 5 in the enum. 40+12+15=7 There are a few different ways to make this calculation. Feel free to pick what makes the most sense to you. If meal1s score is greater than meal2s score, print The first meal is the healthier choice with a score of
Use followRecipe() to create a meal1 and meal2 that test all possible outcomes (i.e. meal1 healthier, meal2 healthier, same score).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started