Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creative Commons Attribution Non-Commercial Share Alike License

Similar presentations


Presentation on theme: "Creative Commons Attribution Non-Commercial Share Alike License"— Presentation transcript:

1 Creative Commons Attribution Non-Commercial Share Alike License
Original Developer: Beth Simon, 2009

2 CSE8A Lecture 9 Read next class: read pg
Finish PSA2! Get an interview before Thurs! Advice on PSAs from the tutors Read over the WHOLE PSA specification before you start coding Figure out which methods in which files you will write Next figure out the signature (return type, name, parameters) Know how this method will be called Know what your output should look like (check with others) Compile every couple of lines (makes finding bugs easier) READ THE SPECIFICATION WITH SUPER FINE ATTENTION! Specifications are “specific” and detail exactly how things must be done Software Development is a “team effort” which is managed by specifications

3 By the end of today’s class you should be able to…
LG19: Read and trace execution of a code with a for loop (using a single array of pixels). LG20: Find and fix array index out of bounds exceptions in a for loop LG21: Read and trace execution of a nested loop that loops over a Picture object LG22: Read and code nested loops to perform mirroring (and related) transformations using nested loops.

4 How many times is each set of code executed?
Pixel[] pixelArray = this.getPixels(); int value = 0; Pixel p = null; for(int index = 0; index < pixelArray.length; index++); { p = pixelArray[index]; value = p.getRed(); value = (int) (value * 0.5); p.setRed(value); }

5 What picture most accurately describes what this code does ?
DO NOT SHOW RESULTS: ISOMORPHIC NEXT Pixel[] pixelArray = this.getPixels(); int value = 0; Pixel p = null; for(int index = 0; index < pixelArray.length-1; index++) { p = pixelArray[index]; q = pixelArray[index+1]; p.setRed(q.getRed()); p.setBlue(q.getRed()); p.setGreen(q.getGreen()); }

6 What picture most accurately describes what this code does ?
Pixel[] pixelArray = this.getPixels(); int value = 0; Pixel p = null; for(int index = 0; index < pixelArray.length-1; index++) { p = pixelArray[index+1]; q = pixelArray[index]; p.setRed(q.getRed()); p.setBlue(q.getRed()); p.setGreen(q.getGreen()); }

7 Why does this code have an error?
Pixel[] pixelArray = this.getPixels(); Pixel p, q; for(int index = 0; index < pixelArray.length; index++) { p = pixelArray[index]; q = pixelArray[index+1]; p.setRed(q.getRed()); p.setBlue(q.getRed()); p.setGreen(q.getGreen()); } It tries to access pixelArray[-1] It tries to access pixelArray[0] It tries to access pixelArray[pixelArray.length] It tries to access pixelArray[pixelArray.length+1] None of the above

8 Fill in the code to loop over pixels in THIS ORDER
UP question: 2 min Fill in the code to loop over pixels in THIS ORDER (bottom right to top left) Pixel[] pixelArray = this.getPixels(); for ( ) { //Some code doing set on pixelArray[index] }


Download ppt "Creative Commons Attribution Non-Commercial Share Alike License"

Similar presentations


Ads by Google