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

Intro To Java Programming, debug method help. I\'m not sure why this method isn\

ID: 3730962 • Letter: I

Question

Intro To Java Programming, debug method help.

I'm not sure why this method isn't working the way I want it to.

This method modifies the calling object to contain the complete firstSound followed by the complete secondSound. Both sounds should overwrite the SoundSamples in the calling object. For this method you can assume that the calling object is at least as long as the sum of lengths of the two parameter objects. If the calling object is longer, the method should make the last part of the calling object silent (that is, set the values of all of the remaining sound samples to 0).

Explanation / Answer

public void concatenateSound(Sound firstSound, Sound secondSound)

{

int endOfOriginal = this.getLength();

int endOfFirstSound = firstSound.getLength();

int endOfSecondSound = secondSound.getLength();

for (int firstSoundi = 0; firstSoundi < endOfFirstSound; firstSoundi++)

{

this.setSampleValueAt(firstSoundi, firstSound.getSampleValueAt(firstSoundi));

}

for (int secondSoundi = endOfFirstSound,secondSongIndex=0; secondSongIndex < endOfSecondSound; secondSoundi++,secondSongIndex++)

{

this.setSampleValueAt(secondSoundi, secondSound.getSampleValueAt(secondSongIndex));

}

for (int endSound = endOfSecondSound; endSound < endOfOriginal; endSound++)

{

this.setSampleValueAt(endSound, 0);

}

}

Error:

Assume Song1 =5;

Song 2 =6

Original Song15

Error 1 : for this problem we don't need the outer loop to copy the 2 arrays so we can remove the outer loop

Error 2 : in the 2nd inner loop secondSoundi is assigned with endOfFirstSong in our case it is 5

when we try get the value

and changed condition to secondSongIndex<endOfSecondSong;secondSongIndex++

so that it will pick from 0 and put it in the original Array

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote