import java.awt.*; import java.awt.font.*; import java.awt.geom.*; import java.text.*; /** * A class that represents a picture. This class inherits from * SimplePicture and allows the student to add functionality to * the Picture class. * * Copyright Georgia Institute of Technology 2004-2005 * @author Barbara Ericson ericson@cc.gatech.edu */ public class ExamPicture extends SimplePicture { ///////////////////// constructors ////////////////////////////////// /** * Constructor that takes no arguments */ public ExamPicture () { /* not needed but use it to show students the implicit call to super() * child constructors always call a parent constructor */ super(); } /** * Constructor that takes a file name and creates the picture * @param fileName the name of the file to create the picture from */ public ExamPicture(String fileName) { // let the parent class handle this fileName super(fileName); } /** * Constructor that takes the width and height * @param width the width of the desired picture * @param height the height of the desired picture */ public ExamPicture(int width, int height) { // let the parent class handle this width and height super(width,height); } /** * Constructor that takes a picture and creates a * copy of that picture */ public ExamPicture(Picture copyPicture) { // let the parent class do the copy super(copyPicture); } ////////////////////// methods /////////////////////////////////////// /** * Method to return a string with information about this picture. * @return a string with information about the picture such as fileName, * height and width. */ public String toString() { String output = "Picture, filename " + getFileName() + " height " + getHeight() + " width " + getWidth(); return output; } // ***** Methods for Exam 1 ------------------------------------- public void increaseRed() { Pixel[] pixels = this.getPixels(); for ( int i = 0; i < pixels.length; i++ ) { Pixel p = pixels[i]; p.setRed ( (int) (p.getRed () * 1.1) ); } } public void problemFive() { for ( Pixel p : this.getPixels() ) { int red;// = 0; int green;// = 0; int blue;// = 0; if ( p.getRed() > 127 ) red = 255; else red = 0; if ( p.getGreen() > 127 ) green = 255; else green = 0; if ( p.getBlue() > 127 ) blue = 255; else blue = 0; p.setColor( new Color( red, green, blue ) ); } } public void problemFiveOneIf() { for ( Pixel p : this.getPixels() ) { int red;// = 0; int green;// = 0; int blue;// = 0; if ( p.getRed() > 127 || p.getGreen() > 127 || p.getBlue() > 127 ) { red = 255; green = 255; blue = 255; } else { red = 0; green = 0; blue = 0; } p.setColor( new Color( red, green, blue ) ); } } public void problemFiveAverage() { for ( Pixel p : this.getPixels() ) { int red;// = 0; int green;// = 0; int blue;// = 0; if ( p.getAverage() > 127 ) { red = 255; green = 255; blue = 255; } else { red = 0; green = 0; blue = 0; } p.setColor( new Color( red, green, blue ) ); } } public static void whileLoop() { boolean keepGoing = true; int count = 0; int max = 0; while ( keepGoing ) { System.out.println( count ); count++; max++; if ( count > 10 || max > 40 ) keepGoing = false; } } } // end of class Picture, put all new methods before this