You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
984 B

7 years ago
  1. public class Rectangle extends Shape{
  2. private double width;
  3. private double length;
  4. public Rectangle() {
  5. super();
  6. this.width = 1.0;
  7. this.length = 2.0;
  8. }
  9. public Rectangle(double width, double length){
  10. super();
  11. setLW(width,length);
  12. }
  13. public Rectangle(double width, double length,boolean isFilled,String color) {
  14. super(isFilled, color);
  15. setLW(width,length);
  16. }
  17. public double getWidth() {
  18. return this.width;
  19. }
  20. public double getLength() {
  21. return this.length;
  22. }
  23. public void setLW(double x, double y){
  24. this.length = Math.max(x,y);
  25. this.width = Math.min(x,y);
  26. }
  27. public double getArea() {
  28. return this.length * this.width;
  29. }
  30. public String toString() {
  31. String ret = "";
  32. ret += "Width: " + this.width + "\n";
  33. ret += "Length: " + this.length + "\n";
  34. ret += "Area: " + getArea() + "\n";
  35. ret += super.toString();
  36. return ret;
  37. }
  38. }