he rectangle’s perimeter and area
Question
I am having a difficult time with what I’m doing incorrect here. Could someone guide me in the right direction.
class Rectangle with attributes length and width, each of which defaults to 1. Provide methods that calculate the rectangle’s perimeter and area. Use set and get methods for both length and width. The set methods will verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0. A program to test class Rectangle.
public class Rectangle {
public float rectangle;
public float length;
public float width;
public float perimeter;
public float area;
public Rectangle(float length, float width){
if(length < 0.0 || length >= 20.0){
throw new IllegalArgumentException(“Length must be between 0.0 and 20.0”);
}
if(width < 0.0 || width >= 20.0){
throw new IllegalArgumentException(“Width must be between 0.0 abnd 20.00”);
}
this.length = length;
this.width = width;
}
public float getLength(){
return length;
}
public float getWidth(){
return width;
}
public void setPerimeter(float perimeter){
perimeter = ((getLength() *2) + (getWidth()*2));
}
public float getPerimeter(){
return perimeter;
}
public void setArea(float area){
area = getLength() * getWidth();
}
}
HERE IS MY TEST….
public class TestRectangle {
public static void main(String[] args){
Rectangle rectangle1 = new Rectangle( 3.2f,3.3f);
System.out.printf(“The perimeter of rectangle is: %d%n”,rectangle1.getPerimeter());
}
}