Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following questions concern the following piece of code. 1: public Sound sil

ID: 3864071 • Letter: T

Question

The following questions concern the following piece of code.

1: public Sound sillyModification()
2: {
3: Sound newMusic = new Sound(this.getLength());
4:
5: int yyy = 0;
6: int qqq = this.getSampleValueAt(0);
7: int rrr = qqq;
8: int curr;
9: for (int i = 0; i < this.getLength(); i++)
10: {
11: curr = this.getSampleValueAt(i);
12: yyy += curr;
13: if (curr > qqq)
14: qqq = curr;
15: else if (curr < rrr)
16: rrr = curr;
17: }
18: int zzz = yyy / this.getLength();
19:
20: for (int i = 0; i < this.getLength(); i++)
21: {
22: curr = this.getSampleValueAt(i);
23: if (curr > zzz)
24: newMusic.setSampleValueAt(i, qqq);
25: else if (curr < zzz)
26: newMusic.setSampleValueAt(i, rrr);
27: }
28: return newMusic;
29: }

-------------------------------------------------------------------------------------------


1. What would be a better variable name for qqq (pick the BEST answer) ?
A) sum
B) average
C) value
D) min
E) max

-------------------------------------------------------------------------------------------


2. What would be a better variable name for zzz (pick the BEST answer) ?
A) sum
B) average
C) value
D) min
E) max

-------------------------------------------------------------------------------------------


3. How long is the SoundSample array in the object newMusic?
A) 0
B) zzz
C) zzz – 1
D) this.getLength()
E) this.getLength()-1

-------------------------------------------------------------------------------------------


4. Describe in plain English what this code does.

-------------------------------------------------------------------------------------------


5. Assume that the calling object SoundSample array looks like this. What does the newMusic
SoundSample array contain after this method executes?

-------------------------------------------------------------------------------------------

6. If the sillyModification method was called by the following piece of code in a main method, what would
be true?

Sound foo = new Sound(FileChooser.pickAFile());
Sound x;
x = foo.sillyModification();
A) the foo sound is unchanged, the x sound is empty (silent)
B) the foo sound is unchanged, the x sound is a modified version of foo
C) the foo sounds is changed and empty(silent), the x sound is what foo originally was
D) the foo sound is changed (a modified version of its original values), the x sound is what foo originally was
E) None of the above.


6B) Pick one of the not-correct options above. Explain in a few English sentences why that answer is wrong.

-------------------------------------------------------------------------------------------


7. Suppose I want to write a different version of sillyModification to do basically the same thing.
However, I want the method to be called from a main program like this:

Sound foo = new Sound(FileChooser.pickAFile());
Sound x = new Sound(foo.getLength());
foo.sillyModification(x);
What line numbers would you change in the program and how would they change?

-------------------------------------------------------------------------------------------


9. Write a method of the Picture class that modifies the calling object so that every “pair” of columns of the
picture is swapped with the column next to it. That is – the original picture’s column 0 should be swapped
with column 1, column 2 should be swapped with column 3, etc. The code you write should work for both
Pictures of odd and even widths.

(Variations to consider – do you know how to…)
• Do the same thing but with rows?
• Swap columns, but only those pixels that have a strong green component (say green is more than 200?)
• Swap the entire column, but only those columns that contain a large percentage of green pixels (say 50%
above 200)
• Instead of modifying the calling object, create a new object (of just the right size) and make it be the
“swapped column” result?

Please help me #1 - #9 questions!

Thanks in advance! :-)

#java programming

Explanation / Answer

1. E) max

2. B) Average

3. D) this.getLength()

4. The code creates a Sound object with the length from this object. It goes through the sound and finds out the maximum, minimum and average sample values. Then for every sample, it replaces the samplevalue that is less than the average with the minimum value and greater than the average with maximum value.

5. The newmusic will contain an array of values which will contain the average value, maximum value and the minimum values that were calculated from the this sample values.

6. B) the foo sound is unchanged, the x sound is a modified version of foo

6B) Taking option C) the foo sounds is changed and empty(silent), the x sound is what foo originally was

This is not true because foo is unchanged and all the sample values are modified to the newmusic object. Also x sound doesnt contain the original values of foo.

7. These are the modified lines,

1: public void sillyModification(Sound newMusic)
Remove this line - 3: Sound newMusic = x;

Remove this line - 28: return newMusic;

Question 9 - Do you already have a Picture implementation? Its difficult to write the program without it. Also each question is limited to be answered only for first 4 parts. However, except quesion 9 (which has less information) I have answered everything else .