Advertisement
Flaron

Udemy_35. Cylinder

Sep 20th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. public class Circle {
  2. private double radius;
  3.  
  4. public Circle(double radius){
  5. if(radius<0) this.radius=0;
  6. else this.radius=radius;
  7. }
  8.  
  9. public double getRadius() {
  10. return radius;
  11. }
  12.  
  13. public double getArea(){
  14. return (radius*radius*Math.PI);
  15. }
  16. }
  17.  
  18.  
  19. public class Cylinder extends Circle {
  20. private double height;
  21.  
  22. public Cylinder(double radius, double height) {
  23. super(radius);
  24. if(height<0) this.height=0;
  25. else this.height = height;
  26. }
  27.  
  28. public double getHeight() {
  29. return height;
  30. }
  31.  
  32. public double getVolume() {
  33. return getArea()*getHeight();
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement