200 likes | 353 Views
Creative Commons Attribution Non-Commercial Share Alike License. http://creativecommons.org/licenses/by-nc-sa/3.0/ Original Developer: Beth Simon, 2009 bsimon@cs.ucsd.edu. CSE8A Lecture 19 (18 was midterm). Read next class: read up to page 287 Freshman seminar:
E N D
Creative Commons AttributionNon-Commercial Share Alike License • http://creativecommons.org/licenses/by-nc-sa/3.0/ • Original Developer: Beth Simon, 2009bsimon@cs.ucsd.edu
CSE8A Lecture 19 (18 was midterm) • Read next class: read up to page 287 • 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!
Question 9: Did you read the part in red? 9. (3pts) Consider six variables, declared as follows:int a, b, c; int i, j, k;The purpose of the following three lines of code is to swap thevalues in variables a and b: c = a; a = b; b = c;In one sentence, written in the box below, state the purpose of the following three lines of code: // THERE WAS THREE LINES OF // CODE // HERE • Yes • No • No, I was too pressed for time • I don’t recall
Feedback from midterm survey • I was a bit surprised by the cross problem but it was a good way to test understanding of a concept in a way that we hadn't looked at a million times before. • Was a good exam, I was a little freaked out after looking at the review midterms you posted online but this one seemed to be a lot easier. • The group exam helped me see other ways to write code on the flower • I liked how it was a reflection of most of the problems we seen in class and not something surprising. • too easy • I liked the second question on the exam that had us explain how we reasoned out our solution. I think that will be very beneficial to improving our class.
Some good advice from your peers • I feel that I could've received a much better grade on the midterm, had I studied actual code more. • It had some tricky problems that really made me think. • I like how most of the questions were similar to the clicker questions that we did during lecture.
Things I’ll fix from your help • Make it clear that input is in black and white • Group part shorter • More space for code (it was a hint, but OK) • More explanation on code writing question FYI • There is partial credit on MCQ • Time is always tough
Be proud of yourself! • I felt like skipping when I got out of the classroom because I was so happy. Studying was definitely worth it.
By the end of today’s class you should be able to… • LG37: Identify, compare and contrast if-else if –else statements and separate if statement blocks. • LG38: Explain the relationship between amplitude, frequency, compression and rarefaction as it describes sound. • LG39: Defend a choice of sampling rate and sample size for a digital sound file based on human hearing abilities and translate that into an estimate of the size of a sampling array for storing sound. • LG40: Compare an array of Pixels which forms a Picture to an Array of SoundSamples which forms a Sound including the result of indexing into each. • LG41: Read, trace, and write code to change the volume of a Sound object (using for each, while and for loops)
Advice: How to use if statements • Figure out what you want to do • Sketch out on paper your scenario. • Are your conditions for change mutually exclusive (only one can happen?) • If so, use an if, else if, (and maybe an else) • Does something ALWAYS get done? Use an else. • If more than one “thing” gets done – then probably this is in a separate if statement • Conditional change not related to each other should be in separate (multiple) if statements.
Lab (Quiz) Review: Write if statement to make sure we have no index out of bounds errors for (int x = 0; x < this.getWidth(); x++) { for (int y = 0; y < this.getHeight(); y++) { <<INSERT LINE HERE>> int foo = this.getPixel(x-3, y-2).getRed() + this.getPixel(x+2,y+3).getRed(); } } if ( (x < this.getWidth() + 2) && (x >= -3) && (y < this.getHeigth() + 3) && (y >= -2) ) if ( (x < this.getWidth() - 2) && (x >= 3) && (y < this.getHeight() - 3) && (y >= 2) ) if ( (x+2 < this.getWidth() ) && (x-3 >= 0) && (y+3 < this.getHeight() ) && (y-2 >= 0) ) if ( (x+2 <= this.getWidth() ) && (x-3 > 0) && (y+3 <= this.getHeight() ) && (y-2 > 0) )
Lab (Quiz) Review: Write if statement to make sure we have no index out of bounds errors for (int x = 0; x < this.getWidth(); x++) { for (int y = 0; y < this.getHeight(); y++) { int foo = this.getPixel(x-3, y-2).getRed() + this.getPixel(x+2,y+3).getRed(); } }
Isomorphic Don’t show results until after next one Which of these statements best characterizes sepia? • All Color components are changed, based on that same component’s original value (red changed based on red, blue changed based on blue, green changed based on green) • All Color components are changed, based on one component’s original value (just use one component to make decision) • Some (not all) Color components are changed, based on their original value • Some (not all) Color components are changed based on red’s original component value • None of these are true!
Which of these statements best characterizes posterize? • All Color components are changed, based on that same component’s original value (red changed based on red, blue changed based on blue, green changed based on green) • All Color components are changed, based on one component’s original value (just use one component to make decision) • Some (not all) Color components are changed, based on their original value • Some (not all) Color components are changed based on red’s original component value • None of these are true!
If the following sound were modified to be louder it would • Have shorter frequency and stronger compressions/rarefactions • Have smaller amplitude and stronger compressions/rarefactions • Have higher frequency and stronger compressions/rarefactions • Have larger amplitude and stronger compressions/rarefactions • None of the above
If higher pitch? Show web site: compression rarefaction explanation
Sample Rate versus Sample Size • Size is max (and min) amplitude • Rate is “how often we record an amplitude”
Discuss: (3 min) Beth makes bad music: What’s wrong with these decisions? • I’ve decided that I don’t like the sampling rate and sample size provided by the book authors. Comment on my decision to use…
Match the Java type to the (simplified) diagram • This is something you look at Picture Sound Pixel SoundSample Pixel[] SoundSample[] • This is something you listen to There are a few details hiding here – like Picture has a few more things in it.. Later…
Our Representation of Sound String fileName = FileChooser.pickAFile(); Sound noise = new Sound(fileName); SoundSample[] noiseArray = noise.getSamples(); noiseArray[3].setValue(0); int foo = noiseArray[2].getValue(); String fileName = FileChooser.pickAFile(); Picture pic = new Picture(fileName); Pixel[] pixArray = pic.getPixels(); pixArray[3].setBlue(255); int foo = pixArray[2].getRed();