Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java Part 1 Coding An inheritance principle is used to explore and implement the Consumable interface and its related classes. The UML diagram is provided

java image text in transcribed
image text in transcribed
image text in transcribed
Part 1 Coding An inheritance principle is used to explore and implement the Consumable interface and its related classes. The UML diagram is provided below. Part 1.1. Implement the Interface Consumable strictly according to the UML above. a. The displayNutritionalValue () method should print the Basic nutritional information not specified. b. Add comments to the method. Part 1.2. Implement the abstract class Food strictly according to the UML above. a. Use appropriate access modifiers. b. No method should have any empty body (unless they are abstract) Part 1.3. Write classes Fruit and Vegetable based on the UML diagram above. a. Use appropriate access modifiers. b. Implement all required data fields and methods. c. Make sure all abstract methods implemented (if appropriate) d. At least one of the classes should implement the displayNutritionalValue () method. e. The displayNutritionalValue () method should call nutritioninfo () method to provide more details about the Consumable object. f. No method should have any empty body (unless they are abstract) Part 1.4. Write the main() method in a TestFood class having the following: a. Create an array of two Consumable objects. b. The First object is a Fruit of your choice with any country of origin and specified fields (of your choice). c. The Second object is a Vegetable of your choice with properties of your choice. d. Call method displayNutritionalValue on both objects that you just created. Sample output: Nutritional Value of Apple: Main Vitamin: Vitamin C Nutritional Value of Vegetable: Basic nutritional information not specified. Part 2 Recursion 1. Answer the following True/False questions about the Recursion. A. Recursion is one of the choices for solving problems, but not always the most appropriate. B. Some problems can be solved only by using recursion. C. A recursive function does not have to have a termination condition. D. In Java, excessive recursion can lead to a StackOverflowError. E. Tail recursion is a specific form of recursion where the recursive call is the first operation in the function. F. Every recursive method in programming must include at least one condition that does not lead to another recursive call. A. B. c. D. E. F. 2. Tracing the Recursion. Observe the recursive solution provided below. a) Which line(s) of this program define(s) the base case of myMethod( ) method? b) Which line(s) of this program include recursive call(s)? c) Trace the recursion below using the BOX method. d) At what step of your recursion tracing did you hit the base case? e) What is the final output of this code? You must show the trace step by step, otherwise - little to no credit! 1 public class Test \{ 2 public static void main(String [] args) \{ 3 System,out.println(newMethod(3, 9)): 4 \} 5 6 public static int newMethod(int a, int b ) \{ 7 if (a==b) 8 return b : 9 else if (a

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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