/** * Anything that has a volume level is audible. */ public interface Audible { public int getVolume(); } /** * Anything that has a recharge method is rechargeable */ public interface Rechargeable { public void recharge(); } /** * Class representing a generic loud toy. * Exists only to serve as a superclass. */ public abstract class LoudToy { private int volume; public LoudToy(int volume) { this.volume = volume; } public abstract void makeNoise(); public int getVolume() { return volume; } } /** * A rechargable toy robot. */ public class ToyRobot extends LoudToy { private int chargeLevel; public ToyRobot() { super(10); chargeLevel = 5; } public void makeNoise() { System.out.println("Beep Beep!"); } public void recharge() { chargeLevel = 10; System.out.println("Charged up!"); } } /** * A toy sheep that says "Baaa." */ public class ToySheep extends LoudToy { public ToySheep() { super(3); } public void makeNoise() { System.out.println("Baaa."); } } /** * Cell phones, are not toys, but they have some * functionality in common with some toys: * They are audible and rechargeable. */ public class CellPhone implements Rechargeable, Audible { private int volume; private int chargeLevel; public int getVolume() { return 0; } public int makeCall() { System.out.println("Riing... Hello."); } public void recharge() { chargeLevel = 10; System.out.println("Phone is charged."); } }