Test them and convince yourself that they are equivalent. Which do you prefer and why? Many students will prefer the ¯rst one since it is shorter, but some may prefer the second because the steps are clearer.
What will be an ideal response?
```
/**
* Method to inc r e a s e the amount o f red by 1.3
*/
public void inc r eas eRed2 ( )
{
Pix e l [ ] pixe lAr ray = this . g e tPi x e l s ( ) ;
int value = 0 ;
// loop through a l l the p i x e l s
for ( int i = 0 ; i < pixe lAr ray . l eng th ; i++)
f
// s e t the red v a lue to 1.3 t imes what i t was
value = pixe lAr ray [ i ] . getRed ( ) ;
pixe lAr ray [ i ] . setRed ( ( int ) ( value ¤ 1 . 3 ) ) ;
}
}
```
```
/**
* Method to inc r e a s e the amount o f red by 1.3
*/
public void inc r eas eRed3 ( )
{
Pix e l [ ] pixe lAr ray = this . g e tPi x e l s ( ) ;
Pix e l p i x e l = nul l ;
int red = 0 ;
int green = 0 ;
int blue = 0 ;
int newRed = 0 ;
// loop through a l l the p i x e l s
for ( int i = 0 ; i < pixe lAr ray . l eng th ; i++)
{
// g e t the cur r ent p i x e l
p i x e l = pixe lAr ray [ i ] ;
// g e t the c o l o r v a l u e s
red = p i x e l . getRed ( ) ;
green = p i x e l . getGreen ( ) ;
blue = p i x e l . getBlue ( ) ;
// c a l c u l a t e the new red v a lue
newRed = ( int ) ( red ¤ 1 . 3 ) ;
// s e t the p i x e l c o l o r to the new c o l o r
p i x e l . s e tCo l o r (new Color (newRed , green , blue ) ) ;
}
}
```
You might also like to view...
Many ____ numbers cannot be represented exactly in binary form using a finite number of bits.
A. small B. large C. integer D. decimal
DSL is an example of what type of Internet access?
A. Mobile B. Portable C. Fixed D. Wireless
You can comfortably mix writing styles within a presentation as long as you are consistent with writing styles on each individual slide.
Answer the following statement true (T) or false (F)
Most databases created today do not use the hierarchical or network models; however, these models, which are generally used with legacy mainframe systems, are still operational and so must be maintained.
Answer the following statement true (T) or false (F)