Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. public class Rectangle {
  2. private double length;
  3. private double width;
  4.  
  5. Rectangle(double length, double width) {
  6.  
  7. this.length = length;
  8. this.width = width;
  9. }
  10. public double getLength() {
  11. return this.length;
  12. }
  13. public void setLength(double length) {
  14. if((length >= 1.0) && (length <= 50.0)) {
  15. this.length = length;
  16. }
  17. else{
  18. this.length = 1.0;
  19. }
  20.  
  21.  
  22.  
  23. }
  24. public double getWidth() {
  25. return this.width;
  26. }
  27. public void setWidth(double width) {
  28. if((width >= 1.0) && (width <= 50.0))
  29. this.width = width;
  30. else{
  31. this.width = 1.0;
  32. }
  33.  
  34. }
  35.  
  36. public double getCalcPrimeter(){
  37.  
  38. return 2 *(this.getLength() * this.getWidth());
  39. }
  40. public double getArea(){
  41.  
  42. return (this.getWidth() * this.getLength());
  43. }
  44.  
  45.  
  46.  
  47.  
  48. @Override
  49. public String toString() {
  50. return "Rectangle [length=" + length + ", width=" + width + "]";
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement