码迷,mamicode.com
首页 > 其他好文 > 详细

实验九

时间:2019-05-27 13:17:31      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:异常   rect   ati   class   int()   cep   exce   length   throw   

public class error {
 public static void main(String[] args) {
  point point1=new point(1,2);
  point point2=new point(1,2);
  point point3=new point(1,2);
  rectangle rectangle1=new rectangle(point1,0,0);
  triangle t=new triangle(point1,point2,point3);
  point pointx[]= new point[]{point1,point2};
  polygon polygonx=new polygon(pointx);
 }
}

class point{
 point(){}
 int x,y;
 public point(int x,int y)throws IllegalArgumentException
 {
  this.x=x;
  this.y=y;
  if(x<0||y<0){
   throw new IllegalArgumentException("抛出无效参数异常");
  }
 }
}

class rectangle extends point{
 public rectangle(point point1,int length,int width)throws IllegalArgumentException
 {
  if(length<0||width<0){
   throw new IllegalArgumentException("抛出无效参数异常");
  }
 }
}

class triangle extends point{
 public triangle(point point1,point point2,point point3)throws IllegalArgumentException
 {
  if((point1.x==point2.x)&&(point1.x==point3.x)&&(point1.y==point2.y)&&(point1.y==point3.y)){
   throw new IllegalArgumentException("抛出无效参数异常");
  }
 }
}

class polygon extends point{  

public polygon(point[] points)throws IllegalArgumentException  {   

if(points.length<3){    

throw new IllegalArgumentException("抛出无效参数异常");

  }  

}

}

实验九

标签:异常   rect   ati   class   int()   cep   exce   length   throw   

原文地址:https://www.cnblogs.com/Beyondhuman/p/10930088.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!