java 编程 练习_Java编程练习

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.

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值