When running my program, I get the following error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at CylinderTest.main(Cylinder.java:42)
I'm sure there is an easy solution, but I am an inexperienced programmer and to me it seems like it should work.
Program Description: Write a class called CylinderTest.java and declare an array of three Cylinder objects to call the methods you declared in the Cylinder class. Make sure that all class methods are called from main(). Have main() display the value returned by volume() and verify the returned value by hand calculations (paper/pencil). Prompt the user to enter the values for the radius and height of each Cylinder object in the array.
public class Cylinder
{
private double radius;
private double height;
public Cylinder(double radius, double height)
{
this.radius = radius;
this.height = height;
}
public double getRadius()
{
return radius;
}
public double getHeight()
{
return height;
}
public double volume()
{
return radius*radius*height*3.1416;
}
}
public class CylinderTest
{
public static void main(String[] args)
{
Cylinder[] myCylinder = new Cylinder[3];
myCylinder [0] = new Cylinder (2,7);
myCylinder [1] = new Cylinder (9,3);
myCylinder [2] = new Cylinder (12,4);
for (Cylinder c: myCylinder)
{
System.out.println("*******");
System.out.println("Radius: " + c.getRadius());
System.out.println("Height: " + c.getHeight());
System.out.println("Volume: " + c.volume());
System.out.println("*******");
}
}
}