CS 101

Exam 2 Solutions

  1. D
  2. D
  3. D
  4. A
  5. A
  6. E
  7. A
  8. C
  9. B
  10. A
  11. C
  12. C
  13. A
  14. B
  15. B
  16. A
  17. C
  18. D
  19. A
  20. C

 =// method to make a 5 color posterized version of  a picture=   
 =public static Picture q21 (Picture p)=   
 ={=     
 =int xPos, yPos;=      
 =int wid = p.getWidth();=     
 =int hgt = p.getHeight();=         
 =// loop for all the x values=      
 =for (  xPos = 0 ; xPos < wid ; ++xPos )=     
 ={= 
       =// loop for the the Y values= 
       =for ( yPos = 0 ; yPos < hgt ; ++yPos )= 
       ={= 
         =// access a pixel= 
         =Pixel pix = p.getPixel (xPos, yPos);= 
         =// access the color values of that pixel= 
         =int red = pix.getRed ();= 
         =int green = pix.getGreen ();= 
         =int blue = pix.getBlue ();= 
 =// modify the color values of the pixel= 
         =int grayAmount;= 
         =grayAmount = (int)Math.round((red * 0.299) + (green * 0.587) + (blue * 0.114)) ;                    if ( grayAmount < 255 / 5 )  // 51= 
        ={           pix.setColor ( Color.BLACK );= 
        =}=         
        =else if ( grayAmount < 2 * 255 / 5 )  // 102= 
         ={           pix.setColor ( Color.BLUE );         }= 
        =else if ( grayAmount < 3 * 255 / 5 )  // 153= 
        ={           pix.setColor ( Color.GREEN );         }= 
         =else if ( grayAmount < 4 * 255 / 5 )  // 204= 
         ={           pix.setColor ( Color.CYAN );= 
        =}= 
         =else= 
          ={           pix.setColor ( Color.WHITE);         }= 
               =}= 
      =}= 
    =return p;= 
   =}= 
  22.
 =// method to make a color negtive from a picture= 


This topic: CS101 > WebHome > CS101Spring2012 > S12Exam2Solutions
Topic revision: r1 - 2012-04-16 - 22:27:18 - Main.troy
 
Copyright 2016 The Board of Trustees
of the University of Illinois.webmaster@cs.uic.edu
WISEST
Helping Women Faculty Advance
Funded by NSF