Activity #7 (lab): Picture methods

A Picture is actually a matrix (2-dimensional array) of Pixel objects. In Chapter 4, to have a gentle introduction to arrays and loops, the authors grab all the Pixels into an array. In Chapter 5, we consider it as what it really is: a matrix. To process the Pixels stored in a matric, we need to use the X and Y coordinate of the pixel we want. To process them all we need nested loops! Your job in this assignment is to rewrite a couple of Picture methods using nested loops instead of the single loops from Chapter 4.

Problems

Remember to abide by the programming style and documentation guidelines.

  1. Include all methods given in chapter 4 in your Picture class. Use a for loop for makeSunset(), use a for-each loop for grayscale().
  2. Change the method clearBlue() to use a nested for loop to iterate through all the pixels. Run the method again to check that it still works. Check that the blue values are all 0 using pictureObj.explore()
  3. Change the method makeSunset() to use a nested while loop to iterate through all the pixels. Run the method again to check that it still works. Check that the green and blue values are 70% of the original value using pictureObj.explore().

Deliverables

Once you've compiled and tested your code, you must submit the Picture.java file as an attachment via e-mail.

Programming Resources