Rectangle type
Package cn.edu. UIBE. Oop;
Public class rectangle {
Float width, height;
/**
* Calculated Area
* @ Return the area of the rectangle
*/
Public float getarea (){
Return width * height;
}
/**
* Calculate the perimeter
* @ Return the perimeter of the rectangle
*/
Public float getcircumference (){
Return 2 * (width + height );
}
/**
* Change the rectangle size.
* @ Param W width
* @ Param H height
*/
Public void resize (float W, float h ){
Width = W;
Height = h;
}
/**
* Width and height of the output rectangle
*/
Public void printsize (){
System. Out. println ("width:" + width + "height:" + height );
}
Public static void main (string [] ARGs ){
Rectangle R1 = new rectangle ();
Rectangle r2 = new rectangle ();
R1.resize (4.0f, 3.0f );
R2.resize (2, 5 );
R1.printsize ();
R2.printsize ();
System. Out. println ("area of rectangle 1:" + r1.getarea ());
System. Out. println ("area of rectangle 2:" + r2.getarea ());
System. Out. println ("perimeter of rectangle 1:" + r1.getcircumference ());
System. Out. println ("perimeter of rectangle 2:" + r2.getcircumference ());
}
}