Skip to content

Instantly share code, notes, and snippets.

Created December 11, 2017 16:32
/**
* SmartRadio enough smart which let you tune your
* favorite channel in louder and lower volumes
* Now added smartness of auto tuning channel
*/
public interface SmartRadio {
//old declared methods
public void tuneChannel(float channelFrequency);
//old declared methods
public void increaseVolume();
//old declared methods
public void decreaseVolume();
//new method added
default public void autoTuneChannel() {
System.out.println("auto tune channel feature added");
}
}
/**
* ABC company has now launched their next smart {@link ABCAutoTuneRadio}
* which is type of SmartRadio but with added auto tune feature.
*/
public class ABCAutoTuneRadio extends ABCRadio {
final float MIN_FREQ = 85.00F;
final float MAX_FREQ = 110.00F;
@Override
public void autoTuneChannel() {
for (float startFreq = MIN_FREQ; startFreq <= MAX_FREQ; startFreq += 1.0) {
tuneChannel(startFreq);
if (channel.isTuned()) {
break;
}
}
System.out.println("channel auto tuned to : " + getFrequency());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment