import java.util.Scanner;
import java.util.InputMismatchException;

/**
 * Asks the user for a radius and then prints out the dimensions
 * of a circle and a sphere of that size.
 *
 * @author Zach Tomaszewski.
 * @version 31 Mar 2008
 */
public class Assignment12 {

  public static void main(String[] args) {

    Scanner input = new Scanner(System.in);
    String again = "yes";

    while (again.equalsIgnoreCase("yes")) {
      //get radius
      System.out.print("Please enter a radius: ");
      try {
        double radius = input.nextDouble();
        Circle ring = new Circle(radius); //circle as circle
        Circle round = new Sphere(radius);  //sphere as circle
        Sphere ball = new Sphere(radius);  //sphere as sphere

        //print circle details for a simple circle
        System.out.println();
        System.out.println("For " + ring.toString() + ": ");
        System.out.println("Diameter = " + ring.getDiameter());
        System.out.println("Circumference = " + ring.getCircumference());
        System.out.println("Area = " + ring.getArea());

        //print circle details for a sphere (seen as a circle)
        System.out.println();
        System.out.println("For " + round.toString() + " (as a Circle): ");
        System.out.println("Diameter = " + round.getDiameter());
        System.out.println("Circumference = " + round.getCircumference());
        System.out.println("Area = " + round.getArea());

        //print sphere details for a sphere
        System.out.println();
        System.out.println("For " + ball.toString() + ": ");
        System.out.println("Diameter = " + ball.getDiameter());
        System.out.println("Circumference = " + ball.getCircumference());
        System.out.println("Surface area = " + ball.getSurfaceArea());
        System.out.println("Volume = " + ball.getVolume());

      }catch (InputMismatchException ime) {
        //this is how you use try/catch to catch an exception
        System.out.println("Error: Sorry, that was not a number.");
      }

      //play again?
      System.out.println();
      System.out.print("Would you like to display the details of " +
                        "another circle/sphere (yes/no)? ");
      input.nextLine(); //clear input stream from nextDouble, above
      again = input.nextLine();
    }
  }

}
