Peer Instruction: Unit 6 Multiple Choice Questions (with pictures)¶
- 1 - Pixel, 2 - Pixel[ ]
- Incorrect! The larger highlighted section (1) represents the array Pixel[ ], which is composed of the smaller highlighted section (2), Pixel objects.
- 1 - Pixel[ ], 2 - Pixel
- Correct! The larger highlighted section (1) represents the array Pixel[ ], which is composed of the smaller highlighted section (2), Pixel objects.
- 1 - Pixel[ ], 2 - Color
- Incorrect! The larger highlighted section (1) represents the array Pixel[ ], which is composed of the smaller highlighted section (2), Pixel objects, not Color objects.
- 1 - Pixel, 2 - Color
- Incorrect! The larger highlighted section (1) represents the array Pixel[ ] which is composed of the smaller highlighted section (2), Pixel objects. Pixel[ ] cannot be composed of Color objects and a Pixel object is not an array so it cannot contain other objects.
8-10-1: What is the type of each indicated variable?
- A
- Incorrect! The while loop continues to iterate as long as the index value is less than the length of the Pixel array divided by 4. For this reason, 1/4 of the pixels are modified as a result of this code. The first 1/4 of the pixels will be changed.
- B
- Incorrect! The while loop continues to iterate as long as the index value is less than the length of the Pixel array divided by 4. For this reason, 1/4 of the pixels are modified as a result of this code. The first 1/4 of the pixels will be changed.
- C
- Incorrect! The while loop continues to iterate as long as the index value is less than the length of the Pixel array divided by 4. For this reason, 1/4 of the pixels are modified as a result of this code. The first 1/4 of the pixels will be changed.
- D
- Correct! The while loop continues to iterate as long as the index value is less than the length of the Pixel array divided by 4. For this reason, 1/4 of the pixels are modified as a result of this code. The first 1/4 of the pixels will be changed.
- None of the above
- Incorrect! One of the answers above correctly represents what pixels this code modifies. The while loop continues to iterate as long as the index value is less than the length of the Pixel array divided by 4. For this reason, 1/4 of the pixels are modified as a result of this code. The first 1/4 of the pixels will be changed.
8-10-2: What pixels does this code modify (assuming Pixel objects in pixelArray follow this pattern: [(0,0), (0,1), (0,2)…])?
Pixel[] pixelArray = this.getPixels();
int value = 0;
int index = 0;
while (index < pixelArray.length/4)
{
value = pixelArray[index].getRed();
value = (int) (value * 0.5);
pixelArray[index].setRed(value);
}
- A
- Incorrect! Each time the for loop executes, p is assigned the pixel value at the current index and q is assigned the pixel value at the next index. p's red value is replaced with q's red value and q's blue value. Then p's green value is replaced with q's green value. Each time the code runs, p is changed and q stays the same.
- B
- Incorrect! Each time the for loop executes, p is assigned the pixel value at the current index and q is assigned the pixel value at the next index. p's red value is replaced with q's red value and q's blue value. Then p's green value is replaced with q's green value. Each time the code runs, p is changed and q stays the same.
- C
- Correct! Each time the for loop executes, p is assigned the pixel value at the current index and q is assigned the pixel value at the next index. p's red value is replaced with q's red value and q's blue value. Then p's green value is replaced with q's green value. Each time the code runs, p is changed and q stays the same.
- None of the above.
- Incorrect! One of the choices above accurately represents what this code does. Each time the for loop executes, p is assigned the pixel value at the current index and q is assigned the pixel value at the next index. p's red value is replaced with q's red value and q's blue value. Then p's green value is replaced with q's green value. Each time the code runs, p is changed and q stays the same.
8-10-3: What picture most accurately describes what this code does ?
Pixel[] pixelArray = this.getPixels();
int value = 0;
Pixel p = null;
for(int index = 0; index < pixelArray.length-1; index++)
{
p = pixelArray[index];
q = pixelArray[index+1];
p.setRed(q.getRed());
p.setBlue(q.getRed());
p.setGreen(q.getGreen());
}
- A
- Incorrect! Each time the for loop executes, p is assigned the pixel value at the next index and q is assigned the pixel value at the current index. p's red value is replaced with q's red value and q's blue value. Then p's green value is replaced with q's green value. Each time the code runs, p is changed and q stays the same.
- B
- Correct! Each time the for loop executes, p is assigned the pixel value at the next index and q is assigned the pixel value at the current index. p's red value is replaced with q's red value and q's blue value. Then p's green value is replaced with q's green value. Each time the code runs, p is changed and q stays the same.
- C
- Incorrect! Each time the for loop executes, p is assigned the pixel value at the next index and q is assigned the pixel value at the current index. p's red value is replaced with q's red value and q's blue value. Then p's green value is replaced with q's green value. Each time the code runs, p is changed and q stays the same.
- None of the above.
- Incorrect! One of the choices above accurately represents what this code does. Each time the for loop executes, p is assigned the pixel value at the next index and q is assigned the pixel value at the current index. p's red value is replaced with q's red value and q's blue value. Then p's green value is replaced with q's green value. Each time the code runs, p is changed and q stays the same.
8-10-4: What picture most accurately describes what this code does ?
Pixel[] pixelArray = this.getPixels();
int value = 0;
Pixel p = null;
for(int index = 0; index < pixelArray.length-1; index++)
{
p = pixelArray[index+1];
q = pixelArray[index];
p.setRed(q.getRed());
p.setBlue(q.getRed());
p.setGreen(q.getGreen());
}
- A
- Incorrect! Since the sample rate is 3 Hz, there are 3 samples per second. Though there are 3 samples in this example, they do not convey a broad range of sample points.
- B
- Correct! Since the sample rate is 3 Hz, there are 3 samples per second. There are 3 samples in this example and they convey a broad range of sample points.
- C
- Incorrect! Since the sample rate is 3 Hz, there should be 3 samples per second, not 6.
- D
- Incorrect! Since the sample rate is 3 Hz, there should be 3 samples per second, not 6.
8-10-5: How would we fill in this SampleSound[]?
- A
- Incorrect! This code adjusts the entire array rather than the second half.
- B
- Correct! This code adjusts the second half of the array.
- C
- Incorrect! This code adjusts the entire array rather than the second half.
8-10-6: Which code which makes the following changes?
String fileName = FileChooser.pickAFile();
Sound noise = new Sound(fileName);
SoundSample[] noiseArray = noise.getSamples();
<<< PICK SOME CODE >>>
- Makes a lower pitched sound during first half of play
- Incorrect! This code adjusts the second half of the sound array, not the first half.
- Makes a quieter sound during first half of play
- Incorrect! This code adjusts the second half of the sound array, not the first half.
- Makes a lower pitched sound during second half of play
- Correct! This code adjusts the second half of the array, specifically halving the pitch.
- Makes a quieter sound during second half of play
- Incorrect! Although this code adjusts the second half of the array, it does not impact the loudness/quietness of the sound. Rather, it impacts the pitch.
- 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
- Incorrect! This code only adjusts the second half of the array, not the whole array.
8-10-7: What does this code do?
String fileName = FileChooser.pickAFile();
Sound noise = new Sound(fileName);
SoundSample[] noiseArray = noise.getSamples();
for (int i = noiseArray.length/2; i < noiseArray.length)
{
SoundSample sample = noiseArray[i];
int foo = sample.getValue();
sample.setValue(foo/2);
}
You have attempted of activities on this page