============================== Cool Coder Ad > int[] msg = { 78, 111, 119, 32, 72, 105, 114, 105, 110, 103 }; > for ( int ch : msg ) System.out.print( (char) ch ); Now Hiring > { for ( int ch : msg ) System.out.print( (char) ch ); System.out.println(); } Now Hiring ============================== Look at Homework 1... ============================== recall our method to lighten an image public void lighter( double amount ) { Pixel[] pixels = this.getPixels(); for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; double factor = 1 + amount; p.setRed ( (int) (p.getRed () * factor) ); p.setGreen( (int) (p.getGreen() * factor) ); p.setBlue ( (int) (p.getBlue () * factor) ); } } > Picture p = new Picture( "/Users/wallingf/Desktop/billy-joel-sf.jpg" ); > p.show(); > p.lighter( 0.1 ); > p.repaint(); > p.lighter( 0.4 ); > p.repaint(); > p = new Picture( "/Users/wallingf/Desktop/greece.jpg" ); > p.show(); > p.lighter( 0.5 ); > p.repaint(); // NOW: step through for loop ============================== EXERCISE: write a loop over an array of doubles > double[] mileageForWeek = {3, 8, 10, 7, 10, 0, 20}; > double sum = 0; > for (int i = 0; i < mileageForWeek.length; i++) sum = sum + mileageForWeek[i]; > sum 58.0 > sum / mileageForWeek.length 8.285714285714286 > sum / 6 9.666666666666666 // BONUS QUESTION: How would I find the average run if I didn't know // how many rest days I had? [Loop to count non-0 days!] ====================== pixel operations that depend on location: nested loops // Look at Delbert T. Quimby. > Picture quimby; > quimby = new Picture( "/Users/wallingf/Desktop/delbert-t-quimby.jpg" ); > quimby.show(); // I'd like to doctor the image so that it has a bookcase // across the entire background. > int width = quimby.getWidth(); width 400 // First, explore with PictureExplorer... > PictureExplorer explorer = new PictureExplorer( quimby ); // Find (393, 184) as bottom of bookcase on right. // Decide to copy right half of image, down to y = 184, // into left half, column by column.