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