Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm exam 1 review Sp2006: Posterize

Questions, comments, concerns, answers, concerns about answers?
(Back to Midterm Exam 1 Review Sp2006)


I seem to be remembering that in Python - you had to say like

if (red < 64)
red = 31;
if (64 > red < 128)
red = 95;

REMOVEDke, you can't just say that it's less that a higher number, because that would include those that are lower than the first parameter as well... I know I'm not saying this very well - but so I am just checking and wondering if java is able to remember that first part and the "else if" allows it to do it as if it were above 64 and less than 128 instead of just below 128... Did that make sense???

Student252

I think I know what you're asking, and yes.
I guess I'll post the answer I wrote out for this one, give me a minute...

This block of code replaces what's provided in the sample code from just after the comment
"//Check for red range and change color"
Down to the comment
"//Set the colors."
The stuff before and after those comments stays the same. The new part is:
if(redValue>128)
  redValue = 255;
else redValue = 4;
if(blueValue <= 250)
  blueValue=200;
else blueValue = 201;
if(greenValue<10)
  greenValue = 200;
else if(greenValue > 200)
  greenValue = 10;

Note that there are 3 conditions for the green, so I used an else if statement...
And please try to spot any errors!!!

looks good, except I have "else redValue = 5" for the third line :)

:D Yup. Good catch. My bad.
~Jim

Shouldn't it be "else if (redValue <= 128) redValue = 5;"?? Or does the "else redValue = 5" mean that for any other value of red make it this??
~Jennifer

Yep, that second part you said is right on the money. If red is greater than 128, we make it 255, for all other cases (lessthan or equal to 128) we make it 5. When you do 'else' without another if statement, it covers all other cases.



Link to this Page