📄 rectangle.java
字号:
/**
*Title:Rectangle.java
*Description:This class defines a rectangle and
*it is a subclasse of class Shape
*@author: Peng yu
*@version:1.0
*/
public class Rectangle extends Shape
{
//define a constructor which may throw exception
public Rectangle() throws IllegalRectangleException
{
//create the height and the width of the rectangle
//with random integer between 20 and 30.
this.height = (int)(20+Math.random()*11);
this.width = (int)(20+Math.random()*11);
if(this.height==this.width) //check if the rectangle is legal
throw new IllegalRectangleException();
}
/**
*This Method is to calculate the area
*@return the area of the rectangle
*/
public double calcShapeArea()
{
return (this.height)*(this.width);
}
/**
*This Method is to calculate the perimeter
*@return the perimeter of the rectangle
*/
public double calcShapePerimeter()
{
return 2*((this.height)+(this.width));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -