CS 101 - Fall 2011

Exam 2 Solutions

  1. c
  2. c
  3. d
  4. a
  5. b
  6. c
  7. a
  8. c
  9. a
  10. b
  11. c
  12. c
  13. a
  14. a
  15. c
  16. b
  17. c
  18. d
  19. a
  20. b

  21. public static Picture q21 (PPicture p1)
    {
      int w = p1.getWidth();
      int h = p1.getHeight();
      Picture p2 = new Picture (w*2, h);
    
      int x, y, x2, y2;
      Pixel pix1;
      Pixel pix2;
    
      for (x = 0 ; x < w ; ++x)
       {
        for (y = 0 ; y < h ; ++y)
         {
          pix1 = p1.getPixel (x, y);
          pix2 = p2.getPixel (x, y);
          pix2.setColor (pix1.getColor());
          x2 = w*2 - 1 - x;
          y2 = y;
          pix2 = p2.getPixel (x2, y2);
          pix2.setColor (pix1.getColor());
         }
       }
      return p2;
    }
    

  22. public static Picture q22 (Picture p1)
    {
      int w = p1.getWidth();
      int h = p1.getHeight();
      Picture p2 = new Picture (w*2, h);
    
      int x, y;
      Pixel pix1;
      Pixel pix2;
      int lum;
    
      for (x = 0 ; x < w ; ++x)
       {
        for (y = 0 ; y < h ; ++y)
         {
          pix1 = p1.getPixel (x, y);
          lum = (pix1.getRed() + pix1.getGreen() + 
                 pix1.getBlue())/3;
    
          pix2 = p2.getPixel (x, y);
          if (lum < 255/3)
           {
            pix2.setColor (Color.RED);
           }
          else if (lum < 255/2*3)
           {
            pix2.setColor (Color.ORANGE);
           }
          else
           {
            pix2.setColor (Color.PINK);
           }
         }
       }
      return p2;
    }