Homework #7

COSC 4304
Submission Instructions
a) Programming Assignment
1) Design a class named Fan that contains:
– Three constants named SLOW, MEDIUM, and FAST with the values 1, 2
and 3 to denote the fan speed.
– 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 (get) and mutator (set) 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 9, color
yellow, and turn it on to the first object. Assign medium speed, radius 4, color blue,
and turn it off to the second object. Display the objects by invoking their toString
method in your main method (not part of the Fan class).
Run your program. Your program must run successfully to receive full credit for
this homework. Take a screenshot of your program. The screenshot should show all
of your source code and the output of your program in the Console window. Resize
the editor and/or console windows as needed so that everything is shown. You may
also need to expand Eclipse to full screen size. If you program is too large you can
take multiple screenshots.
b) Questions
2) In the following code, radius is private in the Circle class, and myCircle is an
object of the Circle class. Does the highlighted code cause any problems? If so,
explain why.
public class Circle {
private double radius = 1;
/** Find the area of this circle */

"Get 15% discount on your first 3 orders with us"
Use the following coupon
"FIRST15"

Order Now