forked from rhlomax/Module_1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFan.java
More file actions
112 lines (108 loc) · 2.59 KB
/
Fan.java
File metadata and controls
112 lines (108 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
Fan.java
August, 2022
Rich Lomax
Bellevue Unviersity.
Module 1 Assignment.
A class to implement a Fan object that has several attributes.
**/
public class Fan {
// Constants for the speed attribute:
static final int STOPPED = 0;
static final int SLOW = 1;
static final int MEDIUM = 2;
static final int FAST = 3;
static final String TEMPLATE1 = "The fan is %s with a radius of %2.2f and the fan is off";
static final String TEMPLATE2 = "The fan speed is set to %d with a color of %s and a radius of %2.2f";
// attributes for speed, on/off, radius, and color:
private int speed;
private boolean on;
private double radius;
private String color;
/* The no-argument constructor: */
public Fan() {
// Call the super constructor:
super();
// Set the attributes to their default values
setSpeed(STOPPED);
setOn(false);
setRadius(6.0);
setColor("White");
}
/* A specific constructor: */
public Fan(int speed, boolean on, double radius, String color) {
super();
setSpeed(speed);
setOn(on);
setRadius(radius);
setColor(color);
}
/**
* Accessor method for the speed attribute
* @return the value of the speed attribute
*/
public int getSpeed() {
return this.speed;
}
/**
* Accessor method for the on attribute
* @return the value of the on attribute
*/
public boolean isOn() {
return this.on;
}
/**
* Accessor method for the radius attribute
* @return the value of the radius attribute
*/
public double getRadius() {
return this.radius;
}
/**
* Accessor method for the color attribute
* @return the value of the color attribute
*/
public String getColor() {
return this.color;
}
/**
* Mutator method for the speed attribute
* @param speed int
*/
public void setSpeed(int speed) {
this.speed = speed;
}
/**
* Mutator method for the on attribute
* @param on boolean
*/
public void setOn(boolean on) {
this.on = on;
}
/**
* Mutator method for the radius attribute
* @param radius double
*/
public void setRadius(double radius) {
this.radius = radius;
}
/**
* Mutator method for the color attribute
* @param color String
*/
public void setColor(String color) {
this.color = color;
}
/**
* override of the toString method for this class:
*/
@Override
public String toString() {
if (this.isOn()) {
return String.format(TEMPLATE2, this.getSpeed(), this.getColor(), this.getRadius());
}
else {
return String.format(TEMPLATE1, this.getColor(), this.getRadius());
}
}
}