-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyColor.java
More file actions
46 lines (40 loc) · 987 Bytes
/
MyColor.java
File metadata and controls
46 lines (40 loc) · 987 Bytes
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
//Filename: MyColor.java
//Class to encapsulate properties for color
//Jason LaHatte
//12/8/2018
public class MyColor {
final int MIN_VALUE = 0; //final is comparable to const in c++
final int MAX_VALUE = 0;
private int colorR;
private int colorG;
private int colorB;
//Constructors
public MyColor() {
colorR = 0;
colorG = 0;
colorB = 0;
}
public MyColor(int red, int green, int blue) {
r(red);
g(green);
b(blue);
}
//Accessor functions
public int r() {return colorR;}
public int g() {return colorG;}
public int b() {return colorB;}
public void r(int red) {
if (red >= MIN_VALUE && red <=MAX_VALUE) colorR = red;
}
public void g(int green) {
if (green >= MIN_VALUE && green <=MAX_VALUE) colorG = green;
}
public void b(int blue) {
if (blue >= MIN_VALUE && blue <=MAX_VALUE) colorB = blue;
}
public void set(int red, int green, int blue) {
this.r(red);
this.g(green);
this.b(blue);
}
}