Having trouble with "Rectangles" (am a simpleton) : I recently got back into coding and have forgotten most things (am a simpleton), tried warming up with a simple question ":Create a class Rectangle with instance variables length and width to have default value of 1 for both of them. The class should have suitable set and get methods for accessing its instance variables. The set    methods should verify that length and width are assigned a value that is larger than 0.0 and is lesser than 20.0, Provide suitable public methods to calculate the rectangle’s perimeter and area. Write a suitable class "RectangleTest" to test the Rectangle class.

What i came up with:

    package rectangle;
    public class Rectangle
    {
        private double width;
        private double length;
        public Rectangle()
        {
    	width=1;
    	length=1;
        }
        public Rectangle(double width, double length)
        {
            this.width = width;
    	    this.length = length;
        }
        public void setWidth(float width)
        {      
            this.width = width;        
        }
        public float getWidth()
        {
    	    return (float) width;
        }
        public void setLength(float length)
        {
            this.length = length;
        }
        public float getLength()
        {
    	    return (float) length;
        }
        public double getPerimeter()
        {
            return 2 * (width + length);
        }
        public double getArea()
        {
            return width * length;
        }   
    }


----------


    package rectangle;
    import java.util.Scanner;
    public class RectangleTest extends Rectangle 
    {   
        public static void main(String[] args)
        {               
            Scanner RectangleTest = new Scanner(System.in);
            System.out.print("Length: ");
            float lengthInput = RectangleTest.nextFloat();
            System.out.print("Width: ");
            float widthInput = RectangleTest.nextFloat();
            Rectangle rectangle = new Rectangle (lengthInput, widthInput);
            System.out.printf("Perimeter: %f%n",
            rectangle.getPerimeter());
            System.out.printf("Area: %f%n",
            rectangle.getArea());        
        }   
    }
 

code is fine, it's just i am not sure how to implement the between 0 - 20 without breaking everything and have tried different things, is it actually pretty easy?


