CS 111 - 2/26/15 Last Time: How do we loop to access all of the pixels in a picture For a picture of Width = 200, Height = 100 We have 20,000 pixel int x; int y; x = 0; // loop for all of the columns in the picture while ( x < p.getWidth() ) { y = 0; // access column x in the picture while ( y < p.getHeight() ) { Pixel pix = p.getPixel(x, y); // manipulate pix as desired y = y + 1; } x = x + 1; } Algorithm Idea: Invert a value: If the original value is high => make it low If the original value is low => make it high updatedValue = MAX - originalValue; Encapsulation - The process of using methods to enhance readability of code where a set of code that does one specialized task is placed in a method and that method gets called when needed. For Loop - a loop that is designed to execute a set number of times. The for loop combines three of the elements of the the while loop onto a single line of code - the initialization - the condition - the increment SYNTAX: for ( ; ; ) { ; } The execution of the for loop will: 1. do the initialization 2. check the if true - do step 3 next if false - end the loop 3. execute the statement(s) 4. executed the 5. goto step 2. The for loop of the form: for ( ; ; ) { ; } Is the same as the following while loop ; while ( ) { ; ; } When the of the for loop only contains one statement, we can leave off the curly braces {} The increment operator: ++ adds one to a value The decrement operator: -- subtracts one from a value PLEASE USE WITH CAUTION: Bizzare errors can result otherwise The operators preform assignment with value change These operators have a prefix and postfix form that don't work the same int x = 5; x++; // postfix form ++x; // prefix form x++ is NOT the same as: x+1 x++ is the SAME as: x = x+1 x = 10; x = x++; // strangly wrong System.out.println ("x is: " + x);