Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Program untuk mencari luas dan keliling
- * persegi panjang.
- *
- * Benito Dannes
- */
- public class Rectangle
- {
- public static final double DEFAULT_LENGTH = 15;
- public static final double DEFAULT_WIDTH = 5;
- public static final String DEFAULT_COLOR = "Black";
- private double width;
- private double length;
- private String color;
- public Rectangle()
- {
- length = DEFAULT_LENGTH;
- width = DEFAULT_WIDTH;
- color = DEFAULT_COLOR;
- }
- public Rectangle (double length, double width)
- {
- this.length = length;
- this.width = width;
- color = DEFAULT_COLOR;
- }
- public Rectangle (String color)
- {
- this.color = color;
- length = DEFAULT_LENGTH;
- width = DEFAULT_WIDTH;
- }
- public Rectangle (String color, double length, double width)
- {
- this.color = color;
- this.length = length;
- this.width = width;
- }
- public double getLength()
- {
- return length;
- }
- public double getWidth()
- {
- return width;
- }
- public String getColor()
- {
- return color;
- }
- public double getArea()
- {
- return length * width;
- }
- public double getCircumference()
- {
- return 2 * (length + width);
- }
- public String toString()
- {
- return "Rectangle with length " + length + " and width " + width +
- " and its' color is " + color;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment