
A device has a name and can do something. TV, Printer and Microwave are devices. Using TV, you can watch movie; using Printer, you can print; using Microwave, you can cook. When a device is made to dosomething, it shouts out its name as well. An Electrician is one who can test any device. When he is asked to test a device, he will make it do something and test it. A TV can switchChannel as well. So if a tv is given to be tested to an electrician, he will make the tv dosomething and switch channel as well. Write a tester class to test how devices, electricians work.
i tryed this program..,but errors
Class Device
{
String name = "Device ";
Public void doSomething()
{
System.out.println("My name is "+ name ",i will do some work");
}
}
Public Class Tv extends Device implements Electrician
{
Public void doSomething()
{
System.out.println("playing video");
}
Public void SwitchChannel()
{
System.out.println("Changing channal");
}
Public movie()
{
System.out.println("watching movie");
}
}
Class Printer extends Device
{
Public Print()
{
System.out.println("Printing newspaper");
}
}
Class MicroWave extends Device
{
Public Cook()
{
System.out.println("Cooking some stuff");
}
}
class TestDevice
{
public static void main(String args[])
{
//Device d = new Device();
//Tv t = new Tv();
Electrician e = new Tv();
Printer p = new Printer();
MicroWave m = new MicroWave();
e.doSomething();
}
}
Public interface Electrician
{
Public abstract void doSomething();
Public abstract void SwitchChannel();
}

Check this:
class Device
{
String name = "Device ";
public void doSomething()
{
System.out.println("My name is "+ name+ ",i will do some work");
}
}
class Tv extends Device implements Electrician
{
public void doSomething()
{
super.doSomething();
System.out.println("playing video");
}
public void SwitchChannel()
{
System.out.println("Changing channal");
}
public void movie()
{
System.out.println("watching movie");
}
}
class Printer extends Device
{
public void Print()
{
System.out.println("Printing newspaper");
}
}
class MicroWave extends Device
{
public void Cook()
{
System.out.println("Cooking some stuff");
}
}
class TestDevice
{
public static void main(String args[])
{
Electrician e = new Tv();
Printer p = new Printer();
MicroWave m = new MicroWave();
e.doSomething();
e.SwitchChannel();
}
}
interface Electrician
{
public abstract void doSomething();
public abstract void SwitchChannel();
}