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.
46 lines
984 B
46 lines
984 B
public class Rectangle extends Shape{
|
|
private double width;
|
|
private double length;
|
|
|
|
public Rectangle() {
|
|
super();
|
|
this.width = 1.0;
|
|
this.length = 2.0;
|
|
}
|
|
|
|
public Rectangle(double width, double length){
|
|
super();
|
|
setLW(width,length);
|
|
}
|
|
|
|
public Rectangle(double width, double length,boolean isFilled,String color) {
|
|
super(isFilled, color);
|
|
setLW(width,length);
|
|
}
|
|
|
|
public double getWidth() {
|
|
return this.width;
|
|
}
|
|
|
|
public double getLength() {
|
|
return this.length;
|
|
}
|
|
|
|
public void setLW(double x, double y){
|
|
this.length = Math.max(x,y);
|
|
this.width = Math.min(x,y);
|
|
}
|
|
|
|
public double getArea() {
|
|
return this.length * this.width;
|
|
}
|
|
|
|
public String toString() {
|
|
String ret = "";
|
|
ret += "Width: " + this.width + "\n";
|
|
ret += "Length: " + this.length + "\n";
|
|
ret += "Area: " + getArea() + "\n";
|
|
ret += super.toString();
|
|
return ret;
|
|
}
|
|
}
|