Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/http://creativecommons.org/licenses/by-nc-

Similar presentations


Presentation on theme: "Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/http://creativecommons.org/licenses/by-nc-"— Presentation transcript:

1 Creative Commons Attribution Non-Commercial Share Alike License http://creativecommons.org/licenses/by-nc- sa/3.0/http://creativecommons.org/licenses/by-nc- sa/3.0/ Original Developer: Beth Simon, 2009 bsimon@cs.ucsd.edu

2 CSE8A Lecture 7 Read next class: read pg 131-134, –take the online reading quiz (there’s NEW questions). Discussion Section! 3pm or 4pm

3 By the end of today’s class you should be able to… LG13: Read and understand a while loop for modifying a Picture, including being able to draw a memory model of this code LG14: Describe the single array representation of pixels in Picture.java LG16: Find bugs in code including: a common “empty loop” bug, using the “how many times does this statement get executed” analysis technique. LG17: Argue about the best location of a print statement to debug a problem with a loop. LG18: Apply knowledge of how people pass racketballs to swap values of variables LG19: Read and trace execution of a code with a for loop (using a single array of pixels).

4 Rules of Memory Model Drawing Two sections of memory (separate them somehow): –Simple memory: primitive type variable “boxes” with actual data in them Class/object variable “boxes” have an arrow in them to complex memory –Complex memory: class/object type ACTUAL DATA is stored here Declaration ; –Write down the name in the correct memory space –Class/object types actually have an empty box (will have arrow later) Instantiation/Assignment –Draw box (or multi-boxes if array) and fill in values Ok, we’re not writing in all the pixel values, but maybe some. Execution (sequential or loop) –If an assignment is made, change the value in the box on the left side of the assignment –If you need to evaluate an expression, read the values in the boxes to help.

5 Play computer: draw a model of memory* Pixel[] pixelArray = this.getPixels(); int value = 0; Pixel p = null; int index = 0; while (index < pixelArray.length) { value = pixelArray[index].getRed(); value = (int) (value * 0.5); pixelArray[index].setRed(value); } * This is something you WILL be asked to do on an exam/quiz.

6 What does this code do?* A.Removes all red from the picture B.Changes ½ of the red pixels to not be red C.Reduces the red component of ½ of the pixels D.Reduces the red component of each pixel to ½ of its original value E.Sets the red component of each pixel to 0.5 Pixel[] pixelArray = this.getPixels(); int value = 0; Pixel p = null; int index = 0; while (index < pixelArray.length) { value = pixelArray[index].getRed(); value = (int) (value * 0.5); pixelArray[index].setRed(value); } * This is something you WILL be asked to do on an exam/quiz.

7 What pixels does this code modify? Pixel[] pixelArray = this.getPixels(); int value = 0; int index = 0; while (index < pixelArray.length/4) { value = pixelArray[index].getRed(); value = (int) (value * 0.5); pixelArray[index].setRed(value); } 1)Solo: (60 sec) 2)Discuss: (2min) 3)Group: (30 sec)

8 DEBUGGING: How many times is each set of code executed? Pixel[] pixelArray = this.getPixels(); int value = 0; Pixel p = null; int index = 0; while (index < pixelArray.length); { value = pixelArray[index].getRed(); value = (int) (value * 0.5); pixelArray[index].setRed(value); index = index + 1; } 1)Solo: (30 sec) 2)Discuss: (1min) 3)Group: (30 sec)


Download ppt "Creative Commons Attribution Non-Commercial Share Alike License sa/3.0/http://creativecommons.org/licenses/by-nc-"

Similar presentations


Ads by Google