package username.analysis; /** * A simple way to graph points. * * @author Samuel A. Rebelsky * @version 1.0 of April 2006 */ public class Graph { // +------------------+------------------------------------- // | Design Decisions | // +------------------+ /* (1) Graphs provide a simple wrapper for the Screen class, adding axis marks and changing the name of the setCharAt method to plot. */ // +--------+----------------------------------------------- // | Fields | // +--------+ /** The underlying screen used for the graph. */ Screen screen; /** The character used to plot points. */ char point; // +--------------+----------------------------------------- // | Constructors | // +--------------+ /** * Build a graph of specified height and width. */ public Graph(int _width, int _height) { // Create the screen this.screen = new Screen(_width+1, _height+1); // Fill in the axes screen.setCharAt(0,0,'+'); for (int x = 1; x <= _width; x++) { screen.setCharAt(x, 0, '-'); } for (int y = 1; y <= _height; y++) { screen.setCharAt(0, y, '|'); } // Set the default plot character point = '*'; } // Graph(int, int) // +------------------+------------------------------------- // | Standard Methods | // +------------------+ /** * Convert to a string (e.g., for printing). */ public String toString() { return this.screen.toString(); } // toString() // +----------------+--------------------------------------- // | Public Methods | // +----------------+ /** * Plot a point at (x,y). If (x,y) is not within the displayable * portion, show nothing. */ public void plot(int x, int y) { this.screen.setCharAt(x,y,this.point); } // plot(int, int) /** * Set the character used to plot points. */ public void setPlotChar(char ch) { this.point = ch; } // setPlotChar(char) } // class Graph