import java.util.Scanner; /** * An abstract geometric object. Provides some, but not much, functionality. * Probably should have get/set accessors for color, name and filled * @author gtowell * Created: 10/12/2020 */ public abstract class GeometricObject { /** The color of the object */ protected String color; /** The name of the object */ protected String name; /** When drawn, should the object get filled */ protected boolean filled; /** * The perimiter of the object * @return the perimiter */ abstract public int getPerimiter(); /** * The area enclosed by the object * @return the enclosed area */ abstract public int getArea(); public String toString() { return "This is a " + (filled?"filled ":"") + color + " " + name + " with perimiter " + getPerimiter() + " and area " + getArea(); } public static void main(String[] args) { try (Scanner scann = new Scanner(System.in);) { System.out.println("How many sides (0 to quit, -1 for circle)"); int sides = scann.nextInt(); while (sides!=0) { if (sides<0) { System.out.println("Radius"); new Circle(scann.nextInt()); } else { System.out.print("side length: "); new RegularPolygon(sides, scann.nextInt()); } System.out.println("How many sides (0 to quit, -1 for circle)"); sides = scann.nextInt(); } } } }