// FigureTester.java // Use to test FigurePrinter class(es) for CS 10, assignment 4, Fall 2008 // cmc, updated 11/1/08 /* Do not depend on changes you may make to this class. You will not turn it in. */ public class FigureTester { private enum FigureType { generic, rectangle, triangle } public static void main(String args[]) { // set figure type by command line argument if there is one FigureType type = FigureType.generic; if (args.length > 0) if (args[0].toLowerCase().charAt(0) == 'r') type = FigureType.rectangle; else if (args[0].toLowerCase().charAt(0) == 't') type = FigureType.triangle; // create three figure printer objects, one default and two others // that share identical data FigurePrinter p0, p1, p1copy; switch(type) { /*TEMP case rectangle: p0 = new RectanglePrinter(); p1 = new RectanglePrinter('H', 10, 8, 4); p1copy = new RectanglePrinter('H', 10, 8, 4); break; case triangle: p0 = new TrianglePrinter(); p1 = new TrianglePrinter('H', 10, 8); p1copy = new TrianglePrinter('H', 10, 8); break; TEMP*/ default: // generic p0 = new FigurePrinter(); p1 = new FigurePrinter('H', 10); p1copy = new FigurePrinter('H', 10); } // test access methods System.out.printf("%n%-10s%8s%8s%n", "attribute", "default", "other"); System.out.printf( "%-10s%8s%8s%n", "---------", "-------", "-----"); System.out.printf(" %-10s%5c%8c%n", "symbol", p0.getSymbol(), p1.getSymbol()); System.out.printf(" %-10s%5d%8d%n", "offset", p0.getOffset(), p1.getOffset()); /*TEMP if (type == FigureType.rectangle) { RectanglePrinter rp0 = (RectanglePrinter)p0, rp1 = (RectanglePrinter)p1; System.out.printf(" %-10s%5d%8d%n", "width", rp0.getWidth(), rp1.getWidth()); System.out.printf(" %-10s%5d%8d%n", "height", rp0.getHeight(), rp1.getHeight()); } else if (type == FigureType.triangle) { TrianglePrinter tp0 = (TrianglePrinter)p0, tp1 = (TrianglePrinter)p1; System.out.printf(" %-10s%5d%8d%n", "width", tp0.getWidth(), tp1.getWidth()); } TEMP*/ // test print method System.out.printf("%nDefault figure:%n"); p0.print(); System.out.println("Other figure:"); p1.print(); // test printAt method System.out.printf("%nDefault figure printAt(1):%n"); p0.printAt(1); System.out.println("Other figure printAt(2):"); p1.printAt(2); // test equals and compareTo methods System.out.printf("%ndefault equals other? %b%n", p0.equals(p1)); System.out.printf("other equals default? %b%n", p1.equals(p0)); System.out.printf("other equals a copy of it? %b%n", p1.equals(p1copy)); System.out.printf("other equals itself? %b%n", p1.equals(p1)); System.out.printf("other equals null? %b%n", p1.equals(null)); System.out.printf("default compared to other: %d%n", p0.compareTo(p1)); System.out.printf("other compared to default: %d%n", p1.compareTo(p0)); System.out.printf("other compared to a copy of it: %d%n", p1.compareTo(p1copy)); System.out.printf("other compared to itself: %d%n", p1.compareTo(p1)); // test set methods p1.setSymbol('G'); p1.setOffset(5); System.out.printf("%nChanged other symbol to %c%n", p1.getSymbol()); System.out.printf("Changed other offset to %d%n", p1.getOffset()); /*TEMP if (type == FigureType.rectangle) { RectanglePrinter r1 = (RectanglePrinter)p1; r1.setWidth(5); r1.setHeight(6); System.out.printf("Changed other width to %d%n", r1.getWidth()); System.out.printf("Changed other height to %d%n", r1.getHeight()); } if (type == FigureType.triangle) { TrianglePrinter t1 = (TrianglePrinter)p1; t1.setWidth(13); System.out.printf("Changed other width to %d%n", t1.getWidth()); } TEMP*/ System.out.println("Other figure now:"); p1.print(); } }