iawitm

Untitled

Dec 3rd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. package shape;
  2.  
  3. public class Rectangle extends Shape {
  4.  
  5.     protected double width;
  6.     protected double length;
  7.  
  8.     public Rectangle(){}
  9.  
  10.     public Rectangle(double width, double length){
  11.         this.width = width;
  12.         this.length = length;
  13.     }
  14.  
  15.     public Rectangle(double width, double length, String color, boolean filled){
  16.         this.width = width;
  17.         this.length = length;
  18.         this.color = color;
  19.         this.filled = filled;
  20.     }
  21.  
  22.     public double getWidth() {
  23.         return width;
  24.     }
  25.  
  26.     public double getLength() {
  27.         return length;
  28.     }
  29.  
  30.     public void setLength(double length) {
  31.         this.length = length;
  32.     }
  33.  
  34.     public void setWidth(double width) {
  35.         this.width = width;
  36.     }
  37.  
  38.     @Override
  39.     double getArea() {
  40.         return getLength()*getWidth();
  41.     }
  42.  
  43.     @Override
  44.     double getPerimetr() {
  45.         return 2*(getLength()+getWidth());
  46.     }
  47.  
  48.     @Override
  49.     public String toString() {
  50.         return "Length: "+getLength()+", width: "+getWidth()+", color: "+getColor()+", filled: "+isFilled()+", area: "+getArea()+", perimetr: "+getPerimetr();
  51.     }
  52. }
Add Comment
Please, Sign In to add comment