Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*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 . If meal2s score is greater than meal1s score, print The second meal is the healthier choice with a score of . If the two scores are equal, print The two meals are equally healthy with scores of . g) Inside HealthyEating23, create the main method Declare two arrays of type Food[] named meal1 and meal2, respectively. Test your static methods by using them to: Fill these groups with food Print out the contents of each meal Compare meal1 to meal2 in terms of their nutritional value

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MFDBS 91 3rd Symposium On Mathematical Fundamentals Of Database And Knowledge Base Systems Rostock Germany May 6 9 1991

Authors: Bernhard Thalheim ,Janos Demetrovics ,Hans-Detlef Gerhardt

1991st Edition

3540540091, 978-3540540090

More Books

Students also viewed these Databases questions

Question

Nenw the I ewic structure of PBr. Include all the lone nairs

Answered: 1 week ago