Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will be coding classes, abstract classes, and interfaces in the scenario given. Also, you will practice drawing the hierarchy relationships between the classes and

You will be coding classes, abstract classes, and interfaces in the scenario given. Also, you will practice drawing the hierarchy relationships between the classes and interfaces.

Abstract classes and interfaces

In the following example, draw all classes and interfaces to show the relationships. - Write the code to do the following: - Define a structure that can represent SweetFood. - SweetFood has two behaviors; it can sugarBoosts( ) and it can raiseCalories( ). By default, when a SweetFood sugarBoosts, the message "This SweetFood sugarBoosts" is displayed. By default, when a SweetFood raiseCalories, the message "This SweetFood raiseCalories" is displayed. - A general SweetFood cannot be instantiated.

- Define also two classes, Candy and Cake, which are a SweetFood. Both Candy and Cake behave such that when "SweetFood" is displayed in raiseCalorie( ) or sugarBoost( ), "Candy" or "Cake" is displayed by the appropriate classes. Define the default constructors to accomplish this.

- Finally, any instance of Cake can bake( ), just as any Bakable object can.

- A Potato is also a Bakable object. Define the Potato class such that it is Bakable and make sure that any instance of Cake is also Bakable. The specific behaviors when instances of either class bake( ) are up to you.

Instances of Cake should display in the message: the class name and name of object rises and gets fluffy! Instances of Potato should display in the message: the class name and name of object browns and gets crispy. ((Use getClass( ) and getName( ) for class name and object name, respectively) - Instances of either Cake or Potato should be able to be stored in a variable of type Bakable.

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

Systems analysis and design

Authors: kenneth e. kendall, julie e. kendall

8th Edition

135094909, 013608916X, 9780135094907, 978-0136089162

More Books

Students also viewed these Programming questions

Question

Contrast intrinsic motivation with extrinsic motivation.

Answered: 1 week ago