📄 tv.java
字号:
package chapter7.remotecontrol;
import static java.lang.Math.max;
import static java.lang.Math.min;
public class TV implements IRemoteCtrl,IComputer
{
private int VOLUME_MIN = 0;
private int VOLUME_MAX = 100;
private int CHANNEL_MIN = 0;
private int CHANNEL_MAX = 999;
private String make = ""; //厂家
private boolean power = false;
private int volume = VOLUME_MIN;
private int channel = CHANNEL_MIN;
public TV(String make )
{
this.make = make;
//其它设置
}
public boolean powerOnOff()
{
this.power = !this.power;
System.out.println(make + "电视电源:" + (this.power ? "开":"关") );
return this.power;
}
public int volumeDown(int decrement)
{
if(!this.power )return 0; //电源关闭,所以遥控信号均无效
this.volume -=decrement;
this.volume = max(this.volume ,VOLUME_MIN);//声音不能小于最小值
System.out.println(make + "电视声音减小为:" + this.volume );
return this.volume;
}
public int volumeUP(int increment)
{
if(!this.power )return 0; //电源关闭,所以遥控信号均无效
this.volume +=increment;
this.volume = min(this.volume ,VOLUME_MAX);//声音不能大于最大值
System.out.println(make + "电视声音放大为:" + this.volume );
return this.volume;
}
public void mute()
{
if(!this.power )return ; //电源关闭,所以遥控信号均无效
this.volume =VOLUME_MIN;
System.out.println(make + "电视处于静音状态" );
return ;
}
public int channelDown()
{
if(!this.power )return 0; //电源关闭,所以遥控信号均无效
this.channel = this.channel > CHANNEL_MIN ? --this.channel : CHANNEL_MAX;
System.out.println(make + "电视频道设置为:" + this.channel );
return this.channel;
}
public int channelUp()
{
if(!this.power )return 0; //电源关闭,所以遥控信号均无效
this.channel = this.channel < CHANNEL_MAX ? ++this.channel : CHANNEL_MIN;
System.out.println(make + "电视频道设置为:" + this.channel );
return this.channel;
}
public int setChannel(int channel)
{
if(channel > CHANNEL_MAX) this.channel = CHANNEL_MAX;
else if(channel < CHANNEL_MIN)this.channel = CHANNEL_MIN;
else this.channel = channel;
System.out.println(make + "电视频道设置为:" + this.channel );
return this.channel;
}
public byte[] intputComputerSignal()
{
byte[] b = {1,0,0,1,1};
//此处省略信号输入处理
System.out.println(make + "从电脑获取如下信号:" + "Hello TV!");
return b;
}
public void outputTvSignal(byte[] b)
{
//此处省略信号输出处理
System.out.println(make + "向电脑输入如下信号:" + "Hello computer!");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -