public static void main(String args[]) {
    // the first value is the radius and the second value is the height
    Cylinder can = new Cylinder(3.0, 10.0);

    double surfaceArea, volume;

    surfaceArea =
        (2 * can.getRadius() * can.getHeight() * Math.PI)
            + (2 * Math.PI * Math.pow(can.getRadius(), 2));
    System.out.println("The surface area of a soda can is " + surfaceArea);

    volume = Math.PI * Math.pow(can.getRadius(), 2);
    System.out.println("The volume of a soda can is " + volume);
  } // ends main method
Exemple #2
0
 /**
  * Helper method
  *
  * @param c
  */
 public static void printStats(Cylinder c) {
   System.out.println("===");
   System.out.println("Radius: " + c.getRadius());
   System.out.println("Color: " + c.getColor());
   System.out.println("Height: " + c.getHeight());
   System.out.println("Base Area: " + c.getArea());
   System.out.println("Volume: " + c.getVolume());
   System.out.println("===");
 }
 public static double calculateCylinderVolume(Cylinder cylinder) {
   return Math.PI * Math.pow(cylinder.getRadius(), 2) * cylinder.getHeight();
 }
Exemple #4
0
  public static void main(String[] args) {
    Cylinder c1 = new Cylinder(); // no-arg constructor
    System.out.println(
        "cylinder #1 properties:\n"
            + "radius = "
            + c1.getRadius()
            + "\n"
            + "height = "
            + c1.getHeight()
            + "\n"
            + "base area = "
            + c1.getBaseArea()
            + "\n"
            + "surface area = "
            + c1.getArea()
            + "\n"
            + "volume = "
            + c1.getVolume()
            + "\n"
            + c1.toString()
            + "\n");

    Cylinder c2 = new Cylinder(10.0); // one-arg constructor
    System.out.println(
        "cylinder #2 properties:\n"
            + "radius = "
            + c2.getRadius()
            + "\n"
            + "height = "
            + c2.getHeight()
            + "\n"
            + "base area = "
            + c2.getBaseArea()
            + "\n"
            + "surface area = "
            + c2.getArea()
            + "\n"
            + "volume = "
            + c2.getVolume()
            + "\n"
            + c2.toString()
            + "\n");

    Cylinder c3 = new Cylinder(2.0, 10.0); // two-arg constructor
    System.out.println(
        "cylinder #3 properties:\n"
            + "radius = "
            + c3.getRadius()
            + "\n"
            + "height = "
            + c3.getHeight()
            + "\n"
            + "base area = "
            + c3.getBaseArea()
            + "\n"
            + "surface area = "
            + c3.getArea()
            + "\n"
            + "volume = "
            + c3.getVolume()
            + "\n"
            + c3.toString());
  }