Loading...
Loading...
Loading...
A smart-home app switches on a fan, a light, an AC and a TV. They are different devices, but each one can tell its name and its power in watts.
Write an interface Switchable with String name() and int watts(), and the classes Fan (75 W), Light (20 W), Ac (1500 W) and Tv (120 W). Switch on the devices in the order given and print the total power.
fan, light, ac or tv.Name ON (w W), then TOTAL x W.Example
Input
3 fan light tv
Output
Fan ON (75 W) Light ON (20 W) TV ON (120 W) TOTAL 215 W
75 + 20 + 120 = 215.
Try the problem first. Open one hint at a time.
Interface methods are public, so write public String name() in every class.
Store each new object in a Switchable variable, then use only name() and watts().
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor