Skip to content

Instantly share code, notes, and snippets.

@GrantSchiller
Created January 29, 2014 14:17
Show Gist options
  • Save GrantSchiller/8688890 to your computer and use it in GitHub Desktop.
Save GrantSchiller/8688890 to your computer and use it in GitHub Desktop.
public class Circle {
protected int radius;
public Circle(int r) {
setRadius(r);
}
public void setRadius(int r) {
radius = r;
}
public int getRadius() {
return radius;
}
public int getDiameter() {
return radius*2;
}
public double getArea() {
return (Math.pow(radius,2)*Math.PI);
}
}
public class Cylinder extends Circle {
private int height;
public Cylinder(int r, int h) {
super(r);
setRadius(r);
setHeight(h);
}
public void setHeight(int h) {
height = h;
}
public int getHeight() {
return height;
}
public double getVolume() {
return ((Math.pow(radius,2)*Math.PI)*height);
}
public double getSurfaceArea() {
return (2*Math.PI*Math.pow(radius,2) + 2*Math.PI*radius*height);
}
}
public class Runner {
public static void main(String[] args){
Cylinder c = new Cylinder(1,1);
System.out.println("Radius: "+ c.getRadius());
System.out.println("Height: "+ c.getHeight());
System.out.println("Diameter: "+ c.getDiameter());
System.out.println("Volume: "+ c.getVolume());
System.out.println("Surface Area: "+ c.getSurfaceArea());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment