Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

( JAVA ) public class Rectangle { private double length,width; public Rectangle(

ID: 3689691 • Letter: #

Question

( JAVA )

public class Rectangle

{

   private double length,width;

  

   public Rectangle()

   {

   this.length=1.0;

   this.width=1.0;

   }

   public double getLength() {

   return length;

   }

   public double getWidth() {

   return width;

   }

   public void setLength(double length) {

   if(length>0.0 && length<20.0)this.length = length;

   else System.out.println("Rectangle length outof bounds!! Please enter between 0 and 20");

   }

   public void setWidth(double width) {

   if(width>0.0 && width<20.0)this.width = width;

   else System.out.println("Rectangle width outof bounds!! Please enter between 0 and 20");

   }

   public double perimeter()

   {

   return 2*(this.length+this.width);

   }

   public double area()

   {

   return this.length*this.width;

   }

}

   public class TestRectangle

{

   public static void main(String[] args);

}

   Rectangle r=new Rectangle();

   System.out.println("Length: "+r.getLength());

   System.out.println("Width: "+r.getWidth());

   System.out.println("Area: "+r.area());

   System.out.println("Perimeter: "+r.perimeter());

  

   r.setLength(-20);

   r.setWidth(100);

  

   r.setLength(10);

   r.setWidth(5);

   System.out.println("Length: "+r.getLength());

   System.out.println("Width: "+r.getWidth());

   System.out.println("Area: "+r.area());

   System.out.println("Perimeter: "+r.perimeter());

  

   }

}

HOW TO FIX THIS

Bestanals 39 40 41 042 public class Test public static void ain(String[]..args); Rectangle r-new Rectangle; System.out.printlnC"Length: "+r.getLength); System.out.printlnC"Width: "+r.getWidthO); System.out.printlnC"Area: "+r.area)) System.out.printlnC"Perimeter: "+r.perimeterO); 48 49 r.setLength(-20); 5 E o-. Problems @ Javadoc Declaration Console X jdk1.8.0 73.jdk/Contents/Home/bi TestRectangle [Java Application] /Library/Java/JavaVirtualMachin Exception in thread "main" java.lang.Error: Unresolved compilation problem: This method requires a body instead of a semicolon at TestRectangle.main(Rectangle.java:41)

Explanation / Answer

TestRectangle.java

public class TestRectangle

{

    public static void main(String[] args)

{

       Rectangle r=new Rectangle();

       System.out.println("Length: "+r.getLength());

       System.out.println("Width: "+r.getWidth());

       System.out.println("Area: "+r.area());

       System.out.println("Perimeter: "+r.perimeter());

    

       r.setLength(-20);

       r.setWidth(100);

    

       r.setLength(10);

       r.setWidth(5);

       System.out.println("Length: "+r.getLength());

       System.out.println("Width: "+r.getWidth());

       System.out.println("Area: "+r.area());

       System.out.println("Perimeter: "+r.perimeter());

    

   }

}

Rectangle.java

public class Rectangle

{

   private double length,width;

   public Rectangle()

   {

       this.length=1.0;

       this.width=1.0;

   }

   public double getLength() {

       return length;

   }

   public double getWidth() {

       return width;

   }

   public void setLength(double length) {

       if(length>0.0 && length<20.0)this.length = length;

       else System.out.println("Rectangle length outof bounds!! Please enter between 0 and 20");

   }

   public void setWidth(double width) {

       if(width>0.0 && width<20.0)this.width = width;

       else System.out.println("Rectangle width outof bounds!! Please enter between 0 and 20");

   }

   public double perimeter()

   {

       return 2*(this.length+this.width);

   }

   public double area()

   {

       return this.length*this.width;

   }

}

sample output

Length: 1.0                                                                                                                                                 
Width: 1.0                                                                                                                                                  
Area: 1.0                                                                                                                                                   
Perimeter: 4.0                                                                                                                                              
Rectangle length outof bounds!! Please enter between 0 and 20                                                                                               
Rectangle width outof bounds!! Please enter between 0 and 20                                                                                                
Length: 10.0                                                                                                                                                
Width: 5.0                                                                                                                                                  
Area: 50.0                                                                                                                                                  
Perimeter: 30.0