rectangle.java

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

JAVA
55
字号

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