CS 111 - 11/10/15 Exam During Lecture on Thursday - 11/12/15 Same format 20 multiple choice 2 write method question Topics: Pictures ( no Turtle ) pix.setColor ( Color.PINK ); Picture => Pixels => Red amount, green amount, blue amount valid range of color amounts 0 - 255 For a picture of width X and height y range of valid columns: 0 to x-1 range of valid rows: 0 to y-1 Operations from the Picture Object getWidth() getHeight() getPixel() new Picture ( width, height ) Operations from the Pixel Object getRed() getGreen() getBlue() getColor() setRed() setGreen() setBlue() setColor() Pixel.colorDistance ( color1, color2 ) int brightness = (pix.getRed() + pix.Green() + getBlue() ) / 3; no need to memorize the weighted average multipliers Java Language Features for loops for ( ; ; ) { ; } if statement form 1: if ( ) { ; } form 2: if ( ) { ; } else { ; } form 3: if ( ) { ; } else if ( ) { ; } else if ( ) { ; } .... else { ; } Conditions contain relational operators: < <= > >= == != Conditions may contain boolean operators: && || ! Truth Tables: ( ( x > 3 ) || (y < 2) ) && ( z != 5 ) T F T T T b1 b2 | b1 && b2 b1 || b2 !b1 ----------|----------------------------------- T T | T T F T F | F T F F T | F T T F F | F F T b | !b ------|------- T | F F | T ============================ w = 1; x = 2; y = 3; z = 0; if ( ( x < 2 ) || ( w == 1 ) ) // F || T => T z = z + 1; if ( ( x > 2 ) && ( w == 1 ) ) // F && T => F z = z + 2; if ( ( y < 2 ) || ( x <= 1 ) ) // F || F => F z = z + 4; if ( ( y < 5 ) && ( w != 4 ) ) // T && T => T z = z + 8; z: 0 1 9 ============================== z = 0; for ( x = 0 ; x < 10 ; x++ ) { y = x % 3; if ( y == 2 ) z = z + x; } x: 0 1 2 3 4 5 6 7 8 9 10 y: 0 1 2 0 1 2 0 1 2 0 z: 0 2 7 15 ===================================