Advertisement
Flaron

Udemy_36. PoolArea

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