Hi DaniWeb community,
I'm trying to use the MultiCylinder class to instantiate and update the Cylinder objects that will print their radius and height. I also want to allow the user to input their own values for radius and height which will then calculate via the getVolume and getSurface area. I've been playing around with the code and I still get errors. Here is what i have so far.
public class Cylinder
{
double volume;
double surfaceArea;
double radius;
double height;
double result;
public Cylinder(double radius, double height)
{
this.radius = radius;
this.height = height;
}
public double getRadius ()
{
return radius;
}
public double getHeight()
{
return height;
}
public double getsurfaceArea()
{
return (2 * Math.PI * radius) * (radius + height);
}
public double getVolume()
{
return (Math.PI * height * Math.pow(radius, radius));
}
}
and,
import java.util.Scanner;
public class MultiCylinder {
public static void main(String[] args) {
Cylinder cyl1 = new Cylinder(0.0 , 0.0);
Cylinder cyl2 = new Cylinder(0.0 , 0.0);
Scanner scan = new Scanner (System.in);
System.out.println("radius: " + cyl1.getRadius());
System.out.println("height: " + cyl1.getHeight());
System.out.println("volume: " + cyl1.getVolume());
System.out.println("surface area: " + cyl1.getsurfaceArea());
}
}
Any tips ?