Write a class Fan and a public class FanApp.
Fan has three public constants SLOW = 1, MEDIUM = 2, FAST = 3 and four private fields with these starting values: speed (SLOW), on (false), radius (5) and color ("blue"). Besides the accessors:
| method | behaviour |
|---|---|
boolean setSpeed(int) |
accepts only 1, 2 or 3; returns whether it changed |
boolean setRadius(double) |
accepts only positive values |
void setOn(boolean), void setColor(String) |
simple mutators |
String toString() |
fan is on: speed 3, color yellow, radius 10.0 — or, when off, fan is off: color blue, radius 5.0 |
main creates two fans and reads commands until the end of the input, each starting with the fan number: 1 on, 1 off, 2 speed 3, 1 radius 10, 2 color red. A refused value prints a Rejected: … line. At the end both fans are printed. For the input
1 on
1 speed 3
1 radius 10
1 color yellow
2 speed 2
2 radius 5
2 color blue
the program prints
Fan 1: fan is on: speed 3, color yellow, radius 10.0
Fan 2: fan is off: color blue, radius 5.0