triangle.java

来自「一个大学本科java课程的大作业。要求利用GUI以及APPLET分别完成一个任务」· Java 代码 · 共 59 行

JAVA
59
字号

/**
 *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 + =
减小字号Ctrl + -
显示快捷键?