Advertisement
michelksu

Untitled

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