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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
public class SimpleRGBTester
{
public static void main(String[] args)
{
int width = 500;
int height = 650;
int x = 123;
int y = 321;
int red = 1;
int green = 11;
int blue = 111;
int point = 0;
SimpleRGB rgb = new SimpleRGB(width, height);
System.out.println("Constructing an SimpleRGB object using the following statement:");
System.out.println(" SimpleRGB rgb = new SimpleRGB(" + width + "," + height + ");");
// Testing the method getWidth()
System.out.print("Testing the method getWidth(): ");
if(rgb.getWidth() != width)
{
System.out.println("FAIL");
System.out.println("You method getWidth() should return " + width + ".");
System.out.println("But your method getWidth() return " + rgb.getWidth() + ".\n");
}
else
{
point++;
System.out.println("PASS");
}
System.out.println("You current point is " + point + ".\n");
// Testing the method getHeight()
System.out.print("Testing the method getHeight(): ");
if(rgb.getHeight() != height)
{
System.out.println("FAIL");
System.out.println("You method getHeight() should return " + height + ".");
System.out.println("But your method getHeight() return " + rgb.getHeight() + ".\n");
}
else
{
point++;
System.out.println("PASS");
}
System.out.println("You current point is " + point + ".\n");
// Testing methods setRed() and getRed()
System.out.print("Testing method setRed() and getRed(): ");
rgb.setRed(x, y, red);
if(rgb.getRed(x,y) != red)
{
System.out.println("FAIL");
System.out.println("After calling rgb.setRed(" + x + "," + y + "," + red + ")");
System.out.println("The method rgb.getRed(" + x + "," + y + ") should return " + red + ".");
System.out.println("But your method rgb.getRed(" + x + "," + y + ") return " + rgb.getRed(x, y) + ".\n");
}
else
{
point += 1;
System.out.println("PASS");
}
System.out.println("You current point is " + point + ".\n");
// Testing methods setGreen() and getGreen()
System.out.print("Testing method setGreen() and getGreen(): ");
rgb.setGreen(x, y, green);
if(rgb.getGreen(x,y) != green)
{
System.out.println("FAIL");
System.out.println("After calling rgb.setGreen(" + x + "," + y + "," + green + ")");
System.out.println("The method rgb.getGreen(" + x + "," + y + ") should return " + green + ".");
System.out.println("But your method rgb.getGreen(" + x + "," + y + ") return " + rgb.getGreen(x, y) + ".\n");
}
else
{
point += 1;
System.out.println("PASS");
}
System.out.println("You current point is " + point + ".\n");
// Testing methods setBlue() and getBlue()
System.out.print("Testing method setBlue() and getBlue(): ");
rgb.setBlue(x, y, blue);
if(rgb.getBlue(x,y) != blue)
{
System.out.println("FAIL");
System.out.println("After calling rgb.setBlue(" + x + "," + y + "," + blue + ")");
System.out.println("The method rgb.getBlue(" + x + "," + y + ") should return " + blue + ".");
System.out.println("But your method rgb.getBlue(" + x + "," + y + ") return " + rgb.getBlue(x, y) + ".\n");
}
else
{
point += 1;
System.out.println("PASS");
}
System.out.println("You current point is " + point + ".\n");
// getRedImage();
System.out.print("Testing method getRedImage(): ");
SimpleRGB redImage = rgb.getRedImage();
if(redImage.getRed(x, y) != red || redImage.getGreen(x,y) != 0 || redImage.getBlue(x,y) != 0)
{
System.out.println("FAIL");
System.out.println("The variable redImage of type SimpleRGB was initialized using the following statement:");
System.out.println(" SimpleRGB redImage = rgb.getRedImage();");
System.out.println("The (R,G,B) values of the rgb image at (" + x + "," + y + ") are (" + red + "," + green + "," + blue + ").");
System.out.println("The (R,G,B) values of the redImage at (" + x + "," + y + ") should be (" + red + ",0,0).");
System.out.println("But your method");
System.out.println(" redImage.getRed(" + x + "," + y + ") returns " + redImage.getRed(x,y) + ".");
System.out.println(" redImage.getGreen(" + x + "," + y + ") returns " + redImage.getGreen(x,y) + ".");
System.out.println(" redImage.getBlue(" + x + "," + y + ") returns " + redImage.getBlue(x,y) + ".");
}
else
{
point += 1;
System.out.println("PASS");
}
System.out.println("You current point is " + point + ".\n");
// getGreenImage();
System.out.print("Testing method getGreenImage(): ");
SimpleRGB greenImage = rgb.getGreenImage();
if(greenImage.getRed(x, y) != 0 || greenImage.getGreen(x,y) != green || greenImage.getBlue(x,y) != 0)
{
System.out.println("FAIL");
System.out.println("The variable greenImage of type SimpleRGB was initialized using the following statement:");
System.out.println(" SimpleRGB greenImage = rgb.getGreenImage();");
System.out.println("The (R,G,B) values of the rgb image at (" + x + "," + y + ") are (" + red + "," + green + "," + blue + ").");
System.out.println("The (R,G,B) values of the greenImage at (" + x + "," + y + ") should be (0," + green + ",0).");
System.out.println("But your method");
System.out.println(" greenImage.getRed(" + x + "," + y + ") returns " + greenImage.getRed(x,y) + ".");
System.out.println(" greenImage.getGreen(" + x + "," + y + ") returns " + greenImage.getGreen(x,y) + ".");
System.out.println(" greenImage.getBlue(" + x + "," + y + ") returns " + greenImage.getBlue(x,y) + ".");
}
else
{
point += 1;
System.out.println("PASS");
}
System.out.println("You current point is " + point + ".\n");
// getBlueImage();
System.out.print("Testing method getBlueImage(): ");
SimpleRGB blueImage = rgb.getBlueImage();
if(blueImage.getRed(x, y) != 0 || blueImage.getGreen(x,y) != 0 || blueImage.getBlue(x,y) != blue)
{
System.out.println("FAIL");
System.out.println("The variable blueImage of type SimpleRGB was initialized using the following statement:");
System.out.println(" SimpleRGB blueImage = rgb.getBlueImage();");
System.out.println("The (R,G,B) values of the rgb image at (" + x + "," + y + ") are (" + red + "," + green + "," + blue + ").");
System.out.println("The (R,G,B) values of the blueImage at (" + x + "," + y + ") should be (0,0," + blue + ").");
System.out.println("But your method");
System.out.println(" blueImage.getRed(" + x + "," + y + ") returns " + blueImage.getRed(x,y) + ".");
System.out.println(" blueImage.getGreen(" + x + "," + y + ") returns " + blueImage.getGreen(x,y) + ".");
System.out.println(" blueImage.getBlue(" + x + "," + y + ") returns " + blueImage.getBlue(x,y) + ".");
}
else
{
point += 1;
System.out.println("PASS");
}
System.out.println("You current point is " + point + ".\n");
// getGreyImage();
System.out.print("Testing method getGreyImage(): ");
SimpleRGB greyImage = rgb.getGreyImage();
int greyValue = (int) ((0.21 * rgb.getRed(x, y)) + (0.72 * rgb.getGreen(x,y)) + (0.07 * rgb.getBlue(x,y)));
if(greyImage.getRed(x, y) != greyValue || greyImage.getGreen(x,y) != greyValue || greyImage.getBlue(x,y) != greyValue)
{
System.out.println("FAIL");
System.out.println("The variable greyImage of type SimpleRGB was initialized using the following statement:");
System.out.println(" SimpleRGB greyImage = rgb.getGreyImage();");
System.out.println("The (R,G,B) values of the rgb image at (" + x + "," + y + ") is (" + red + "," + green + "," + blue + ").");
System.out.println("The (R,G,B) values of the greyImage at (" + x + "," + y + ") should be (" + greyValue + "," + greyValue + "," + greyValue + ").");
System.out.println("But your method");
System.out.println(" greyImage.getRed(" + x + "," + y + ") returns " + greyImage.getRed(x,y) + ".");
System.out.println(" greyImage.getGreen(" + x + "," + y + ") returns " + greyImage.getGreen(x,y) + ".");
System.out.println(" greyImage.getBlue(" + x + "," + y + ") returns " + greyImage.getBlue(x,y) + ".");
}
else
{
point += 2;
System.out.println("PASS");
}
System.out.println("You current point is " + point + ".\n");
System.out.println("Your final point is " + point + ".");
if(point == 10)
{
System.out.println("Contratulation! Your class SimpleRGB works perfectly (I guess).");
System.out.println("You can run ImageViewer to see how SimpleRGB can be used in a program.");
}
else
{
System.out.println("There is one or more errors in your class.");
System.out.println("Fix your bugs to get more points.");
}
}
}
|