Write a method in the Picture class to convert a Picture object into a Sound object using the average of the color values. Map all values from 0 to 84 to the maximum negative sound value, map all values from 85 to 169 to 0 and all values above 170 to the maximum positive value.

What will be an ideal response?


```
/**
* Method to conv e r t a p i c t u r e int o a sound
* @return the r e s u l t i n g sound
*/
public Sound convertToSound ( )
{
Pix e l [ ] pixe lAr ray = this . g e tPi x e l s ( ) ;
Pix e l c u r rPi x e l = nul l ;
Sound aSound = new Sound ( pixe lAr ray . l ength ) ;
// loop through p i x e l ar ray
for ( int i = 0 ; i < pixe lAr ray . l eng th ; i++)
{
c u r rPi x e l = pixe lAr ray [ i ] ;
double ave rage = c u r rPi x e l . getAverage ( ) ;
// map the ave rage to a sound v a lue
i f ( average <= 84)
aSound . setSampleValueAt ( i , Sound .MAXNEG) ;
el se i f ( average <= 169)
aSound . setSampleValueAt ( i , 0 ) ;
el se
aSound . setSampleValueAt ( i , Sound .MAX POS) ;
}
return aSound ;
}
```

Computer Science & Information Technology

You might also like to view...

After a Finally block has finished executing:

a) control proceeds to the first statement after the Finally block. b) control returns to the throw point. c) the app exits. d) control proceeds to the first statement after the last Catch block.

Computer Science & Information Technology

Which of the following statements are true?

a. A PriorityQueue orders its elements according to their natural ordering using the Comparable interface if no Comparator is specified. b. A PriorityQueue orders its elements according to the Comparator if a Comparator is specified in the constructor. c. The priority of a PriorityQueue cannot be changed once a PriorityQueue is created. d. The priority of a PriorityQueue cannot be reversed once a PriorityQueue is created.

Computer Science & Information Technology

Input masks can restrict the number of characters allowed in a field

Indicate whether the statement is true or false

Computer Science & Information Technology

According to Figure DW 2-1, the table width will be ____.

Figure DW 4-1


a. fixed
b. changing depending on the browser window’s width
c. 3 inches
d. 200 pixels

Computer Science & Information Technology