Java Reference
In-Depth Information
public int channelUp() {
if(!power) {
// If the power is off
return 0;
// Nothing works
}
// Wrap channel up to MIN_CHANNEL when MAX_CHANNEL is reached
channel = channel<MAX_CHANNEL ? ++channel : MIN_CHANNEL;
System.out.println(make + " "+ screensize + " inch TV tuned to
channel: "
+ channel);
return channel;
}
public int channelDown() {
if(!power) {
// If the power is off
return 0;
// Nothing works
}
// Wrap channel down to MAX_CHANNEL when MIN_CHANNEL is reached
channel = channel>MIN_CHANNEL ? --channel : MAX_CHANNEL;
System.out.println(make + " "+ screensize + " inch TV tuned to
channel: "
+ channel);
return channel;
}
private String make = null;
private int screensize = 0;
private boolean power = false;
private final int MIN_VOLUME = 0;
private final int MAX_VOLUME = 100;
private int volume = MIN_VOLUME;
private final int MIN_CHANNEL = 0;
private final int MAX_CHANNEL = 999;
private int channel = MIN_CHANNEL;
}
Directory "TryRemoteControl"
This class implements all the methods declared in the RemoteControl interface, and each method out-
puts a message to the command line so you know when it is called. Of course, if you omitted any of the
interface method definitions in the class, the class would be abstract and you would have to declare it as
such.
A DVDPlayer class defining a DVD player/recorder might also implement RemoteControl :
Search WWH ::




Custom Search