///////////////////////////////////////////////////////////////////////////////////////////
//For RectangleTest.java
///////////////////////////////////////////////////////////////////////////////////////////
public class RectangleTest{
public static void main(String [] args){
//Create rectangle1 object
Rectangle rectangle1 = new Rectangle ();
rectangle1.setLength(2);
rectangle1.setWidth(4);
//Print Object 1 values and method
System.out.println("Length of Rectangle1 = "+ rectangle1.getLength());
System.out.println("Width of Rectangle1 = "+rectangle1.getWidth());
System.out.println("Area of Rectangle1 = "+rectangle1.getArea());
System.out.println("Perimeter of Rectangle1 = "+rectangle1.getPerimeter());
System.out.println();
//Create rectangle2 object
Rectangle rectangle2 = new Rectangle ();
rectangle2.setLength(4);
rectangle2.setWidth(6);
//Print Object 2 values and method
System.out.println("Length of Rectangle1 = "+ rectangle2.getLength());
System.out.println("Width of Rectangle1 = "+rectangle2.getWidth());
System.out.println("Area of Rectangle1 = "+rectangle2.getArea());
System.out.println("Perimeter of Rectangle1 = "+rectangle2.getPerimeter());
}
}
///////////////////////////////////////////////////////////////////////////////////////////
//For Rectangle.java
///////////////////////////////////////////////////////////////////////////////////////////
public class Rectangle{
private double length;
private double width;
public void setLength(double length){
this.length = length;
}
public void setWidth(double width){
this.width = width;
}
public double getLength(){
return length;
}
public double getWidth(){
return width;
}
public double getArea(){
return length * width;
}
public double getPerimeter(){
return 2*(length + width);
}
}