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 24 Exam: Wed 3-6pm Read next class: read 367-380
What’s happening the rest of the term Finish Chapter 10 (Sound) Chapter 11 (Creating your own classes) Arrays – not just for Sounds and Pictures anymore… Week 9 (Tgiving) Beth in Europe, Leo Lectures Monday No class, No lab Wed PSA8 due Tues 11:59 (individual – Sound collage) Week 10 PSA9 due WED 11:59pm (pair – Make a class) Lecture all week, Exam Wed of finals week 3-6pm Yes, there’s a quiz Friday Week 10 Exam: Wed 3-6pm Individual and Group

3 Ahhh! There’s no way I am going to pass this class!
CSE8A Winter 2010

4 Video of “how class goes”: I would be willing to be in “large” scenes in the video (not identified personally) Yes No I have a concern

5 A half-page description
When asked: What does this code do? Or What is the purpose of this code? The answer should be… A high-level explanation in English that your grandmother might understand A half-page description Something like, it loops over all the pixels and sets the blue component to 0 and the red to 255 and the green to 0 A line-by-line reading of the code that makes the graders eyes glaze over

6 By the end of today’s class you should be able to…
LG45: Be able to explain in plain English what code modifying Sounds does. LG46: Trace indexing patterns in code to perform Sound manipulations (e.g., reversing a sound, create echos). LG47: Identify scenarios where object transformations lead to objects of different “sizes”. LG48: Create a Sound of a specific “length” or duration using new LG48: Read, trace, and write methods which creates and returns new objects (rather than modifying calling objects). LG49: Identify issues with overwriting arrays when trying to “modify in place”. LG50: Describe how a Java class is made up of instance variables or fields, constructors, and methods and brainstorm a given class design. LG51: Identify common errors made by novices in defining their own classes. LG53: Identify common structure of “getter” and “setter” methods.

7 Concept Summary When you want to create a “new” object
Call a “constrcutor” with new. Look in the file of that class to find out what constructors are available What parameters you can send Don’t forget to return the object you created with a return statement! When working with 2 (multiple) arrays Sometimes you will want 2 iterators (to index into them) moving independently If you are indexing “in synchrony” then use one iterator – it communicates to those reading your code!

8 Options to raisePitch Create new Sound Modify existing Sound
V1) Of same length as original with “silence” at end V2) Of exact length needed for higher pitched sound Modify existing Sound V3) Will be of same length with “silence” at end

9 V3: Modify existing sound:
<<<INSERT METHOD HEADER HERE>>> SoundSample[] noiseAr= XXXX; int newPlace = 0; for(int i = 0; i < noiseAr.length; i+=2) { <<SOME CODE HERE>> } public void raisePitch() this.getSamples(); public void raisePitch(Sound noise) noise.getSamples(); public Sound raisePitch() this.getSamples(); public Sound raisePitch(Sound noise) noise.getSamples();

10 V3: Modify existing sound: Trace the execution of this code (may be buggy!)
newPlace is not updated Even then it doesn’t zero out last half. SoundSample[] noiseAr= XXXX; int newPlace = 0; for(int i = 0; i < noiseAr.length; i+=2) { noiseAr[newPlace] = noiseAr[i]; }

11 Modify existing sound: BUT Put sound in last half of array!
SoundSample[] noiseAr= this.getSamples(); int newPlace = <<XXXXX>>; for(int i = 0; i < noiseAr.length; i+=2) { <<XXXXX>> } 0; noiseAr[newPlace++] = noiseAr[i]; noiseAr.length/2; noiseAr[newPlace++] = noiseAr[i]; 0; noiseAr[newPlace+=2] = noiseAr[i]; E What’s the problem? Overwriting data we need Could make copy first, but we can be smarter noiseAr.length/2; noiseAr[newPlace+=2] = noiseAr[i];

12 Concept Summary Modifying the original sound has difficulties
And especially if size will change Might not be best solution if result is DIFFERENT than original (different size, shape, etc.) Loops don’t always have to go “up” (left to right) through the array Think about the modifications you are making, be sure to “use” any data before you overwrite it. If you can’t make that work out – make a temporary “copy” of the data before you modify it.


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

Similar presentations


Ads by Google