Download presentation
Presentation is loading. Please wait.
Published byLindsey Strickland Modified over 9 years ago
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 5 TODO: –FINISH PSA1 WITH YOUR PARTNER! Expect to spend 6 hours! If you don’t have a partner, do this PSA on your own AND GET a partner on the discussion forum Read next class: pages 117-127, take the online reading quiz. Quiz Reflection: Group quiz PLAY WITH CODE! –Get stuck – it’s how you learn! CLICKERS OUT! LAPTOPS? http://up.ucsd.edu “Stuck, stuck, stuck!” “I felt like a lost child when I first came in and tried this. But now I’m much more comfortable with how we’re supposed to be [learning].” --”A” Student from CSE8A 2008
3
By the end of today’s class you should be able to… LG9: Nest several method calls in one statement (in contrast to doing multiple assignments) LG10: Explain how bits (0s and 1s) in a computer’s memory can be interpreted in a variety of ways (depending on issues of type and representation) LG11: Use a for each loop in Java to loop over all pixels in a picture and perform a transformation on those pixels (e.g. decrease their red component). LG12: Apply Java syntax to cast a variable to another value (and explain how it’s useful in setting picture colors). LG13: Read and understand a while loop for modifying a Picture, including being able to draw a memory model of this code
4
CSE8A: Introduction to Programming in Java Chapter 4 (up to 89)
5
What does this data stored in a computer represent? A.Deep Red (a channel) B.White (all channels maximum) C.Black (all channels minimum) D.1 E.255 1)SOLO VOTE (60 sec) 2)Discuss (2 min) 3)Team VOTE (30 sec) 11111111
6
Advice: READING! There is very important information in the textbook you are responsible for knowing. –I won’t talk about all of it in class, if you CAN learn it from the reading In class, you’ll need to have LEARNED from the reading in order to learn effectively from the clicker questions! –Which emphasize the book material that is hard to learn
7
What is the difference between these codes? 1)Think SOLO (30 sec) 2)Discuss (2 min) 3)Type in answer on UP (30 sec) String fileName = FileChooser.pickAFile(); Picture picObj = new Picture(fileName); picObj.show(); Picture picObj = new Picture(FileChooser.pickAFile()); picObj.show(); A B
8
Chapter 2 review! What is stored in the variable name after the following line of code is executed? String name = "Bob"; A.“Bob” B.Bob C.The address in memory where “Bob” is stored D.new String(“Bob”) 1)Solo: (20 sec) 2)Discuss: (1 min) 3)Group: (20sec) In 2 slides help me apply this to a Pixel array!
9
What does this code do? A.Decreases the blue component of a picture B.Sets the green component of each pixel to be the same as the blue component C.Sets the blue component of each pixel to be the same as the green component D.Loops over all pixels in pixelArray. For each pO calls getGreen and stores that into value. Then sets value into blue. E.None of the above. Pixel[] pixelArray = this.getPixels(); int value = 0; for (Pixel pO: pixelArray) { value = pO.getGreen(); pO.setBlue(value); } 1)Solo: (45 sec) 2)Discuss: (1 min) 3)Group: (30 sec)
10
Pixel[] pixelArray = this.getPixels(); int value = 0; for (Pixel pO: pixelArray) { value = pO.getGreen(); pO.setBlue(value); }
11
Pixel[] pixelArray = this.getPixels(); int value = 0; Pixel pO = //first pixel in picture value = pO.getGreen(); pO.setBlue(value); pO = //next pixel in picture value = pO.getGreen(); pO.setBlue(value); pO = //next pixel in picture value = pO.getGreen(); pO.setBlue(value); pO = //next pixel in picture value = pO.getGreen(); pO.setBlue(value); pO = //next pixel in picture value = pO.getGreen(); pO.setBlue(value); pO = //next pixel in picture value = pO.getGreen(); pO.setBlue(value); pO = //next pixel in picture ON AND ON THROUGH ALL PIXELS IN PICTURE
12
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.
13
Play with code! For example (from page 93): for (Pixel pixelObj : pixelArray) { //get the red value value = pixelObj.getRed(); //decrease the red value by 50% value = (int) (value * 0.5); //set the red value of the current pixel to new value pixelObj.setRed(value); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.