Java Reference
In-Depth Information
// In practice you would probably have more
// arguments to set the max and min channel
// and volume here plus other characteristics for a particular TV.
}
public boolean powerOnOff() {
power = !power;
System.out.println(make + " "+ screensize + " inch TV power "
+ (power ? "on.":"off."));
return power;
}
public int volumeUp(int increment) {
if(!power) // If the power is off
return 0; // Nothing works
// Set volume - must not be greater than the maximum
volume = volume+increment > MAX _ VOLUME ? MAX _ VOLUME : volume+increment;
System.out.println(make + " "+ screensize + " inch TV volume level: "
+ volume);
return volume;
}
public int volumeDown(int decrement) {
if(!power) // If the power is off
return 0; // Nothing works
// Set volume - must not be less than the minimum
volume = volume-decrement < MIN _ VOLUME ? MIN _ VOLUME : volume-decrement;
System.out.println(make + " "+ screensize + " inch TV volume level: "
+ volume);
return volume;
}
public void mute() {
if(!power) // If the power is off
return; // Nothing works
volume = MIN _ VOLUME;
System.out.println(make + " "+ screensize + " inch TV volume level: "
+ volume);
}
public int setChannel(int newChannel) {
if(!power) // If the power is off
return 0; // Nothing works
// Channel must be from MIN _ CHANNEL to MAX _ CHANNEL
if(newChannel>=MIN _ CHANNEL && newChannel<=MAX _ CHANNEL);
channel = newChannel;
System.out.println(make + " "+ screensize + " inch TV tuned to channel: "
+ channel);
return channel;
Search WWH ::




Custom Search