Java-defined rectangle class

Source: Internet
Author: User

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 ());
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.