-->
当前位置:首页 > 题库

PROGRAMMING:Design a fan class

Luz5年前 (2021-05-10)题库369
Design a class named fan to represent a fan. This class includes:
1. Three constants named slow, medium and fast with values of 1, 2 and 3 represent the speed of the fan.
2. A private data field of type int named speed represents the speed of the fan (the default value is slow).
3. A private data field of boolean type named on indicates whether the fan is on (the default value is false).
4. A double type private data field named radius represents the radius of the fan (the default value is 5).
5. A string type data field named color represents the color of the fan (the default value is white).
6. Accessors and modifiers of the four member variables (data fields).
7. A nonparametric construction method;
8. A parametric construction method public fan (int fanspeed, Boolean Fanon, double fanradius, string fancolor) {...},
9. A method named tostring() returns a string describing the fan. If the fan is on, the method returns the speed, color, and radius of the fan in a combined string. If the fan is not turned on, the method returns a string composed of "fan is off" and the fan color and radius.
Please draw UML diagram in your own draft book to form a good design habit.
Requirement: create two fan objects:
In the first object, the default fan object Fan1 is constructed by nonparametric construction method;
The second object calls the parametric construction method to construct the custom fan object fan2 according to the fan attribute.
These objects are displayed by calling their toString method.
###Input format:
Properties of the second object
###Output format:
Output the speed, color, radius of default fan and custom fan, and whether the fan is on or not
###Input example:
Here is a set of inputs. For example:
```in
two
True
six
Red
```
###Output example:
The corresponding output is given here. For example:
```out
-------
Default
-------
speed 1
color white
radius 5.0
fan is off
-------
My Fan
-------
speed 2
color Red
radius 6.0
fan is on
```







answer:If there is no answer, please comment