// Defines a Shape object that can be displayed // in an output file as a 3x3 cross. import java.io.PrintWriter; import java.io.FileNotFoundException; public class Shape { protected char symbol; protected int x; protected int y; public Shape(char theSymbol, int xPos, int yPos) { symbol = theSymbol; x = xPos; y = yPos; } public char getSymbol( ) { return symbol; } public int getX( ) { return x; } public int getY( ) { return y; } public String toString( ) { return String.format("%dx%d", x, y); } public void plot(Canvas theCanvas) { theCanvas.setPoint(symbol, x, y); theCanvas.setPoint(symbol, x + 1, y); theCanvas.setPoint(symbol, x, y + 1); theCanvas.setPoint(symbol, x - 1, y); theCanvas.setPoint(symbol, x, y - 1); } public static void main(String[ ] args) throws FileNotFoundException { // Create objects. Canvas c = new Canvas("output.txt", 100, 50); Shape s = new Shape('%', 30, 20); // Test methods of Shape object. System.out.println("symbol for s is " + s.getSymbol( )); System.out.println("x value for s is " + s.getX( )); System.out.println("y value for s is " + s.getY( )); System.out.println("toString output for s is " + s); // Plot shape on canvas. s.plot(c); // Write canvas to output file. c.write( ); } }