Luninariel

ReadMe.

Oct 29th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. Rectangles
  2. Write a class called rectangles. The file has two private data members:
  3.  
  4. length: double
  5. width: double
  6. The length and the width are always positive doubles. If a negative value is given in a constructor it is set to 1.
  7.  
  8. Rectangles always have the longer of the two dimensions as the length. The width is always less than or equal to the length.
  9.  
  10. Constructors:
  11. Rectangle(length, width)
  12. Rectangle(side) -- Both the length and the width are set to the value of side
  13. Rectangle() -- Both the length and width are set to 1.0
  14. If the user specifies Rectangle(side) it should call this(side, side)
  15.  
  16. If the user specifies Rectangle() it should call this(1.0, 1.0)
  17.  
  18. Setters
  19. The setters are busy.
  20.  
  21. If the length is less than 0, the length should be set to 1
  22. After setting the length or the width, the values should be swapped if necessary so that the length is always larger (or as large as) the width
  23. Getters
  24. They should be standard getters.
  25.  
  26. toString
  27. The toString should be return the following value:
  28.  
  29. String.format("%1.4f x %1.4f", length, width);
  30. Other methods
  31. getArea()
  32. returns the area of the rectangle. This is a pseudo-getter because the result is calculated on the fly.
  33.  
  34. getPerimeter()
  35. returns length + width + length + width. It is another pseudo getter.
  36.  
  37. isSquare()
  38. returns true if the length == the width. Otherwise returns false.
Advertisement
Add Comment
Please, Sign In to add comment