实验九

---恢复内容开始---

package 异常;

public class Error {
public static void main(String[] args) {

point p1=new point(0,0);
point p2=new point(1,0);
point[] point= {p1,p2};
new polygon(point);
}
}
class point
{
int x;
int y;
point(){}
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
{
int length;
int width;
public rectangle(point point1,int length,int width)throws IllegalArgumentException
{
this.length=length;
this.width=width;
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.y)-(point2.x-point1.y))+((point2.x-point3.y)-(point3.x-point2.y))+((point3.x-point1.y)-(point3.y-point1.x))==0)
throw new IllegalArgumentException("无效的参数");
}
}
class polygon extends point
{
public polygon(point[] points)throws IllegalArgumentException
{
int i;
i=points.length;
if(i<=2)
throw new IllegalArgumentException("无效参数");
}
}

实验结果

---恢复内容结束---

 

posted @ 2019-05-26 20:18  me13  阅读(140)  评论(0编辑  收藏  举报