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 20 Read next class: read pg 293-300 Freshman seminar: –Peer Instruction: Exploring a Revolution in College Science Teaching –Find out more about the theory behind clicker use –Analyze data from this and previous classes! CSE 8A Art Show! Sat Nov 14 10:30-12 noon –Submit either your collage or chromakey (one per pair) –Art show open to all UCSD students –JSOE High School Outreach Day -- >110 high schoolers (and their parents) –We want MORE, GREAT people in CSE at UCSD!

3 Midterm: Avg 83% 90-80-70-60 min 55% on individual final Answers posted on line tomorrow Midterms available for pickup Thurs/Fri in lab hours and in class

4 By the end of today’s class you should be able to… LG41: Read, trace, and write code to change the volume of a Sound object (using for each, while and for loops) LG42: Compare and contrast the difference between changing the Color of Pixels in a Picture to changing the volume of SoundSamples in a Sound.

5 How would we fill in this SampleSound[]

6 The Sample Rate that the Sound class ASSUMES is 22KHz: How long is a SampleSound[] in a Sound object of 1 second? A.22 elements B.11,000 elements C.22,000 elements D.44,000 elements E.We can’t tell from the data provided

7

8

9 Write code which makes the following changes Here’s a Sound String fileName = FileChooser.pickAFile(); Sound noise = new Sound(fileName); SoundSample[] noiseArray = noise.getSamples(); >> for (SoundSample sample: noiseArray) { int foo = sample.getValue(); sample.setValue(foo/2); } for (int i = noiseArray.length/2; i < noiseArray.length) { SoundSample sample = noiseArray[i]; int foo = sample.getValue(); sample.setValue(foo/2); } int i = 0; while (i < noiseArray.length) { SoundSample sample = noiseArray[i]; int foo = sample.getValue(); sample.setValue(foo/2); }

10 What does that code do? But before we do that…

11 So modified from the midterm: A.This code modifies the middle half (from the top and bottom) of the picture B.This code modifies the middle half (from the left and right) of the picture C.This code loops over the pixels in the Pixel array starting at length/4 and up to 2*length/4 and gets the red, blue and green values adds them up and divides by 3 and sets that pixel to the calculated value 0: Pixel[] pixelArray = this.getPixels(); 1: int mystery; 2: for(int i = pixelArray.length/4; i < 3*pixelArray.length/4; i++) 3: { 4: mystery = (pixelArray[i].getBlue() + pixelArray[i].getGreen() + pixelArray[i].getRed() ) / 3; 5: Color thing = new Color(mystery, mystery, mystery); 6: pixelArray[i].setColor(thing); 7: } 8:

12 Questions of the form: What does this code do should have what kind of answer? A.A short sentence your grandmother can understand B.A short sentence that describes the loop structure used C.A short sentence that describes both the loop structure used and the method calls executed inside the loop D.A paragraph at least 50 words long that the causes the graders’ eyes to glaze over

13 REVIEW: Looking at this code… Here’s a Sound String fileName = FileChooser.pickAFile(); Sound noise = new Sound(fileName); SoundSample[] noiseArray = noise.getSamples(); >> for (SoundSample sample: noiseArray) { int foo = sample.getValue(); sample.setValue(foo/2); } for (int i = noiseArray.length/2; i < noiseArray.length) { SoundSample sample = noiseArray[i]; int foo = sample.getValue(); sample.setValue(foo/2); } int i = 0; while (i < noiseArray.length) { SoundSample sample = noiseArray[i]; int foo = sample.getValue(); sample.setValue(foo/2); }

14 What does that code do A.Makes a lower pitched sound during first half of play B.Makes a quieter sound during first half of play C.Makes a lower pitched sound during second half of play D.Makes a quieter sound during second half of play E.For each SoundSample element if the array it gets the Value and stores that in an int and then sets the Value with something that is half that


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

Similar presentations


Ads by Google