public class Person
{
private String name;
private int age;
public Person(String name, int age)
{
super();
this.name = name;
this.age = age;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
@Override
public String toString()
{
return "Person [name=" + name + ", age=" + age + "]";
}
public void switchOnTheTV()
{
System.out.println(name+" is calling switchOn method of Remote ");
Remote remote = new LEDTVRemote();
remote.switchOn();
}
public void switchOffTheTV()
{
System.out.println(name+" is calling switchOff method of Remote ");
Remote remote = new LEDTVRemote();
remote.switchOff();
}
}
Remote.java /**
* An interface is a group of related methods with empty bodies.
*/
public interface Remote
{
void switchOn();
void switchOff();
}
LEDTVRemote.java public class LEDTVRemote implements Remote
{
@Override
public void switchOn()
{
System.out.println("switchOn method of LEDTVRemote is called"
+ " and Remote is calling switchOnTV method of LED TV ");
LedTV ledtv = new LedTV("106 Cm",true);
ledtv.switchOnTV();
}
@Override
public void switchOff()
{
System.out.println("switchOff method of LEDTVRemote is called"
+ " and Remote is calling switchOffTV method of LED TV ");
LedTV ledtv = new LedTV("106 Cm",true);
ledtv.switchOffTV();
}
}
LedTV.java public class LedTV
{
private String displaySize;
private boolean isSmartTv;
public LedTV(String displaySize, boolean isSmartTv)
{
super();
this.displaySize = displaySize;
this.isSmartTv = isSmartTv;
}
public String getDisplaySize()
{
return displaySize;
}
public void setDisplaySize(String displaySize)
{
this.displaySize = displaySize;
}
public boolean isSmartTv()
{
return isSmartTv;
}
public void setSmartTv(boolean isSmartTv)
{
this.isSmartTv = isSmartTv;
}
public void switchOnTV()
{
System.out.println("switchOnTV method of LEDTV is called.");
System.out.println("LED TV is Switched on.");
}
public void switchOffTV()
{
System.out.println("switchOffTV method of LEDTV is called.");
System.out.println("LED TV is Switched off.");
}
}