Advertisement
mmayoub

Rectangle, 29.06.2021

Jun 26th, 2021
1,113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1.  
  2. public class Rectangle {
  3.     private double width = 1;
  4.     private double length = 1;
  5.  
  6.     public Rectangle() {
  7.     }
  8.  
  9.     public Rectangle(double width, double length) {
  10.         this.width = width;
  11.         this.length = length;
  12.     }
  13.  
  14.     public double getWidth() {
  15.         return width;
  16.     }
  17.  
  18.     public void setWidth(double width) {
  19.         this.width = width;
  20.     }
  21.  
  22.     public double getLength() {
  23.         return length;
  24.     }
  25.  
  26.     public void setLength(double length) {
  27.         this.length = length;
  28.     }
  29.  
  30.     public double getArea() {
  31.         return this.width * this.length;
  32.     }
  33.  
  34.     public double getPerimeter() {
  35.         return 2 * (this.width + this.length);
  36.     }
  37.  
  38.     @Override
  39.     public String toString() {
  40.         return "Rectangle[length=" + this.length + ", width=" + this.width + "]";
  41.     }
  42.  
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement