package chapter20230814;
class MyTv {
boolean isPowerOn;
int channel;
int volume;
final int MAX_VOLUME = 100;
final int MIN_VOLUME = 0;
final int MAX_CHANNEL = 100;
final int MIN_CHANNEL = 1;
void turnOnOff() {
isPowerOn = !isPowerOn;
}
void volumeUp() {
volume = (MAX_VOLUME > volume) ? volume + 1 : volume;
}
void volumeDown() {
volume = (MIN_VOLUME < volume) ? volume - 1 : volume;
}
void channelUp() {
channel = (MAX_CHANNEL == channel) ? MAX_CHANNEL : channel + 1;
}
void channelDown() {
channel = (MIN_CHANNEL == channel) ? MAX_CHANNEL : channel - 1;
}
}
public class test01 {
public static void main(String[] args) {
MyTv t = new MyTv();
t.channel = 100;
t.volume = 0;
System.out.println("CH:" + t.channel + ", VOL:" + t.volume);
t.channelDown();
t.volumeDown();
System.out.println("CH:" + t.channel + ", VOL:" + t.volume);
t.volume = 100;
t.channelUp();
t.volumeUp();
System.out.println("CH:" + t.channel + ", VOL:" + t.volume);
}
}