Listing 8. Complete listing of the program named Prob01.
/*File Prob01 Copyright 2008 R.G.Baldwin 
Revised 12/16/08 
*********************************************************/ 
 
public class Prob01{ 
  public static void main(String[] args){ 
    Picture pic = new Prob01Runner().run(); 
    System.out.println(pic); 
  }//end main method 
}//end class Prob01 
//======================================================// 
 
class Prob01Runner{ 
  public Prob01Runner(){ 
    System.out.println("Display your name here."); 
  }//end constructor 
  //----------------------------------------------------// 
  public Picture run(){ 
    Picture pix = new Picture("Prob01.jpg"); 
    //Display the input picture. 
    pix.explore(); 
 
    //Call the mirrorUpperQuads method to modify the top 
    // half of the picture. 
    pix = mirrorUpperQuads(pix); 
    //Mirror the top half into the bottom half. 
    pix = mirrorHoriz(pix); 
    //Add your name and display the output picture. 
    pix.addMessage("Display your name here.",10,20); 
    pix.explore(); 
    return pix; 
 
  }//end run 
  //----------------------------------------------------// 
 
  //This method mirrors the upper-left quadrant of a 
  // picture into the upper-right quadrant. 
  private Picture mirrorUpperQuads(Picture pix){ 
    Pixel leftPixel = null; 
    Pixel rightPixel = null; 
    int midpoint = pix.getWidth()/2; 
    int width = pix.getWidth(); 
    for(int row = 0;row < pix.getHeight()/2;row++){ 
      for(int col = 0;col < midpoint;col++){ 
        leftPixel = pix.getPixel(col,row); 
        rightPixel = 
                   pix.getPixel(width-1-col,row); 
        rightPixel.setColor(leftPixel.getColor()); 
      }//end inner loop 
    }//end outer loop 
 
    return pix; 
  }//end mirrorUpperQuads 
  //----------------------------------------------------// 
 
  //This method mirrors the top half of a picture into 
  // the bottom half. 
  private Picture mirrorHoriz(Picture pix){ 
    Pixel topPixel = null; 
    Pixel bottomPixel = null; 
    int midpoint = pix.getHeight()/2; 
    int height = pix.getHeight(); 
    for(int col = 0;col < pix.getWidth();col++){ 
      for(int row = 0;row < midpoint;row++){ 
        topPixel = pix.getPixel(col,row); 
        bottomPixel = 
                   pix.getPixel(col,height-1-row); 
        bottomPixel.setColor(topPixel.getColor()); 
      }//end inner loop 
    }//end outer loop 
 
    return pix; 
  }//end mirrorHoriz 
  //----------------------------------------------------// 
}//end class Prob01Runner