Solutions to the Exam

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

  21. String filename = FileChooser.pickAFile();
    Picture pict = new Picture (fileName);
       
    Pixel pixArray[];
    pixArray = pict.getPixels();
        
    int index;
    Pixel pix;
    int red, green, blue;
    int red2, green2, blue2;
    for ( index = 0 ; index < pixArray.length ; index++ )
    {
      // Access the pixel from the pizel array
      pix = pixArray[index];
      
      // access the 3 color intensities
      red = pix.getRed();
      green = pix.getGreen();
      blue = pix.getBlue();
          
      // modify the color intensities
      red2 = red/2;
      green2 = blue;
      blue2 = green;
           
      // set the new color intensities
      pix.setRed(red2);
      pix.setGreen(green2);
      pix.setBlue(blue2);
            
      // return the pixel to the pixel array
      pixArray[index] = pix;
    }
        
    pict.explore();
        
    fileName = FileChooser.pickAFile();
    pict.write (fileName);
    

  22. String fileName = FileChooser.pickAFile();
    Picture pict = new Picture (fileName);
       
    // create the canvas for the mirrored image
    Picture pictNew = new Picture (pict.getWidth(), pict.getHeight());
    
    int index;
    Pixel pix, pixNew, pixNew2, pixNew3;;
    int xPos, yPos;
    int red, green, blue;
    
    // set up two loops; one nested inside the other
    int xIndex, yIndex;
    for (xIndex = 0 ; xIndex < pict.getWidth() ; xIndex++)
    {
      for (yIndex = 0 ; yIndex < pict.getHeight() ; yIndex++)
      {
        // Access the pixel from the orignal image
        pix = pict.getPixel (xIndex, yIndex);
        
        // Access the correct pixel from the new Image
        pixNew = pictNew.getPixel (pict.geWidth - xIndex - 1, 
                                   pict.getHeight() - yIndex - 1);  
        
      
        // access the 3 color intensities
        red = pix.getRed();
        green = pix.getGreen();
        blue = pix.getBlue();
            
        // copy into the rotated image
        pixNew.setRed(green);
        pixNew.setGreen(blue);
        pixNew.setBlue(red);
        
      }
    }
    
    pictNew.show();
    fileName = FileChooser.pickAFile();
    pict.write (fileName);