Reconstructing the electronic pet system teacher: Wang Shaohua QQ Group No.: 483773664
First, reconstruct the demand
Define the Eatable interface, define the Eat () method in the interface, and indicate the eating function
Define the Flyingdisccatchable interface, define the Catchingflydisc () method in the interface, and indicate the ability to pick up the Frisbee
Define the Swimmable interface, define the swim () method in the interface, and indicate the game function
Defines abstract class pet, including pet name, health value (Heath) and intimacy with host (Love) attribute, and provides abstract method print (), used to export pet information
Define dog classes, inherit pet classes, implement Eatable, flyingdisccatchable interfaces, and override or implement each method
Define Penguin Class Penguin, inherit the pet class, implement eatable and Swimmable interfaces, and override or implement each method
Write test classes that enable dogs to eat, penguin games and dogs to play with frisbee games and output penguin messages.
Second, reference code
:
From for notes (Wiz)
Learn from Teacher Wang interface: (v) Example: the reconstruction of electronic pet system