public class TV {
public int channel=1;
public int volumeLevel=1;
public boolean on=false;
public TV() {
}
public void turnOn() {
on =true;
System.out.println("电视机已经打开了。");
}
public void turnOff() {
on=false;
System.out.println("电视机已经关闭了。");
}
public int getChannel() {
return channel;
}
public void setChannel(int channel) {
if(on) {
System.out.println("电视机已开,可以开始调台了。");
if(channel>=1&&channel<=120) {
this.channel = channel;
System.out.println("频道已经调到 "+channel+" 台");
}else {
System.out.println("你要调的频道不存在。");
}
}else {
System.out.println("电视机关着的时候是不能调台的");
}
}
public int getVolumeLevel() {
return volumeLevel;
}
public void setVolumeLevel(int volumeLevel) {
if(on) {
System.out.println("电视机已开,声音大小可调了");
if(volumeLevel>=1&&volumeLevel<=7) {
this.volumeLevel = volumeLevel;
System.out.println("声音的大小设置成了 "+volumeLevel+" 大小");
}
}else {
System.out.println("电视机关着的时候是不能调声音的");
}
}
public void channelUp() {
if(on&&channel<120) {
channel++;
}
}
public void channelDown() {
if(on&&channel>1) {
channel--;
}
}
public void volumeUp() {
if(on&&volumeLevel<7) {
volumeLevel++;
}
}
public void volumeDown() {
if(on&&volumeLevel>1) {
volumeLevel--;
}
}