Created
January 29, 2014 14:17
-
-
Save GrantSchiller/8688890 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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