实验九
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("抛出无效参数异常");
}
}
}