PleasecreateaninterfaceElectricalDevicewhichhasmethodsturnOn()andturnOff().PleasecreateclassesAudioDeviceandRefrigeratorwhichimplementtheinterfaceElectricalDevice.AudioDe...
Please create an interface ElectricalDevice which has methods turnOn()and turnOff().
Please create classes AudioDevice and Refrigerator which implement the interface ElectricalDevice. AudioDevice has its own methods increaseVol() and decreaseVol(). Refrigerator has its own method setFreezingLevel().
Please create AudioDevice’s subclasses TV and Radio. TV has its own methods changeChannel()and adjustColor(). Radio has its own method adjustWavelength(). Classes TV and Radio should override the methods increaseVol() and decreaseVol() from AudioDevice. When overriding the two methods, use super to invoke the two methods first and then add the other sentences that you want.
Please create a class TestElecDevice. Thisclass should be able to accept a command-line argument. You can run the class with different argument TV or Radio. In the class, create instance variables ed (which type is ElectricalDevice) and ad (which type isAudioDevice). In the main method, assign the instance of Refrigerator toedand then useedto invoke the methodturnOn() and turnoff(). According to the argument, assign the instance of TV or Radio to ad and invoke the method increaseVol() and decreaseVol(). Please watch the result and make clear the methods in which class to be invoked.
Notice:
In each method of the classes, please include a statement to display a message. For example, put System.out.println(“The refrigerator is on”) in the class Refrigerator ‘s method turnOn().
You are free to add more methods in the classes.
展开