// CSE 143, Winter 2009, Marty Stepp // A small testing program to play with various shape objects. // Demonstrates the polymorphism achieved by interfaces. public class TestShapes { public static void main(String[] args) { Circle circ = new Circle(12.0); Rectangle rect = new Rectangle(5.0, 7.0); Triangle tri = new Triangle(5, 12, 13); printInfo(circ); printInfo(rect); printInfo(tri); // We also declare collections by interface types: // Queue q = new LinkedList(); // List list = new ArrayList(); } // Prints some information about the given shape. // Any type of shape can be passed, and that object's version of // the behavior will be used. public static void printInfo(Shape s) { System.out.println("The shape: " + s); System.out.println("area : " + s.area()); System.out.println("perim: " + s.perimeter()); System.out.println(); } }