Advertisement
Guest User

Untitled

a guest
Sep 15th, 2009
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Geo
  4. { class Rectangle
  5. { protected double width;
  6. protected double height;
  7. public double Width{get{return width;}}
  8. public double Height{get{return height;}}
  9.  
  10. public Rectangle(double width, double height)
  11. { if(width > 0 && height > 0)
  12. { this.width = width;
  13. this.height = height;
  14. }
  15. else throw new ArgumentOutOfRangeException("bad data");
  16. }
  17. }
  18. class Square : Rectangle
  19. { public Square(double size):base(size, size){} }
  20.  
  21. class MutableRectangle : Rectangle
  22. { public MutableRectangle(double width, double height) : base(width, height){}
  23. public void setWidth(double width)
  24. { if(width>0) this.width = width;
  25. else throw new ArgumentOutOfRangeException("bad data");
  26. }
  27. public void setHeight(double height)
  28. { if(height>0) this.height = height;
  29. else throw new ArgumentOutOfRangeException("bad data");
  30. }
  31. }
  32. class MutableSquare : Square
  33. { public MutableSquare(double size):base(size){}
  34. public void setSize(double size)
  35. { if(size>0)
  36. { this.width=size;
  37. this.height=size;
  38. }
  39. else throw new ArgumentOutOfRangeException("bad data");}
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement