BenitoDannes

PBO-4.2-1 Rectangle

Mar 20th, 2017
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. /**
  2.  * Program untuk mencari luas dan keliling
  3.  * persegi panjang.
  4.  *
  5.  * Benito Dannes
  6.  */
  7.  
  8. public class Rectangle
  9. {
  10.     public static final double DEFAULT_LENGTH = 15;
  11.     public static final double DEFAULT_WIDTH = 5;
  12.     public static final String DEFAULT_COLOR = "Black";
  13.    
  14.     private double width;
  15.     private double length;
  16.     private String color;
  17.    
  18.     public Rectangle()
  19.     {
  20.         length = DEFAULT_LENGTH;
  21.         width = DEFAULT_WIDTH;
  22.         color = DEFAULT_COLOR;
  23.     }
  24.    
  25.     public Rectangle (double length, double width)
  26.     {
  27.         this.length = length;
  28.         this.width = width;
  29.         color = DEFAULT_COLOR;
  30.     }
  31.    
  32.     public Rectangle (String color)
  33.     {
  34.         this.color = color;
  35.         length = DEFAULT_LENGTH;
  36.         width = DEFAULT_WIDTH;
  37.     }
  38.    
  39.     public Rectangle (String color, double length, double width)
  40.     {
  41.         this.color = color;
  42.         this.length = length;
  43.         this.width = width;
  44.     }
  45.    
  46.     public double getLength()
  47.     {
  48.         return length;
  49.     }
  50.    
  51.     public double getWidth()
  52.     {
  53.         return width;
  54.     }
  55.    
  56.     public String getColor()
  57.     {
  58.         return color;
  59.     }
  60.    
  61.     public double getArea()
  62.     {
  63.         return length * width;
  64.     }
  65.    
  66.     public double getCircumference()
  67.     {
  68.         return 2 * (length + width);
  69.     }
  70.    
  71.     public String toString()
  72.     {
  73.         return "Rectangle with length " + length + " and width " + width +
  74.             " and its' color is " + color;
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment