souaden12

02-09-2012, 12:37 AM

Hi

I'm new to Java and just started studying it in university right now

There is an excersie where we have to create a cylinder class, calculate its volume and surface area etc

Part of the excersie is to compare the volumes of two cylinder objects in the class and return the one with the bigger volume

The following is my code so far without the comparision method

public class Cylinder

{

private double radius;

private double height;

public Cylinder()

{

radius = 0.0;

height = 0.0;

}

public Cylinder (double radius, double height)

{

this.radius = radius;

this.height = height;

}

public double getRadius()

{

return radius;

}

public double getHeight()

{

return height;

}

public void printValues()

{

System.out.println("Radius: " + radius + " Height: " + height);

}

public double volume()

{

double volume = Math.PI*Math.pow(radius,2)*height;

return volume;

}

public double surfaceArea()

{

double surfaceArea = (2*Math.PI*Math.pow(radius,2))+(2*Math.PI*radius*height);

return surfaceArea;

}

}

can anyone explain to me how I can compare the volume values of two cylinders?

I don't want solution just explanations and hints

Thanx

I'm new to Java and just started studying it in university right now

There is an excersie where we have to create a cylinder class, calculate its volume and surface area etc

Part of the excersie is to compare the volumes of two cylinder objects in the class and return the one with the bigger volume

The following is my code so far without the comparision method

public class Cylinder

{

private double radius;

private double height;

public Cylinder()

{

radius = 0.0;

height = 0.0;

}

public Cylinder (double radius, double height)

{

this.radius = radius;

this.height = height;

}

public double getRadius()

{

return radius;

}

public double getHeight()

{

return height;

}

public void printValues()

{

System.out.println("Radius: " + radius + " Height: " + height);

}

public double volume()

{

double volume = Math.PI*Math.pow(radius,2)*height;

return volume;

}

public double surfaceArea()

{

double surfaceArea = (2*Math.PI*Math.pow(radius,2))+(2*Math.PI*radius*height);

return surfaceArea;

}

}

can anyone explain to me how I can compare the volume values of two cylinders?

I don't want solution just explanations and hints

Thanx