Question: 1 1 . In the following example, draw all classes and interfaces to show the relationships. - Write the code to do the following: -
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 CampGear.
CampGear have two behaviors; it can hold and it can insulate By default, when a CampGear holds, the message "This CampGear holds" is displayed. By default, when an CampGear insulates, the message "This CampGear insulates" is displayed.
A general CampGear cannot be instantiated.
Define also two classes, SleepingBag and Canteen, which are CampGear. Both SleepingBag and Canteen behave such that when "CampGear" is displayed in insulate or hold "SleepingBag" or "Canteen" is displayed by the appropriate classes. Define the default constructors to accomplish this.
Finally, any instance of Canteen can cook just as any Cooking object can.
A Microwave is also a Cooking object. Define the Microwave class such that it is Cooking and make sure that any instance of Canteen is also Cooking. The specific behaviors when instances of either class cook are up to you.
Instances of Canteen should display in the message: the class name and name of object gets hot hot' Instances of Microwave should display in the message: the class name and name of object bakes and pops. Use getClass and getName for class name and object name
Instances of either Canteen or Microwave should be able to be stored in a variable of type Cooking.
USE THE NEXT PAGE FOR EXTRA SPACE
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
