Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA CODE also is there a way to not use import array??? Create a class called HappyEat1 Create an enumeration (enum) called Food - Add

JAVA CODE

also is there a way to not use import array???

image text in transcribed

image text in transcribed

Create a class called HappyEat1 Create an enumeration (enum) called Food - Add the following values to the enum: JUNK_FOOD, DAIRY, GRAIN, PROTEIN, FRUIT, and VEGETABLE - This should be in a separate Java file from HappyEat1 Inside HappyEat1, create a public, static method called mealPrep that takes in an integer named numFoods and returns a Food array. Within this method: - Create a Food array of size numFoods called foodArray - At each index of foodArray, place a random value of Food - Note that EnumName.values() returns an array of the values inside an enum. How can you use it along with Math. random() to get random values of type Food? You should not just return EnumName.values (). - Each time this method is called a different array should be returned. - Return the foodArray Inside HappyEat1, create a public, static method called followRecipe that takes in a string named recipe and returns a Food array. Within this method: - 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. Inside HappyEat1, 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. Within this method: - 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 GRAIN 1 PROTEIN 0 FRUIT 0 VEGETABLE 1 Inside HappyEat1, 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. Within this method: - 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 Enumbalue 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 meal1's score is greater than meal2's score, print "The first meal is the healthier choice with a score of ." - If meal2's score is greater than meal1's score, print "The second meal is the healthier choice with a score of ." Inside HappyEat1, create the main method and within it: - 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

Students also viewed these Databases questions