(The Fan class) Design a class named Fan to represent a fan. The class contains: Three constants named SLOW, MEDIUM, and FAST with the yalues 1, 2, and 3 to denote the fan speed. The Fan class VideoNote M08_LIAN6521_09_SE_C08.qxd 2/2/12 10:21 PM Page 331 332 Chapter 8 Objects and Classes A private int data field named speed that specifies the speed of the fan (the default is SLOW) A private boolean data field named on that specifies whether the fan is on (the default is false) A private double data field named radius that specifies the radius of the fan (the default is 5) A string data field named color that specifies the color of the fan (the default is blue) The accessor and mutator methods for all four data fields A no-arg constructor that creates a default fan A method named toString) that returns a string description for the fan. If the fan is on, the method returns the fan speed, color, and radius in one combined string. If the fan is not on, the method returns the fan color and radius along with the string "fan is off" in one combined string Draw the UML diagram for the class and then implement the class. Write a test program that creates two Fan objects. Assign maximum speed, radius 10, color yellow, and turn it on to the first object. Assign medium speed, radius 5, color blue, and turn it off to the second object. Display the objects by invoking their toString method SAMPLE RUN #01 Java Fan Standard Output Hide Invisibles A-10 .0 . Inch-yellow. fan-at-a-speed-of-3qd A.5.0.inch.blue fan: fan is off+

Question

(The Fan class)

Design a class named Fan to represent a fan. The class contains:
■ Three constants named SLOW, MEDIUM, and FAST with the values 1, 2, and 3 to
denote the fan speed. The Fan class
VideoNote
M08_LIAN6521_09_SE_C08.qxd 2/2/12 10:21 PM Page 331
332 Chapter 8 Objects and Classes
■ A private int data field named speed that specifies the speed of the fan (the
default is SLOW).
■ A private boolean data field named on that specifies whether the fan is on (the
default is false).
■ A private double data field named radius that specifies the radius of the fan
(the default is 5).
■ A string data field named color that specifies the color of the fan (the default
is blue).
■ The accessor and mutator methods for all four data fields.
■ A no-arg constructor that creates a default fan.
■ A method named toString() that returns a string description for the fan. If
the fan is on, the method returns the fan speed, color, and radius in one combined
string. If the fan is not on, the method returns the fan color and radius
along with the string “fan is off” in one combined string.
Draw the UML diagram for the class and then implement the class. Write a test
program that creates two Fan objects. Assign maximum speed, radius 10, color
yellow, and turn it on to the first object. Assign medium speed, radius 5, color
blue, and turn it off to the second object. Display the objects by invoking their
toString method.

(The Fan class) Design a class named Fan to represent a fan. The class contains:
Three constants named SLOW, MEDIUM, and FAST with the yalues 1, 2, and 3 to
denote the fan speed. The Fan class
VideoNote
M08_LIAN6521_09_SE_C08.qxd 2/2/12 10:21 PM Page 331
332 Chapter 8 Objects and Classes
A private int data field named speed that specifies the speed of the fan (the
default is SLOW)
A private boolean data field named on that specifies whether the fan is on (the
default is false)
A private double data field named radius that specifies the radius of the fan
(the default is 5)
A string data field named color that specifies the color of the fan (the default
is blue)
The accessor and mutator methods for all four data fields
A no-arg constructor that creates a default fan
A method named toString) that returns a string description for the fan. If
the fan is on, the method returns the fan speed, color, and radius in one combined
string. If the fan is not on, the method returns the fan color and radius
along with the string "fan is off" in one combined string
Draw the UML diagram for the class and then implement the class. Write a test
program that creates two Fan objects. Assign maximum speed, radius 10, color
yellow, and turn it on to the first object. Assign medium speed, radius 5, color
blue, and turn it off to the second object. Display the objects by invoking their
toString method
SAMPLE RUN #01 Java Fan
Standard Output
Hide Invisibles
A-10 .0 . Inch-yellow. fan-at-a-speed-of-3qd
A.5.0.inch.blue fan: fan is off+

Image Transcription

(The Fan class) Design a class named Fan to represent a fan. The class contains: Three constants named SLOW, MEDIUM, and FAST with the yalues 1, 2, and 3 to denote the fan speed. The Fan class VideoNote M08_LIAN6521_09_SE_C08.qxd 2/2/12 10:21 PM Page 331 332 Chapter 8 Objects and Classes A private int data field named speed that specifies the speed of the fan (the default is SLOW) A private boolean data field named on that specifies whether the fan is on (the default is false) A private double data field named radius that specifies the radius of the fan (the default is 5) A string data field named color that specifies the color of the fan (the default is blue) The accessor and mutator methods for all four data fields A no-arg constructor that creates a default fan A method named toString) that returns a string description for the fan. If the fan is on, the method returns the fan speed, color, and radius in one combined string. If the fan is not on, the method returns the fan color and radius along with the string "fan is off" in one combined string Draw the UML diagram for the class and then implement the class. Write a test program that creates two Fan objects. Assign maximum speed, radius 10, color yellow, and turn it on to the first object. Assign medium speed, radius 5, color blue, and turn it off to the second object. Display the objects by invoking their toString method SAMPLE RUN #01 Java Fan Standard Output Hide Invisibles A-10 .0 . Inch-yellow. fan-at-a-speed-of-3qd A.5.0.inch.blue fan: fan is off+

Expert Answer

Want to see the step-by-step answer?

See Answer

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

See Answer
*Response times vary by subject and question complexity. Median response time is 34 minutes and may be longer for new subjects.

Related Computer Science Q&A

Find answers to questions asked by student like you

Q: how to put a picture to top right corner in HTML

A: HTML stands for Hypertext markup language and is mainly used to format web pages and web sites. Html...

Q: The following print code is to find out the ASCII code, character for the decimal codes,and comparis...

A: ASCII chart is shown on the board

Q: SQL(Oracle): How do I create an index for the number of days it takes to ship an order? i.e. shipdat...

A: Since we need to create an index based on a calculated field we need to create a calculated index. T...

Q: Use Java to answer the question. 5-1) (Count positive and negative numbers and compute the average o...

A: Java codeimport java.util.Scanner; public class AvgWithLoop {      public static void main(String[] ...

Q: Design a Turing machine that computes the function f (x) = x − 2 if x > 2   = 0 i...

A: Click to see the answer

Q: Write a GUI application that calculates a car’s gas mileage. The application should let the user ent...

A: Create the MPGCalculator class and declare the given fields along with two JPanel gallonsLabel and m...

Q: Write a class AnalyzeNumbers which asks the user to enter the number of inputs andstores them in an ...

A: Program plan:Define the class “AnalyzeNumbers”.Define the “main()” method.Create object for “Scanner...

Q: Eliminate all λ-productions from S → AaB|aaB, A → λ, B → bbA|λ.

A: A procedure of removing all λ productions is as follows:

Q: Develop the ‘Shape’ application such that: ‘Rectangle’, ‘Ellipse’, and ‘Triangle’ classes inherit f...

A: Program plan:Define a class named “Shape”.Define a default constructor to print constructor invoked ...