/**
 * {@link <a href=
 * "https://[Log in to view URL]"
 * target= "_blank"></a>}
 * 
 * @author itammb ( Italia Massimiliano Buscati )
 * @version JDK 1.15
 *
 */

class Main {
	public static interface Device {
		public boolean isEnabled();

		public void enable();

		public void disable();

		public int getVolume();

		public void setVolume(int volPercent);

		public double getChannel();

		public void setChannel(double channel);
	}

	public static abstract class RemoteControl {

		public RemoteControl(Device device) {
			this.device = device;
		}

		protected Device device;
		
		public boolean isEnabled() {
			return device.isEnabled();
		}

		public void togglePower() {
			if (device.isEnabled())
				device.disable();
			else
				device.enable();
		}

		public void volumeDown() {
			device.setVolume(device.getVolume() - 10);
		}

		public void volumeUp() {
			device.setVolume(device.getVolume() + 10);
		}
		
		public void channelDown() {
			device.setChannel(device.getChannel() - 1);
		}

		public void channelUp() {
			device.setChannel(device.getChannel() + 1);
		}
	}

	public static class AdvanceRemote extends RemoteControl {

		public AdvanceRemote(Device device) {
			super(device);
		}

		public void mute() {
			device.setVolume(0);
		}
	}

	public static class Radio implements Device {
		int volPercent = 10;
		double channel = 100.1;

		public boolean isEnabled() {
			return true;
		}

		public void enable() {
		}

		public void disable() {
		}

		public int getVolume() {
			return volPercent;
		}

		public void setVolume(int volPercent) {
			this.volPercent = volPercent;
		}

		public double getChannel() {
			return channel;
		}

		public void setChannel(double channel) {
			this.channel = channel;
		}
	}

	public static void main(String args[]) {
		// Unit test - uso del design pattern: bridge

		RemoteControl remote = new AdvanceRemote(new Radio());
				
		remote.togglePower();
		System.out.println(remote.isEnabled());
	}
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: