-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPixel.java
47 lines (39 loc) · 1008 Bytes
/
Pixel.java
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
public class Pixel{
private int red;
private int green;
private int blue;
//Question 1.1
public Pixel(int redElem, int greenElem, int blueElem){
if( redElem < 0 || redElem > 255 || greenElem < 0 || greenElem > 255 || blueElem < 0 || blueElem > 255){
throw new IllegalArgumentException("Values should range from [0-255] inclusive");
}
else{
this.red = redElem;
this.green = greenElem;
this.blue = blueElem;
}
}
//Question 1.2
public Pixel(int intensity){
if( intensity < 0 || intensity > 255){
throw new IllegalArgumentException("Values should range from [0-255] inclusive");
}
else{
this.red = intensity;
this.green = intensity;
this.blue = intensity;
}
}
public int getRed(){
return this.red;
}
public int getGreen(){
return this.green;
}
public int getBlue(){
return this.blue;
}
public int grey(){
return ((this.red + this.green + this.blue)/3);
}
}