BLOG-2

BLOG-2|PTA作业|学习通

17207119胡立鑫

四边形

7-2 点线形系列4-凸四边形的计算

    用户输入一组选项和数据,进行与四边形有关的计算。
以下四边形顶点的坐标要求按顺序依次输入,连续输入的两个顶点是相邻顶点,第一个和最后一个输入的顶点相邻。
选项包括:
1:输入四个点坐标,判断是否是四边形、平行四边形,判断结果输出true/false,结果之间以一个英文空格符分隔。
2:输入四个点坐标,判断是否是菱形、矩形、正方形,判断结果输出true/false,结果之间以一个英文空格符分隔。 若四个点坐标无法构成四边形,输出"not a quadrilateral"
3:输入四个点坐标,判断是凹四边形(false)还是凸四边形(true),输出四边形周长、面积,结果之间以一个英文空格符分隔。 若四个点坐标无法构成四边形,输出"not a quadrilateral"
4:输入六个点坐标,前两个点构成一条直线,后四个点构成一个四边形或三角形,输出直线与四边形(也可能是三角形)相交的交点数量。如果交点有两个,再按面积从小到大输出四边形(或三角形)被直线分割成两部分的面积(不换行)。若直线与四边形或三角形的一条边线重合,输出"The line is coincide with one of the lines"。若后四个点不符合四边形或三角形的输入,输出"not a quadrilateral or triangle"。
后四个点构成三角形的情况:假设三角形一条边上两个端点分别是x、y,边线中间有一点z,另一顶点s:
1)符合要求的输入:顶点重复或者z与xy都相邻,如x x y s、x z y s、x y x s、s x y y。此时去除冗余点,保留一个x、一个y。
2) 不符合要求的输入:z 不与xy都相邻,如z x y s、x z s y、x s z y
5:输入五个点坐标,输出第一个是否在后四个点所构成的四边形(限定为凸四边形,不考虑凹四边形)或三角形(判定方法见选项4)的内部(若是四边形输出in the quadrilateral/outof the quadrilateral,若是三角形输出in the triangle/outof the triangle)。如果点在多边形的某条边上,输出"on the triangle或者on the quadrilateral"。若后四个点不符合四边形或三角形,输出"not a quadrilateral or triangle"。

输入格式:

 基本格式:选项+":"+坐标x+","+坐标y+" "+坐标x+","+坐标y。点的x、y坐标之间以英文","分隔,点与点之间以一个英文空格分隔。

输出格式:
基本输出格式见每种选项的描述。
异常情况输出:
如果不符合基本格式,输出"Wrong Format"。
如果符合基本格式,但输入点的数量不符合要求,输出"wrong number of points"。
注意:输出的数据若小数点后超过3位,只保留小数点后3位,多余部分采用四舍五入规则进到最低位。小数点后若不足3位,按原始位数显示,不必补齐。例如:1/3的结果按格式输出为 0.333,1.0按格式输出为1.0

选项1、2、3中,若四边形四个点中有重合点,输出"points coincide"。
选项4中,若前两个输入线的点重合,输出"points coincide"。

代码如下

import java.util.Scanner; // 需要导入 util 包
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        //  String ch = input.nextLine();
        PointTaking a = new PointTaking();
        a.ch = input.nextLine();//读入

        double ans =a.Solve();
        if (ans == -1)
            System.out.printf("Wrong Format\n");
        else if (ans == -2)
            System.out.printf("wrong number of points\n");
        else if (ans == -3)
            System.out.printf("data error\n");
        else if (ans==-4)
            System.out.printf("not a quadrilateral\n");
         else if (ans==-5)
            System.out.printf("not a quadrilateral or triangle");
        else if (ans == 1)
            System.out.printf("true\n");
        else if (ans == 2)
            System.out.printf("false\n");
        else  if(ans==4)
            System.out.printf("points coincide\n");

    }
}





class Line {
    Point a ,b;
    double slope(){//斜率
        if(this.a.x==this.b.x)
            return 563;
        //System.out.printf("\n1511565sada\n");
        return (this.a.y-this.b.y)/(this.a.x-this.b.x);
    }
    double intercept() {//截距
        if(slope()==563)
            return this.a.x;
        if(slope()==0)
            return 0;
        return a.x-(this.slope())*a.y;
    }
    double pointVerticalDistanc(Point c){//点到线距离
        if(this.a.x==this.b.x)
            return Math.abs(c.x-this.a.x);
        return (Math.abs((this.a.y-this.b.y)*c.x+(this.b.x-this.a.x)*c.y+this.a.x*this.b.y-this.a.y*this.b.x)/
                (Math.sqrt((this.a.y-this.b.y)*(this.a.y-this.b.y)+(this.a.x-this.b.x)*(this.a.x-this.b.x))));
    }
    int judgeIntersection(Line line){//判断线段是否相交,0:两线平行且嵌入 1 有焦点 -1平行 -2:无交点
        if(slope()==line.slope()&&intercept()==line.intercept())
            return 0;
        if(slope()==line.slope())
            return -1;
        Point point = this.intersection(line);
        if(point.x<=Math.max(line.a.x,line.b.x)&&point.x>=Math.min(line.a.x,line.b.x)&&point.y<=Math.max(line.a.y,line.b.y)&&point.y>=Math.min(line.a.y,line.b.y))
            return 1;

        return -1;
    }
    boolean sameIntersection(Line line1,Line line2){//判断相交点是否相同
        Point point1=this.intersection(line1),point2=this.intersection(line2);
       // System.out.printf("%f %f %f %f %f %f %f %f \n",line1.a.x,line1.a.y,line1.b.x,line1.b.y,line2.a.x,line2.a.y,line2.b.x,line2.b.y);
        return point2.x == point1.x && point1.y == point2.y;
    }
    double dis(){
        return a.DistanceCalculation(b);
    }//线长

    boolean judgeParallelism(Line a) {
        return a.slope() == this.slope();
    }
    Point intersection(Line line){//求相交点
        Point point1 = new Point();
        point1.x=((line.a.x-line.b.x)*(this.a.y*this.b.x-this.a.x*this.b.y)-(this.a.x-this.b.x)*(line.a.y*line.b.x-line.a.x*line.b.y))/
                ((this.b.y-this.a.y)*(line.b.x-line.a.x)-(this.b.x-this.a.x)*(line.b.y-line.a.y));
        point1.y=((line.a.y-line.b.y)*(this.a.y*this.b.x-this.a.x*this.b.y)-(this.a.y-this.b.y)*(line.a.y*line.b.x-line.a.x*line.b.y))/
                ((this.b.y-this.a.y)*(line.b.x-line.a.x)-(this.b.x-this.a.x)*(line.b.y-line.a.y));
        return point1;
    }

    boolean dotLineJudgment(Point point){//判断点是否在直线上
        Line line2 = new Line();
        line2.a = point;line2.b=this.b;
        if((point.x==a.x&&point.y==a.y)||(point.x==b.x&&point.y== b.y))
            return true;
     //   System.out.printf("%f %f %f %f %f %f %f %f "+(line2.slope()==slope())+"\n",a.x,a.y,b.x,b.y,point.x,point.y,slope(),line2.slope());
        return line2.slope() == this.slope() && line2.intercept() == this.intercept();
    }
    boolean vertical(Line line){
        return (a.x - b.x) * (line.a.x - line.b.x) + (a.y - b.y) * (line.a.y - line.b.y) == 0;
    }
}






class Point {//点的类
    double x = 0 , y = 0 ;
    double DistanceCalculation(Point b) {
        return Math.sqrt((this.x-b.x)*(this.x-b.x)+(this.y-b.y)*(this.y-b.y));
    }//返回两点距离
}



class Triangle {
    Line []line = new Line[8];
    double area() {//三角形面积
        double p= (Math.sqrt((line[1].a.x-line[1].b.x)*(line[1].a.x-line[1].b.x)+(line[1].a.y-line[1].b.y)*(line[1].a.y-line[1].b.y))+Math.sqrt((line[2].a.x-line[2].b.x)*(line[2].a.x-line[2].b.x)+(line[2].a.y-line[2].b.y)*(line[2].a.y-line[2].b.y))+ Math.sqrt((line[3].a.x-line[3].b.x)*(line[3].a.x-line[3].b.x)+(line[3].a.y-line[3].b.y)*(line[3].a.y-line[3].b.y)) )/2;
        return Math.sqrt(p*(p- Math.sqrt((line[1].a.x-line[1].b.x)*(line[1].a.x-line[1].b.x)+(line[1].a.y-line[1].b.y)*(line[1].a.y-line[1].b.y)) )*(p - Math.sqrt((line[2].a.x-line[2].b.x)*(line[2].a.x-line[2].b.x)+(line[2].a.y-line[2].b.y)*(line[2].a.y-line[2].b.y)) )*(p- Math.sqrt((line[3].a.x-line[3].b.x)*(line[3].a.x-line[3].b.x)+(line[3].a.y-line[3].b.y)*(line[3].a.y-line[3].b.y)) ));
    }
    void init(Line line1,Line line2,Point point1,Point point2){
        for(int i=1;i<=3;i++){
            line[i] = new Line();
            line[i].a= new Point();
            line[i].b = new Point();
        }
        line[1].a.x=line1.a.x;line[1].a.y=line1.a.y;
        line[1].b.x=line1.b.x;line[1].b.y=line1.b.y;
        line[2].a.x=line2.a.x;line[2].a.y=line2.a.y;
        line[2].b.x=line2.b.x;line[2].b.y=line2.b.y;
        line[3].a.x=point1.x;line[3].a.y=point1.y;
        line[3].b.x=point2.x;line[3].b.y=point2.y;
    }
    void init(Point point3,Point point1,Point point2) {
        for(int i=1;i<=3;i++){
            line[i] = new Line();
            line[i].a= new Point();
            line[i].b = new Point();
        }
        line[1].a.x=point1.x;line[1].a.y=point1.y;
        line[1].b.x=point2.x;line[1].b.y=point2.y;

        line[2].a.x=point2.x;line[2].a.y=point2.y;
        line[2].b.x=point3.x;line[2].b.y=point3.y;

        line[3].a.x=point3.x;line[3].a.y=point3.y;
        line[3].b.x=point1.x;line[3].b.y=point1.y;
    }
    void pointRelation(Point point){
        Triangle b= new Triangle(),c= new Triangle(),d= new Triangle();
        //System.out.printf("%f %f %f %f %f %f\n",line[1].a.x,line[1].a.y,line[2].a.x,line[2].a.y,line[3].a.x,line[3].a.y);
        b.init(point,line[3].a,line[3].b);c.init(point,line[2].a,line[2].b);d.init(point,line[1].a,line[1].b);
        if(d.area()==0||b.area()==0||c.area()==0)
            System.out.println("on the triangle");
        else if(Math.abs(area()-b.area()-c.area()-d.area())<0.0005)
            System.out.printf("in the triangle");
        else
            System.out.println("outof the triangle");
    }

}








class PointTaking {
    String ch;
    Quadrilateral q ;

    public static double printDouble(double num) {
        String str = String.format("%.3f",num);
        num = Double.parseDouble(str);
        return num;
    }
    public static double vectorComputation(Point a,Point b,Point c){//计算点线是否相交
        double x1 = a.x-c.x, y1=a.y-c.y,x2=b.x-c.x,y2=b.y-c.y;
        return  x1*y2-x2*y1;
    }//&ensp;&ensp;

    boolean repetitionPointJudgment(Point a[],int x){//相同点
        if(x<=3){
            for(int i=1;i<=4;i++){//如果一样则返回
                // System.out.printf("%f %f\n",pointSet[i].x,pointSet[i].y);
                for(int j = i+1;j<=4;j++)
                    if(a[i].x==a[j].x&&a[i].y==a[j].y)
                        return true;
          }

        }
        else if(x==4){
            return a[1].x == a[2].x && a[1].y == a[2].y;
        }
        return false;
    }
    int  repetitionPointJudgment2(Point[] points,int x){
        if(x==5)
            x=1;
        else x=2;
        int num=0;
        for(int i=x+1;i<=x+4;i++){
            for(int j=i+1;j<=x+4;j++)
                if(points[i].x== points[j].x&&points[i].y==points[j].y)
                    num++;
        }
        return num;
    }
    public  static  double areaCalculation(Point a,Point b,Point c,Line d,double s) {//计算面积case4
        Line aa = new Line();
        Line bb = new Line();
        aa.a=a;aa.b=b;
        bb.a=a;bb.b=c;
        Point x1 = aa.intersection(d);
        Point x2 = bb.intersection(d);
        double q = (a.DistanceCalculation(b)*a.DistanceCalculation(c));
        double p = (a.DistanceCalculation(x1)*a.DistanceCalculation(x2));
//        System.out.printf(p+" "+q+" ");
//        Systemystem.out.printf(s+" ");
        return (s*p)/q;
    }

    double Solve() {
        Point[] pointSet = new Point[15];//储存点
        int pos = 0;
        //  String[]
        String[] splitSet1 = this.ch.split(":");//将字符串以冒号分割,剥离选项与坐标
        if (splitSet1.length != 2)
            return -1;
        if (!splitSet1[0].matches("[1-5]"))//判断选项是否合规
            return -1;
        int x = Integer.parseInt(splitSet1[0]);//剥离出第选项
        int[] digitalDeposit = {0, 4, 4, 4, 6, 5
                                                                                                                };//定义选项要的点数
        for (int i = 1; i <= 10; i++)
            pointSet[i] = new Point();//new多个点

        String[] splitSet2 = splitSet1[1].split(" ");
        for (String i : splitSet2) {//对分割的字符串遍历
            int count=2;
            String[] splitSet3 = i.split(",");
            for (String j : splitSet3) {
                if (!j.matches("^[+-]?(([1-9]\\d*\\.\\d+)|(0\\.\\d+)|([1-9]\\d*)|0)$"))//正则表达式判断是否合法
                    return -1;//返回输入错误
                int pos2 = pos / 2 + 1;
                //      System.out.printf(pos2+"");
                if ((pos & 1) == 0)//按位读入坐标
                    pointSet[pos2].x = Double.parseDouble(j);
                else if ((pos & 1) == 1)
                    pointSet[pos2].y = Double.parseDouble(j);
                pos++;
                count--;
            }
            if(count!=0)
                return -1;
        }
        if (splitSet2.length != digitalDeposit[x])
            return -2;//返回错误点数量
        if(repetitionPointJudgment(pointSet,x)&&x!=2)
            return 4;
        createQuadrilateral(x,pointSet);
        return juSample(x,pointSet);
    }
    void createQuadrilateral(int x,Point[] points){
        int []a={0,1,1,1,3,2};
        q = new Quadrilateral();
        for(int i=1;i<=4;i++){
            q.line[i]=new Line();

            q.line[i].a=points[(i-1)%4+a[x]];
            q.line[i].b=points[i%4+a[x]];
            //System.out.printf(q.line[i].a.x+" "+q.line[i].a.y+"\n");
        }
    }
    double juSample(int x, Point[] points){
        if(x==1)
            return sample1(points);
        else if(x==2)
            return sample2(points);
        else if(x==3)
            return sample3(points);
        else if(x==4)
            return sample4(points);
        else if(x==5)
            return sample5(points);
        return -1;
    }

    double sample1(Point[] points){

        if(q.quadrilateralOrNot()){
            System.out.print("false false");
            return 5;
        }
        if(q.parallel())
            System.out.print("true true");
        else System.out.print("true false");

        return 5;
    }
    double sample2(Point[] points){
        if(q.quadrilateralOrNot() || repetitionPointJudgment(points,4))
            return -4;
        boolean flag1,flag2;
        flag1=q.judgeDiamond();
        flag2=q.judgeRectangle();
        if(flag1&&flag2)
            System.out.print("true true true");
        else if(flag1)
            System.out.print("true false false");
        else if(flag2)
            System.out.print("false true false");
        else
            System.out.print("false false false");
        return 5;
    }
    double sample3(Point[] points){
        if(repetitionPointJudgment(points,4))
            return -4;
        
        if(q.bump())
            System.out.printf("true ");
        else System.out.printf("false ");
        System.out.printf(printDouble(q.perimeter())+" "+printDouble(q.area()));
        return 5;
    }
    double sample4(Point[] points){
        if(q.fourPointsCollinear()||q.illegalShape())
            return -5;
        Line line= new Line();
        line.a=points[1];line.b=points[2];
         if(q.lineEdgeIntersection(line)) {
            System.out.printf("The line is coincide with one of the lines");
             return 5;
        }
        int num = q.focalPoints(line);
        System.out.printf(num+"");
        if(num<2){

            return 5;
        }
        Quadrilateral[] qua = new Quadrilateral[3];
        return 5;
    }
    double sample5(Point[] points) {

        Triangle tri;
        int num = repetitionPointJudgment2(points, 5);
        if (num > 1||q.fourPointsCollinear()||q.illegalShape())
                    return -5;
        if (num == 1) {
            tri = homonymousTriangle(points,2);
            tri.pointRelation(points[1]);
            return 5;
        }
        if (q.line[1].slope() == q.line[2].slope() || q.line[2].slope() == q.line[3].slope() || q.line[3].slope() == q.line[4].slope() || q.line[4].slope() == q.line[1].slope()) {
            tri = q.generateTriangle();
            tri.pointRelation(points[1]);
            return  5;
        }
        q.pointRelation(points[1]);
        return  5;
    }
    Triangle homonymousTriangle(Point[] points,int x){
        Triangle tri= new Triangle();
        for(int i=x;i<=x+3;i++)
            for(int j=i+1;j<=x+3;j++)
                if(points[i].x==points[j].x&&points[i].y==points[j].y) {
                    if(i==x+1)
                        tri.init(points[x+3],points[x],points[x+2]);
                    if(i==x+2)
                        tri.init(points[x+1],points[x],points[x+3]);
                    if(i==x+3)
                        tri.init(points[x],points[x+1],points[x+2]);
                    if(i==x)
                        tri.init(points[x+1],points[x+3],points[x+2]);

                    return tri;
                }

        return tri;
    }
}







class Quadrilateral {
    Line []line = new Line[5];
    boolean quadrilateralOrNot(){
        return  line[1].judgeIntersection(line[3])==1|| line[2].judgeIntersection(line[4]) ==1 || line[1].dotLineJudgment(line[3].a) || line[1].dotLineJudgment(line[3].b) || line[3].dotLineJudgment(line[1].a) || line[3].dotLineJudgment(line[1].b);


    }
    boolean parallel(){//判断平行四边形
        return line[1].slope() == line[3].slope() && line[2].slope() == line[4].slope();
    }
    boolean judgeDiamond(){//判断是否菱形
        return parallel()&&Math.abs(line[1].dis()-line[2].dis())<0.05;
    }
    boolean judgeRectangle(){//判断矩形
        return line[1].vertical(line[2])&&line[1].judgeParallelism(line[3])&&line[2].judgeParallelism(line[4]);
    }
    boolean fourPointsCollinear(){//判断不能组成三角形或者四边形
     //   System.out.printf(line[1].slope()+" "+line[2].slope()+" "+line[3].slope()+" "+line[4].slope()+"\n");
        return line[1].slope()==line[2].slope()&&line[2].slope()==line[3].slope()&&line[3].slope()==line[4].slope();
    }

    double perimeter(){//周长
        return line[1].dis()+line[2].dis()+line[3].dis()+line[4].dis();
    }
    Triangle[] division(){//划分三角形
        Line a = new Line(),b = new Line();
        Triangle [] tri = new Triangle[5];
        for(int i=1;i<=4;i++)
            tri[i]= new Triangle();
        a.a=line[1].a;a.b=line[3].a;
        b.a=line[1].b;b.b=line[3].b;
        tri[1].line[1]=line[1];
        tri[1].line[2]=line[2];
        tri[1].line[3]=a;

        tri[2].line[1]=line[3];
        tri[2].line[2]=line[4];
        tri[2].line[3]=a;

        tri[3].line[1]=line[1];
        tri[3].line[2]=line[4];
        tri[3].line[3]=b;

        tri[4].line[1]=line[3];
        tri[4].line[2]=line[2];
        tri[4].line[3]=b;
        return tri;
    }

    double area(){//面积
        Triangle [] tri = division();
        return Math.min(tri[1].area()+tri[2].area(),tri[3].area()+tri[4].area());
    }
    boolean bump(){//判断凹凸
        Triangle [] tri = division();

        return tri[1].area() + tri[2].area() == tri[3].area() + tri[4].area();
    }
    int focalPoints(Line line2) {//求线与其焦点数量
        int num=0;
        boolean []flag={false,false,false,false,false};
       
        for(int i=1;i<=4;i++) {
            if (line2.judgeIntersection(line[i]) == 1) {
                num++;
                flag[i] = true;
            }
            //System.out.printf(num + "\n");
        }
//         for(int i=1;i<=4;i++){
//             if(flag[i]&&line2.sameIntersection(line[i],line[i%4+1]))
//                 num--;
//            // System.out.printf(num+"\n");
//         }
        return num;
    }//4:-1,-1 1,1 0,0 2,0 3,0 0,5
    //4:-1,-1 1,1 0,0 5,0 5,5 0,5
    Triangle generateTriangle(){
        Triangle tri = new Triangle();
        if(line[1].slope()==line[2].slope())
            tri.init(line[3],line[4],line[1].a,line[2].b);
        else if(line[3].slope()==line[2].slope())
            tri.init(line[4],line[1],line[2].a,line[3].b);
        else if(line[3].slope()==line[4].slope())
            tri.init(line[1],line[2],line[3].a,line[4].b);
        else if(line[1].slope()==line[4].slope())
            tri.init(line[2],line[3],line[4].a,line[1].b);

        return tri;
    }
    void pointRelation(Point point){
        Triangle a=new Triangle(),b= new Triangle(),c= new Triangle(),d= new Triangle();
        b.init(point,line[3].a,line[3].b);c.init(point,line[2].a,line[2].b);d.init(point,line[1].a,line[1].b);
        a.init(point,line[4].a,line[4].b);
        if((d.area()==0||b.area()==0||c.area()==0||a.area()==0)&&(Math.abs(area()-a.area()-b.area()-c.area()-d.area())<0.0005))
            System.out.println("on the quadrilateral");
        else if(Math.abs(area()-a.area()-b.area()-c.area()-d.area())<0.0005)
            System.out.printf("in the quadrilateral");
        else
            System.out.println("outof the quadrilateral");
    }
    boolean illegalShape(){
        for (int i=1;i<=4;i++)
            if(line[i].slope()==line[i%4+1].slope()){
                if((line[i].a.x>line[i].b.x&&line[i%4+1].b.x>line[i%4+1].a.x)||
                        (line[i].a.x<line[i].b.x&&line[i%4+1].b.x<line[i%4+1].a.x)||
                        (line[i].a.y>line[i].b.y&&line[i%4+1].b.y>line[i%4+1].a.y)||
                        (line[i].a.y<line[i].b.y&&line[i%4+1].b.y<line[i%4+1].a.y))
                    return true;
            }
        return false;
    }
//    Quadrilateral[] division(Quadrilateral q,Line line2){
//        return q;
//    }
    boolean lineEdgeIntersection(Line line2){
        return line2.judgeIntersection(line[1]) == 0 || line2.judgeIntersection(line[2]) == 0 ||
                line2.judgeIntersection(line[3]) == 0 || line2.judgeIntersection(line[4]) == 0;
    }

}

五边形

7-1 点线形系列5-凸五边形的计算-1

用户输入一组选项和数据,进行与五边形有关的计算。
以下五边形顶点的坐标要求按顺序依次输入,连续输入的两个顶点是相邻顶点,第一个和最后一个输入的顶点相邻。
选项包括:
1:输入五个点坐标,判断是否是五边形,判断结果输出true/false。
2:输入五个点坐标,判断是凹五边形(false)还是凸五边形(true),如果是凸五边形,则再输出五边形周长、面积,结果之间以一个英文空格符分隔。 若五个点坐标无法构成五边形,输出"not a pentagon"
3:输入七个点坐标,前两个点构成一条直线,后五个点构成一个凸五边形、凸四边形或凸三角形,输出直线与五边形、四边形或三角形相交的交点数量。如果交点有两个,再按面积从小到大输出被直线分割成两部分的面积(不换行)。若直线与多边形形的一条边线重合,输出"The line is coincide with one of the lines"。若后五个点不符合五边形输入,若前两点重合,输出"points coincide"。

以上3选项中,若输入的点无法构成多边形,则输出"not a polygon"。输入的五个点坐标可能存在冗余,假设多边形一条边上两个端点分别是x、y,边线中间有一点z,另一顶点s:
1)符合要求的输入:顶点重复或者z与xy都相邻,如:x x y s、x z y s、x y x s、s x y y。此时去除冗余点,保留一个x、一个y。
2) 不符合要求的输入:z不与xy都相邻,如:z x y s、x z s y、x s z y

输入格式:

基本格式:选项+":"+坐标x+","+坐标y+" "+坐标x+","+坐标y。点的x、y坐标之间以英文","分隔,点与点之间以一个英文空格分隔。

输出格式:

基本输出格式见每种选项的描述。
异常情况输出:
如果不符合基本格式,输出"Wrong Format"。
如果符合基本格式,但输入点的数量不符合要求,输出"wrong number of points"。
注意:输出的数据若小数点后超过3位,只保留小数点后3位,多余部分采用四舍五入规则进到最低位。小数点后

代码如下



import java.util.Scanner; // 需要导入 util 包
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        //  String ch = input.nextLine();
        PointTaking a = new PointTaking();
        a.ch = input.nextLine();//读入

        double ans =a.Solve();
        if (ans == -1)
            System.out.printf("Wrong Format\n");
        else if (ans == -2)
            System.out.printf("wrong number of points\n");
        else if (ans == -3)
            System.out.printf("data error\n");
        else if (ans==-4)
            System.out.printf("not a pentagon\n");
        else if (ans==-5)
            System.out.printf("not a polygon");
        else if (ans == 1)
            System.out.printf("true\n");
        else if (ans == 2)
            System.out.printf("false\n");
        else  if(ans==4)
            System.out.printf("points coincide\n");

    }
}

 class Line {
    Point a ,b;
    public Line(){

    }
    public Line(Point point1,Point point2){
        a = new Point(point1);
        b = new Point(point2);
    }
    public Line(Line line){
        a = new Point();
        b = new Point();
        a.x = line.a.x;a.y = line.a.y;
        b.x=line.b.x;b.y = line.b.y;
    }
    boolean judgeIntersection(Line line2){
        if(slope()==line2.slope())
            return false;
        Point point = intersection(line2);
        //System.out.printf("\n\n"+point.x+" "+point.y+"\n\n");
        if(dotLineJudgment(point)&&line2.dotLineJudgment(point))
            return true;
        return false;
    }
    double slope(){//斜率
        if(this.a.x==this.b.x)
            return 9521462;

        //System.out.printf("\n1511565sada\n");
        return (this.a.y-this.b.y)/(this.a.x-this.b.x);
    }
    double intercept() {//截距
        if(slope()==9521462)
            return this.a.x;
        if(slope()==0)
            return 0;
        return a.x-(this.slope())*a.y;
    }
    double pointVerticalDistanc(Point c){//点到线距离
        if(this.a.x==this.b.x)
            return Math.abs(c.x-this.a.x);
        return (Math.abs((this.a.y-this.b.y)*c.x+(this.b.x-this.a.x)*c.y+this.a.x*this.b.y-this.a.y*this.b.x)/
                (Math.sqrt((this.a.y-this.b.y)*(this.a.y-this.b.y)+(this.a.x-this.b.x)*(this.a.x-this.b.x))));
    }
    boolean sameIntersection(Line line1,Line line2){//判断相交点是否相同
        Point point1=this.intersection(line1),point2=this.intersection(line2);
        return point2.x == point1.x && point1.y == point2.y&&this.dotLineJudgment(point1)&&dotLineJudgment(point2)&&
                line1.dotLineJudgment(point1)&&line2.dotLineJudgment(point2);
    }
    double dis(){
        return a.DistanceCalculation(b);
    }//线长

    boolean judgeParallelism(Line line) {
        return  Math.abs((line.a.x-line.b.x )*(a.y-b.y)- (a.x-b.x )*(line.a.y-line.b.y))<0.05;
    }
    Point intersection(Line line){//求相交点
        Point point1 = new Point();
        point1.x=((line.a.x-line.b.x)*(this.a.y*this.b.x-this.a.x*this.b.y)-(this.a.x-this.b.x)*(line.a.y*line.b.x-line.a.x*line.b.y))/
                ((this.b.y-this.a.y)*(line.b.x-line.a.x)-(this.b.x-this.a.x)*(line.b.y-line.a.y));
        point1.y=((line.a.y-line.b.y)*(this.a.y*this.b.x-this.a.x*this.b.y)-(this.a.y-this.b.y)*(line.a.y*line.b.x-line.a.x*line.b.y))/
                ((this.b.y-this.a.y)*(line.b.x-line.a.x)-(this.b.x-this.a.x)*(line.b.y-line.a.y));
        return point1;
    }

    boolean dotLineJudgment(Point point){//判断点是否在直线上
        Line line2 = new Line(a,point);
        if(a.x==b.x)
            return  this.judgeParallelism(line2) &&Math.max(a.y,b.y)>=point.y&&Math.min(a.y,b.y)<=point.y;
        else {
            return this.judgeParallelism(line2) &&Math.max(a.x,b.x)>=point.x&&Math.min(a.x,b.x)<=point.x;
        }

    }
    boolean vertical(Line line){
        return (a.x - b.x) * (line.a.x - line.b.x) + (a.y - b.y) * (line.a.y - line.b.y) == 0;
    }
    boolean overlap(Line line){
        if(a.x==b.x)
            return (line.slope()==slope()&&line.intercept()==intercept())&&((line.a.y<=Math.max(a.y,b.y)&&line.a.y>=Math.min(a.y,b.y))||
                    (line.b.y<=Math.max(a.y,b.y)&&line.b.y>=Math.min(a.y,b.y)));
        return (line.slope()==slope()&&line.intercept()==intercept())&&((line.a.x<=Math.max(a.x,b.x)&&line.a.x>=Math.min(a.x,b.x))||
                (line.b.x<=Math.max(a.x,b.x)&&line.b.x>=Math.min(a.x,b.x)));

    }
}


class Pentagon {
    Line[] line = new Line [6];
    public Pentagon(){}

    public Pentagon(Point point1,Point point2,Point point3,Point point4,Point point5) {
        for(int i=1;i<=5;i++){
            line[i] = new Line();
            line[i].a = new Point();
            line[i].b = new Point();
        }
        line[1].a.x = point1.x;line[1].a.y = point1.y;
        line[1].b.x = point2.x;line[1].b.y = point2.y;

        line[2].a.x = point2.x;line[2].a.y = point2.y;
        line[2].b.x = point3.x;line[2].b.y = point3.y;

        line[3].a.x = point3.x;line[3].a.y = point3.y;
        line[3].b.x = point4.x;line[3].b.y = point4.y;

        line[4].a.x = point4.x;line[4].a.y = point4.y;
        line[4].b.x = point5.x;line[4].b.y = point5.y;

        line[5].a.x = point5.x;line[5].a.y = point5.y;
        line[5].b.x = point1.x;line[5].b.y = point1.y;
    }

    boolean legal(){
        for(int i=1;i<=5;i++) {
         //   System.out.printf("%f %f\n",line[i].a.x,line[i].a.y);
            if ((line[i].a.x-line[i].b.x )*(line[i%5+1].a.y-line[i%5+1].b.y)== (line[i%5+1].a.x-line[i%5+1].b.x )*(line[i].a.y-line[i].b.y))
                return false;
        }
        for(int i=1;i<=5;i++){
            for (int j=1;j<=5;j++){

                if(j!=(i%5+1)&&j!=(i+3)%5+1&&i!=j) {
            //        System.out.printf("%f %f %f %f\n",line[i].a.x,line[i].a.y,line[j].a.x,line[j].a.y);
                    if (line[i].judgeIntersection(line[j]))
                        return false;
                }
            }
        }
        return true;
    }
    double area(){
        Triangle []tri=new Triangle[5];
        Line[] lines= new Line[4];
        lines[1] = new Line(line[1].a,line[2].b);
        lines[2] = new Line(line[1].a,line[3].b);
        tri[1]= new Triangle(line[1],line[2],lines[1]);
        tri[2]= new Triangle(lines[1],line[3],lines[2]);
        tri[3]= new Triangle(lines[2],line[4],line[5]);
        return tri[1].area()+tri[2].area()+tri[3].area();
    }
    boolean bump(){//判断凹凸,凹为true
        Triangle []tri=new Triangle[5];
        Line[] lines= new Line[4];
        double num = 0,temp = 0;
        lines[1] = new Line(line[1].a,line[2].b);
        lines[2] = new Line(line[1].a,line[3].b);
        tri[1]= new Triangle(line[1],line[2],lines[1]);
        tri[2]= new Triangle(lines[1],line[3],lines[2]);
        tri[3]= new Triangle(lines[2],line[4],line[5]);
        num = tri[1].area()+tri[2].area()+tri[3].area();
        for(int i = 2;i<=5;i++){

            lines[1]=new Line(line[i].a,line[i%5+1].b);
            lines[2]=new Line(line[i].a,line[(i+1)%5+1].b);
            tri[1]= new Triangle(line[i],line[i%5+1],lines[1]);
            tri[2]= new Triangle(lines[1],line[(i+1)%5+1],lines[2]);
            tri[3]=new Triangle(lines[2],line[(i+2)%5+1],line[(i+3)%5+1]);
            temp = tri[1].area()+tri[2].area()+tri[3].area();
            if(Math.abs(temp-num)>0.005)
                return true;
        }
        return false;
    }
    double perimeter(){
        return line[1].dis()+line[2].dis()+line[3].dis()+line[4].dis()+line[5].dis();
    }
    void partition(Line line1){
        Quadrilateral qua = new Quadrilateral();
        System.out.printf("2 ");
        double s = area(),s2=0;
        boolean f= false;
        Triangle tri = new Triangle();
        A:for(int i= 1;i <=5;i++){
            if((line1.judgeIntersection(line[i])&&line1.judgeIntersection(line[i%5+1])&&!line1.judgeIntersection(line[(i+1)%5+1])&&
                    line1.judgeIntersection(line[(i+2)%5+1])&&line1.judgeIntersection(line[(i+3)%5+1])&&
                    (line1.sameIntersection(line[i],line[i%5+1])&&line1.sameIntersection(line[(i+3)%5+1],line[(i+2)%5+1])))||
                    (line1.judgeIntersection(line[i])&&line1.judgeIntersection(line[i%5+1])&&!line1.judgeIntersection(line[(i+1)%5+1])
                            &&!line1.judgeIntersection(line[(i+2)%5+1]) &&line1.judgeIntersection(line[(i+3)%5+1])
                            &&(line1.sameIntersection(line[i],line[i%5+1])))||
                    (line1.judgeIntersection(line[i])&&!line1.judgeIntersection(line[i%5+1])&&!line1.judgeIntersection(line[(i+1)%5+1])
                            &&line1.judgeIntersection(line[(i+2)%5+1]) &&line1.judgeIntersection(line[(i+3)%5+1])
                            &&(line1.sameIntersection(line[(i+3)%5+1],line[(i+2)%5+1])))||
                    (line1.judgeIntersection(line[i])&&!line1.judgeIntersection(line[i%5+1])&&!line1.judgeIntersection(line[(i+1)%5+1])&&!line1.judgeIntersection(line[(i+2)%5+1])&&line1.judgeIntersection(line[(i+3)%5+1]))){
                tri = new Triangle(line[i].a,line1.intersection(line[i]),line1.intersection(line[(i+3)%5+1]));
                s2 = tri.area();
                f = true;
                break A;
            }
        }

       
           B:for(int i=1;i<=5;i++){
               if((!line1.judgeIntersection(line[i])&&line1.judgeIntersection(line[i%5+1])&&!line1.judgeIntersection(line[(i+1)%5+1])&&//1
                       !line1.judgeIntersection(line[(i+2)%5+1])&&line1.judgeIntersection(line[(i+3)%5+1]))||
                       (!line1.judgeIntersection(line[i])&&line1.judgeIntersection(line[i%5+1])&&line1.judgeIntersection(line[(i+1)%5+1])&&//5
                               !line1.judgeIntersection(line[(i+2)%5+1])&&line1.judgeIntersection(line[(i+3)%5+1])&&
                               line1.sameIntersection(line[(i+1)%5+1],line[i%5+1]))){
                   qua = new Quadrilateral(line[i].a,line[i].b,line1.intersection(line[i%5+1]),line1.intersection(line[(i+3)%5+1]));
                   s2 = qua.area();
                   break B;
               }
           }


        System.out.printf(printDouble(Math.min(s2,s-s2))+" "+printDouble(Math.max(s2,s-s2)));
    }
    public static double printDouble(double num) {
        String str = String.format("%.3f",num);
        num = Double.parseDouble(str);
        return num;
    }
}




class Quadrilateral {
    Line []line = new Line[5];
    public Quadrilateral(){}
    public Quadrilateral(Point []points){
        for(int i=1;i<=4;i++){
            line[i]=new Line(points[i],points[i%4+1]);
        }
    }
    public Quadrilateral(Point point1,Point point2,Point point3,Point point4){
        line[1] = new Line(point1,point2);
        line[2]= new Line(point2,point3);
        line[3] = new Line(point3,point4);
        line[4]= new Line(point4,point1);
    }
    boolean quadrilateralOrNot(){//非法三角形之大小大类型
        return  line[1].judgeIntersection(line[3])|| line[2].judgeIntersection(line[4])  || line[1].dotLineJudgment(line[3].a) || line[1].dotLineJudgment(line[3].b) || line[3].dotLineJudgment(line[1].a) || line[3].dotLineJudgment(line[1].b);
    }
    boolean parallel(){//判断平行四边形
        return line[1].slope() == line[3].slope() && line[2].slope() == line[4].slope();
    }
    boolean judgeDiamond(){//判断是否菱形
        return parallel()&&Math.abs(line[1].dis()-line[2].dis())<0.05;
    }
    boolean judgeRectangle(){//判断矩形
        return line[1].vertical(line[2])&&line[1].judgeParallelism(line[3])&&line[2].judgeParallelism(line[4]);
    }
    boolean fourPointsCollinear(){//判断不能组成三角形或者四边形
     //   System.out.printf(line[1].slope()+" "+line[2].slope()+" "+line[3].slope()+" "+line[4].slope()+"\n");
        return line[1].slope()==line[2].slope()&&line[2].slope()==line[3].slope()&&line[3].slope()==line[4].slope();
    }

    double perimeter(){//周长
        return line[1].dis()+line[2].dis()+line[3].dis()+line[4].dis();
    }
    Triangle[] division(){//划分三角形
        Line a = new Line(),b = new Line();
        Triangle [] tri = new Triangle[5];
        for(int i=1;i<=4;i++)
            tri[i]= new Triangle();
        a.a=line[1].a;a.b=line[3].a;
        b.a=line[1].b;b.b=line[3].b;
        tri[1].line[1]=line[1];
        tri[1].line[2]=line[2];
        tri[1].line[3]=a;

        tri[2].line[1]=line[3];
        tri[2].line[2]=line[4];
        tri[2].line[3]=a;

        tri[3].line[1]=line[1];
        tri[3].line[2]=line[4];
        tri[3].line[3]=b;

        tri[4].line[1]=line[3];
        tri[4].line[2]=line[2];
        tri[4].line[3]=b;
        return tri;
    }

    double area(){//面积
        Triangle [] tri = division();
        return Math.min(tri[1].area()+tri[2].area(),tri[3].area()+tri[4].area());
    }
    boolean bump(){//判断凹凸
        Triangle [] tri = division();

        return tri[1].area() + tri[2].area() == tri[3].area() + tri[4].area();
    }
    int focalPoints(Line line2) {//求线与其焦点数量
        int num=0;
        boolean []flag={false,false,false,false,false};
        for(int i=1;i<=4;i++) {
            if (line2.judgeIntersection(line[i]) ) {
                num++;
                flag[i] = true;
            }
        }
        for(int i=1;i<=4;i++){
            if(flag[i]&&line2.sameIntersection(line[i],line[i%4+1]))
                num--;
        }
        return num;
    }//4:-1,-1 1,1 0,0 2,0 3,0 0,5
    //4:-1,-1 1,1 0,0 5,0 5,5 0,5
    Triangle generateTriangle(){
        Triangle tri =new Triangle();
        if(line[1].slope()==line[2].slope())
            tri=new Triangle(line[3],line[4],line[1].a,line[2].b);
        else if(line[3].slope()==line[2].slope())
            tri=new Triangle(line[4],line[1],line[2].a,line[3].b);
        else if(line[3].slope()==line[4].slope())
            tri=new Triangle(line[1],line[2],line[3].a,line[4].b);
        else if(line[1].slope()==line[4].slope())
            tri=new Triangle(line[2],line[3],line[4].a,line[1].b);

        return tri;
    }
    Triangle returnTriangle(){
        Triangle tri = new Triangle();
        if(line[1].judgeParallelism(line[2])){
            tri = new Triangle(line[3],line[4],line[1].a,line[2].b);
        }
        else if(line[2].judgeParallelism(line[3])){
            tri = new Triangle(line[4],line[1],line[2].a,line[3].b);
        }
        else if(line[3].judgeParallelism(line[4])){
            tri = new Triangle(line[1],line[2],line[3].a,line[4].b);
        }
        else if(line[4].judgeParallelism(line[1])){
            tri = new Triangle(line[2],line[3],line[4].a,line[1].b);
        }
        return  tri;

    }
    int parallelNum(){
        int num = 0;
        for(int i=1;i<=4;i++)
            if(line[i].judgeParallelism(line[i%4+1])){
                num++;
            }
        return num;
    }
    void pointRelation(Point point){
        Triangle a=new Triangle(),b= new Triangle(),c= new Triangle(),d= new Triangle();
        b= new Triangle(point,line[3].a,line[3].b);c= new Triangle(point,line[2].a,line[2].b);d= new Triangle(point,line[1].a,line[1].b);
        a = new Triangle(point,line[4].a,line[4].b);
        if(d.area()==0||b.area()==0||c.area()==0||a.area()==0)
            System.out.println("on the quadrilateral");
        else if(Math.abs(area()-a.area()-b.area()-c.area()-d.area())<0.0005)
            System.out.printf("in the quadrilateral");
        else
            System.out.println("outof the quadrilateral");
    }
//    Quadrilateral[] division(Quadrilateral q,Line line2){
//        return q;
//    }
    boolean illegalShape(){
        for (int i=1;i<=4;i++)
            if(line[i].slope()==line[i%4+1].slope()){
              //  System.out.printf(i+" "+(boolean)(line[i].a.x>line[i].b.x&&line[i%4+1].b.x>line[i%4+1].a.x)+" "+(boolean)(line[i].a.x<line[i].b.x&&line[i%4+1].b.x<line[i%4+1].a.x)+" "+(boolean)(line[i].a.y>line[i].b.y&&line[i%4+1].b.y>line[i%4+1].a.y)+" "+(boolean)(line[i].a.y<line[i].b.y&&line[i%4+1].b.y<line[i%4+1].a.y)+"\n");
                if((line[i].a.x>line[i].b.x&&line[i%4+1].b.x>line[i%4+1].a.x)||
                        (line[i].a.x<line[i].b.x&&line[i%4+1].b.x<line[i%4+1].a.x)||
                        (line[i].a.y>line[i].b.y&&line[i%4+1].b.y>line[i%4+1].a.y)||
                        (line[i].a.y<line[i].b.y&&line[i%4+1].b.y<line[i%4+1].a.y))
                    return true;
            }
        return false;
    }
    boolean lineEdgeIntersection(Line line2){//线和线重叠
    //    System.out.printf("%f %f %f %f\n",line[1].slope(),line[2].slope(),line[3].slope(),line[4].slope());
        return line2.overlap(line[1])  || line2.overlap(line[2]) ||
                line2.overlap(line[3]) || line2.overlap(line[4]);
    }
    void partition(Line line1){
        int num = 0;
        Quadrilateral qua = new Quadrilateral();
        System.out.printf("2 ");
        double s = area(),s2=0;
        Triangle tri = new Triangle();
        if((line1.judgeIntersection(line[1])&&line1.judgeIntersection(line[2])&&line1.judgeIntersection(line[3])&&
                line1.judgeIntersection(line[4])&&(line1.sameIntersection(line[1],line[2])&&line1.sameIntersection(line[3],line[4])))||
                (line1.judgeIntersection(line[1])&&line1.judgeIntersection(line[2])&&!line1.judgeIntersection(line[3])
                        &&line1.judgeIntersection(line[4]) &&(line1.sameIntersection(line[1],line[2])))||
                (line1.judgeIntersection(line[1])&&!line1.judgeIntersection(line[2])&&line1.judgeIntersection(line[3])
                        &&line1.judgeIntersection(line[4]) &&(line1.sameIntersection(line[3],line[4])))||
                (line1.judgeIntersection(line[1])&&!line1.judgeIntersection(line[2])&&!line1.judgeIntersection(line[3])&&line1.judgeIntersection(line[4]))){
            tri = new Triangle(line[1].a,line1.intersection(line[1]),line1.intersection(line[4]));
            s2 = tri.area();
        }
        else if((line1.judgeIntersection(line[1])&&line1.judgeIntersection(line[2])&&line1.judgeIntersection(line[3])&&
                line1.judgeIntersection(line[4])&&(line1.sameIntersection(line[2],line[3])&&line1.sameIntersection(line[1],line[4])))||
                (line1.judgeIntersection(line[1])&&line1.judgeIntersection(line[2])&&line1.judgeIntersection(line[3])
                        &&!line1.judgeIntersection(line[4]) &&(line1.sameIntersection(line[3],line[2])))||
                (line1.judgeIntersection(line[1])&&line1.judgeIntersection(line[2])&&!line1.judgeIntersection(line[3])
                        &&line1.judgeIntersection(line[4]) &&(line1.sameIntersection(line[1],line[4])))||
                (line1.judgeIntersection(line[1])&&line1.judgeIntersection(line[2])&&!line1.judgeIntersection(line[3])&&!line1.judgeIntersection(line[4]))){
            tri = new Triangle(line[2].a,line1.intersection(line[2]),line1.intersection(line[1]));
            s2 = tri.area();
        }
        else if((!line1.judgeIntersection(line[1])&&line1.judgeIntersection(line[2])&&line1.judgeIntersection(line[3])
                        &&line1.judgeIntersection(line[4]) &&(line1.sameIntersection(line[3],line[4])))||
                (line1.judgeIntersection(line[1])&&line1.judgeIntersection(line[2])&&line1.judgeIntersection(line[3])
                        &&!line1.judgeIntersection(line[4]) &&(line1.sameIntersection(line[1],line[2])))||
                (!line1.judgeIntersection(line[1])&&line1.judgeIntersection(line[2])&&line1.judgeIntersection(line[3])&&!line1.judgeIntersection(line[4]))){
            tri = new Triangle(line[3].a,line1.intersection(line[3]),line1.intersection(line[2]));
            s2 = tri.area();
        }
        else if((line1.judgeIntersection(line[1])&&!line1.judgeIntersection(line[2])&&line1.judgeIntersection(line[3])
                        &&line1.judgeIntersection(line[4]) &&(line1.sameIntersection(line[1],line[4])))||
                (!line1.judgeIntersection(line[1])&&line1.judgeIntersection(line[2])&&line1.judgeIntersection(line[3])
                        &&line1.judgeIntersection(line[4]) &&(line1.sameIntersection(line[2],line[3])))||
                (!line1.judgeIntersection(line[1])&&!line1.judgeIntersection(line[2])&&line1.judgeIntersection(line[3])&&line1.judgeIntersection(line[4]))){
            tri = new Triangle(line[4].a,line1.intersection(line[4]),line1.intersection(line[3]));
            s2 = tri.area();
        }
        else if(line1.judgeIntersection(line[1])&&!line1.judgeIntersection(line[2])&&line1.judgeIntersection(line[3])&&
                !line1.judgeIntersection(line[4])){
            qua = new Quadrilateral(line[1].a,line1.intersection(line[1]),line1.intersection(line[3]),line[3].b);
            s2 = qua.area();
        }
        else if(!line1.judgeIntersection(line[1])&&line1.judgeIntersection(line[2])&&!line1.judgeIntersection(line[3])&&
                line1.judgeIntersection(line[4])){
            qua = new Quadrilateral(line[2].a,line1.intersection(line[2]),line1.intersection(line[4]),line[4].b);
            s2 = qua.area();
        }
        System.out.printf(printDouble(Math.min(s2,s-s2))+" "+printDouble(Math.max(s2,s-s2)));
    }
    public static double printDouble(double num) {
        String str = String.format("%.3f",num);
        num = Double.parseDouble(str);
        return num;
    }
}





class Triangle {
    Line []line = new Line[8];
    void printTri(){
        System.out.printf("line[1] = %f %f %f %f \nline[2] = %f %f %f %f \nline[3] = %f %f %f %f\n",
                line[1].a.x,line[1].a.y,line[1].b.x,line[1].b.y,
                line[2].a.x,line[2].a.y,line[2].b.x,line[2].b.y,
                line[3].a.x,line[3].a.y,line[3].b.x,line[3].b.y);
    }
    double area() {//三角形面积
        double p= (Math.sqrt((line[1].a.x-line[1].b.x)*(line[1].a.x-line[1].b.x)+(line[1].a.y-line[1].b.y)*(line[1].a.y-line[1].b.y))+Math.sqrt((line[2].a.x-line[2].b.x)*(line[2].a.x-line[2].b.x)+(line[2].a.y-line[2].b.y)*(line[2].a.y-line[2].b.y))+ Math.sqrt((line[3].a.x-line[3].b.x)*(line[3].a.x-line[3].b.x)+(line[3].a.y-line[3].b.y)*(line[3].a.y-line[3].b.y)) )/2;
        return Math.sqrt(p*(p- Math.sqrt((line[1].a.x-line[1].b.x)*(line[1].a.x-line[1].b.x)+(line[1].a.y-line[1].b.y)*(line[1].a.y-line[1].b.y)) )*(p - Math.sqrt((line[2].a.x-line[2].b.x)*(line[2].a.x-line[2].b.x)+(line[2].a.y-line[2].b.y)*(line[2].a.y-line[2].b.y)) )*(p- Math.sqrt((line[3].a.x-line[3].b.x)*(line[3].a.x-line[3].b.x)+(line[3].a.y-line[3].b.y)*(line[3].a.y-line[3].b.y)) ));
    }
    public Triangle(){

    }
    public Triangle(Line line1,Line line2,Point point1,Point point2){
        line[1] = new Line(line1);
        line[2] = new Line(line2);
        line[3] = new Line(point1,point2);
    }
    public Triangle(Line line1,Line line2,Line line3){
        line[1] = new Line(line1);
        line[2] = new Line(line2);
        line[3] = new Line(line3);
    }
    public Triangle(Point point1,Point point2,Point point3) {
        for(int i=1;i<=3;i++){
            line[i] = new Line();
            line[i].a= new Point();
            line[i].b = new Point();
        }
        line[1].a.x=point1.x;line[1].a.y=point1.y;
        line[1].b.x=point2.x;line[1].b.y=point2.y;

        line[2].a.x=point2.x;line[2].a.y=point2.y;
        line[2].b.x=point3.x;line[2].b.y=point3.y;

        line[3].a.x=point3.x;line[3].a.y=point3.y;
        line[3].b.x=point1.x;line[3].b.y=point1.y;
    }
    boolean legal(){
        for(int i=1;i<=3;i++) {
            if ((line[i].a.x-line[i].b.x )*(line[i%3+1].a.y-line[i%3+1].b.y)== (line[i%3+1].a.x-line[i%3+1].b.x )*(line[i].a.y-line[i].b.y))
                return false;
        }
        return true;
    }
    void pointRelation(Point point){//5:1,4 0,0 5,5 0,0 5,0
        Triangle b= new Triangle(),c= new Triangle(),d= new Triangle();
  //      System.out.printf("%f %f %f %f %f %f\n",line[1].a.x,line[1].a.y,line[2].a.x,line[2].a.y,line[3].a.x,line[3].a.y);
        b= new Triangle(point,line[3].a,line[3].b);c= new Triangle(point,line[2].a,line[2].b);d= new Triangle(point,line[1].a,line[1].b);
        if(d.area()==0||b.area()==0||c.area()==0)
            System.out.println("on the triangle");
        else if(Math.abs(area()-b.area()-c.area()-d.area())<0.0005)
            System.out.printf("in the triangle");
        else
            System.out.println("outof the triangle");
    }
    void division(Line line1){
        int num = 0;

        System.out.printf("2 ");
        double s = area(),s2=0;
        Triangle tri = new Triangle();
        if((line1.judgeIntersection(line[1])&&line1.judgeIntersection(line[2])&&line1.judgeIntersection(line[3]
        )&&(line1.sameIntersection(line[1],line[2])||line1.sameIntersection(line[2],line[3])))||
                (line1.judgeIntersection(line[1])&&!line1.judgeIntersection(line[2])&&line1.judgeIntersection(line[3]))){
            tri = new Triangle(line[1].a,line1.intersection(line[1]),line1.intersection(line[3]));
        }
        if((line1.judgeIntersection(line[1])&&line1.judgeIntersection(line[2])&&line1.judgeIntersection(line[3]
        )&&(line1.sameIntersection(line[1],line[3])))||
                (line1.judgeIntersection(line[1])&&line1.judgeIntersection(line[2])&&!line1.judgeIntersection(line[3]))){
            tri = new Triangle(line[2].a,line1.intersection(line[2]),line1.intersection(line[1]));
        }
        if((line1.judgeIntersection(line[1])&&line1.judgeIntersection(line[2])&&line1.judgeIntersection(line[3]
        ))|| (!line1.judgeIntersection(line[1])&&line1.judgeIntersection(line[2])&&line1.judgeIntersection(line[3]))){
            tri = new Triangle(line[1].a,line1.intersection(line[1]),line1.intersection(line[3]));
        }s2 = tri.area();
        System.out.printf(printDouble(Math.min(s2,s-s2))+" "+printDouble(Math.max(s2,s-s2)));

    }
    public  static  double areaCalculation(Point a,Point b,Point c,Line d,double s) {//计算面积case4
        Line aa = new Line(a,b);
        Line bb = new Line(a,c);
        Point x1 = aa.intersection(d);
        Point x2 = bb.intersection(d);
        double q = (a.DistanceCalculation(b)*a.DistanceCalculation(c));
        double p = (a.DistanceCalculation(x1)*a.DistanceCalculation(x2));
//        System.out.printf(p+" "+q+" ");
//        System.out.printf(s+" ");
        return (s*p)/q;
    }
    public static double printDouble(double num) {
        String str = String.format("%.3f",num);
        num = Double.parseDouble(str);
        return num;
    }

}





class Point {//点的类
    double x = 0 , y = 0 ;
    public Point(){}
    public Point(Point point){
        x= point.x;
        y= point.y;
    }
    double DistanceCalculation(Point b) {
        return Math.sqrt((this.x-b.x)*(this.x-b.x)+(this.y-b.y)*(this.y-b.y));
    }//返回两点距离
}


class PointTaking {
    String ch;
    int num2=0;

    public static double printDouble(double num) {
        String str = String.format("%.3f",num);
        num = Double.parseDouble(str);
        return num;
    }
    public static double vectorComputation(Point a,Point b,Point c){//计算点线是否相交
        double x1 = a.x-c.x, y1=a.y-c.y,x2=b.x-c.x,y2=b.y-c.y;
        return  x1*y2-x2*y1;
    }//&ensp;&ensp;

    boolean repetitionPointJudgment(Point a[],int x,int y){//相同点
        for(int i=x;i<=y;i++)//如果一样则返回
            for(int j = i+1;j<=y;j++)
                if(a[i].x==a[j].x&&a[i].y==a[j].y)
                    return true;
        return false;
    }

    public  static  double areaCalculation(Point a,Point b,Point c,Line d,double s) {//计算面积case4
        Line aa = new Line(a,b);
        Line bb = new Line(a,c);
        Point x1 = aa.intersection(d);
        Point x2 = bb.intersection(d);
        double q = (a.DistanceCalculation(b)*a.DistanceCalculation(c));
        double p = (a.DistanceCalculation(x1)*a.DistanceCalculation(x2));
//        System.out.printf(p+" "+q+" ");
//        Systemystem.out.printf(s+" ");
        return (s*p)/q;
    }
    Point [] duplicate(Point[] points){
        Point []point = new Point[10];Point []point2 = new Point[10];
        Triangle tri = new Triangle();
        boolean []flag = new boolean[]{false, false, false, false, false, false, false, false};
        boolean []flag2 = new boolean[]{false, false, false, false, false, false, false, false};
        num2 = 5;
        for(int i=3;i<=7;i++) {
            for(int j=i+1;j<=7;j++)
                if(!flag[j]&&points[i].x==points[j].x&&points[i].y==points[j].y){
                  //  System.out.printf(j+"\n");
                    flag[j]=true;
                    num2 -- ;
                }
        }
        int pos=1;
        for(int i=3;i<=7;i++)
            if(!flag[i]){
                point[pos++]= new Point(points[i]);
            }
        pos--;
        for(int i=1;i<=pos;i++){
            Line line1 = new Line(point[i],point[i%pos+1]);
            Line line2 = new Line(point[i%pos+1],point[(i+1)%pos+1]);
            if(line1.judgeParallelism(line2)) {
                if(!flag2[i%pos+1])
                {
                //    System.out.printf((i%pos+1)+"\n");
                    flag2[i%pos+1]=true;
                    num2--;
                }
            }
        }

        int pos2=1;
        for(int i=1;i<=pos;i++)
            if(!flag2[i]) {
                point2[pos2++] = new Point(point[i]);
                }
        return point2;

    }


    double Solve() {
        Point[] pointSet = new Point[15];//储存点
        int pos = 0;
        //  String[]
        String[] splitSet1 = this.ch.split(":");//将字符串以冒号分割,剥离选项与坐标
        if (splitSet1.length != 2)
            return -1;
        if (!splitSet1[0].matches("[1-5]"))//判断选项是否合规
            return -1;
        int x = Integer.parseInt(splitSet1[0]);//剥离出第选项
        int[] digitalDeposit = {0, 5, 5, 7 ,6, 5};//定义选项要的点数
        for (int i = 1; i <= 10; i++)
            pointSet[i] = new Point();//new多个点

        String[] splitSet2 = splitSet1[1].split(" ");
        for (String i : splitSet2) {//对分割的字符串遍历
            int count=2;
            String[] splitSet3 = i.split(",");
            for (String j : splitSet3) {
                if (!j.matches("^[+-]?(([1-9]\\d*\\.\\d+)|(0\\.\\d+)|([1-9]\\d*)|0)$"))//正则表达式判断是否合法
                    return -1;//返回输入错误
                int pos2 = pos / 2 + 1;
                //      System.out.printf(pos2+"");
                if ((pos & 1) == 0)//按位读入坐标
                    pointSet[pos2].x = Double.parseDouble(j);
                else if ((pos & 1) == 1)
                    pointSet[pos2].y = Double.parseDouble(j);
                pos++;
                count--;
            }
            if(count!=0)
                return -1;
        }
        if (splitSet2.length != digitalDeposit[x])
            return -2;//返回错误点数量
        return juSample(x,pointSet);
    }
    double juSample(int x, Point[] points){
        if(x==1)
            return sample1(points);
        else if(x==2)
            return sample2(points);
        else if(x==3)
            return sample3(points);
        return -1;
    }

    double sample1(Point[] points){
        Pentagon pentagon  = new Pentagon(points[1],points[2],points[3],points[4],points[5]);
        if(!pentagon.legal()||repetitionPointJudgment(points,1,5))
            return 2;
        return 1;
    }
    double sample2(Point[] points){
        if(sample1(points)==2)
            return -4;
        Pentagon pentagon  = new Pentagon(points[1],points[2],points[3],points[4],points[5]);
        if(pentagon.bump())
            return 2;
       // System.out.printf(q.bump()+"\n");
        System.out.printf("true "+printDouble(pentagon.perimeter())+" "+printDouble(pentagon.area()));

        return 5;
    }
    double sample3(Point[] points){
        if(points[1].x==points[2].x&&points[1].y == points[2].y)
            return 4;
        Line line = new Line(points[1],points[2]);
        Triangle tri = new Triangle();
        Quadrilateral qua = new Quadrilateral();
        Point []point = duplicate(points);
        if(num2==3) {
            tri = new Triangle(point[1],point[2],point[3]);
            tri.division(line);
        }
        else if(num2==4){
            qua = new Quadrilateral(point);
            qua.partition(line);
        }
        else{
            Pentagon pent = new Pentagon(points[3],points[4],points[5],points[6],points[7]);
            pent.partition(line);
        }

        return 5;
    }


}



 

期中考试

7-1 点与线(类设计)

    设计一个类表示平面直角坐标系上的点Point,私有属性分别为横坐标x与纵坐标y,数据类型均为实型数,除构造方法以及属性的getter与setter方法外,定义一个用于显示信息的方法display(),用来输出该坐标点的坐标信息,格式如下:(x,y),数值保留两位小数。为简化题目,其中,坐标点的取值范围设定为(0,200]。若输入有误,系统则直接输出Wrong Format

    设计一个类表示平面直角坐标系上的线Line,私有属性除了标识线段两端的点point1、point2外,还有一个字符串类型的color,用于表示该线段的颜色,同样,除构造方法以及属性的getter与setter方法外,定义一个用于计算该线段长度的方法getDistance(),还有一个用于显示信息的方法display(),用来输出线段的相关信息,输出格式如下:
       The line's color is:颜色值
       The line's begin point's Coordinate is:
       (x1,y1)
       The line's end point's Coordinate is:
       (x2,y2)
       The line's length is:长度值
  其中,所有数值均保留两位小数,建议可用String.format("%.2f", data)方法。


** 题目要求:在主方法中定义一条线段对象,从键盘输入该线段的起点坐标与终点坐标以及颜色,然后调用该线段的display()方法进行输出。**

以下情况为无效作业
    无法运行
    设计不符合所给类图要求
    未通过任何测试点测试
    判定为抄袭

输入格式:

分别输入线段的起点横坐标、纵坐标、终点的横坐标、纵坐标以及颜色,中间可用一个或多个空格、tab或者回车分隔。

输出格式:

The line's color is:颜色值
The line's begin point's Coordinate is:
(x1,y1)
The line's end point's Coordinate is:
(x2,y2)
The line's length is:长度值

代码如下


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        double []num =new double[5];
        for(int i=1;i<=4;i++){
            num[i] = input.nextDouble();
            if(num[i]>200||num[i]<=0){
                System.out.printf("Wrong Format\n");
                return;
            }
        }
        String  color = input.next();
        Point point1 = new Point(num[1],num[2]),point2 = new Point(num[3],num[4]);
        Line line = new Line(point1,point2,color);
        line.display();

    }


}
class Point {
    private double x,y;
    public Point(){

    }
    public Point(double x, double y){
        setX(x);setY(y);
    }
    void setX(double x){
        this.x =x;
    }
    void setY(double y){
        this.y = y;
    }
    double getX(){
        return this.x;
    }
    double getY(){
        return this.y;
    }
    void display(){
        double numx,numy;
        String str1 = String.format("%.3f",getX()),str2 = String.format("%.3f",getY());
        numx = Double.parseDouble(str1);numy = Double.parseDouble(str2);

        System.out.printf("(%.2f,%.2f)",numx,numy);
    }
}
class Line {
    Point point1,point2;
    String color;
    public Line(){}
    public Line(Point point1, Point point2,String color){
        setColor(color);setPoint1(point1) ;setPoint2(point2);
    }
    Point getPoint1(){return point1;}
    Point getPoint2(){return point2;}
    String getColor(){return color;}
    void setPoint1(Point point1){
        this.point1 = new Point(point1.getX(),point1.getY());
    }
    void setPoint2(Point point2){
        this.point2 = new Point(point2.getX(),point2.getY());
    }
    void  setColor(String color){
        this.color = color;
    }
    double getDistance(){
        return Math.sqrt((point1.getX()- point2.getX())*(point1.getX()- point2.getX())+(point1.getY()- point2.getY())*(point1.getY()- point2.getY()));
    }
    void display(){
        System.out.printf("The line's color is:" +getColor()+
                "\nThe line's begin point's Coordinate is:\n" );
        point1.display();
        System.out.printf("\n"+"The line's end point's Coordinate is:\n" );
        point2.display() ;
        System.out.printf("\n"+"The line's length is:" );
        double num;
        String str1 = String.format("%.3f",getDistance());
        num= Double.parseDouble(str1);
        System.out.printf("%.2f",num);
    }



}

7-2 点线面问题重构(继承与多态)

在“点与线(类设计)”题目基础上,对题目的类设计进行重构,以实现继承与多态的技术性需求。

对题目中的点Point类和线Line类进行进一步抽象,定义一个两个类的共同父类Element(抽象类),将display()方法在该方法中进行声明(抽象方法),将Point类和Line类作为该类的子类。
再定义一个Element类的子类面Plane,该类只有一个私有属性颜色color,除了构造方法和属性的getter、setter方法外,display()方法用于输出面的颜色,输出格式如下:The Plane's color is:颜色
在主方法内,定义两个Point(线段的起点和终点)对象、一个Line对象和一个Plane对象,依次从键盘输入两个Point对象的起点、终点坐标和颜色值(Line对象和Plane对象颜色相同),然后定义一个Element类的引用,分别使用该引用调用以上四个对象的display()方法,从而实现多态特性。示例代码如下:
          element = p1;//起点Point
          element.display();
          
          element = p2;//终点Point
          element.display();
          
          element = line;//线段
          element.display();
          
          element = plane;//面
          element.display();
其中,所有数值均保留两位小数,建议可用String.format("%.2f", data)方法。

以下情况为无效作业
    无法运行
    设计不符合所给类图要求
    未通过任何测试点测试
    判定为抄袭

输入格式:

分别输入线段的起点横坐标、纵坐标、终点的横坐标、纵坐标以及颜色,中间可用一个或多个空格、tab或者回车分隔。

输出格式:

(x1,y1)
(x2,y2)
The line's color is:颜色值
The line's begin point's Coordinate is:
(x1,y1)
The line's end point's Coordinate is:
(x2,y2)
The line's length is:长度值
The Plane's color is:颜色值

代码如下



import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        double []num =new double[5];
        for(int i=1;i<=4;i++){
            num[i] = input.nextDouble();
            if(num[i]>200||num[i]<=0){
                System.out.printf("Wrong Format\n");
                return;
            }
        }
        String  color = input.next();
        Element point1 = new  Point(num[1],num[2]),point2 = new Point(num[3],num[4]);
        Element line = new Line(new Point(num[1],num[2]),new Point(num[3],num[4]),color);
        Element plane = new Plane(color);
        point1.display();
        point2.display();
        line.display();
        plane.display();

    }


}
class Point extends Element{
    private double x,y;

    public Point(){

    }

    public Point(double x, double y){
        setX(x);setY(y);
    }
    void setX(double x){
        this.x =x;
    }
    void setY(double y){
        this.y = y;
    }
    double getX(){
        return this.x;
    }
    double getY(){
        return this.y;
    }
    void display(){
        double numx,numy;
        String str1 = String.format("%.3f",getX()),str2 = String.format("%.3f",getY());
        numx = Double.parseDouble(str1);numy = Double.parseDouble(str2);

        System.out.printf("(%.2f,%.2f)\n",numx,numy);
    }
}
class Line extends Element{
    Point point1,point2;
    String color;
    public Line(){}


    public Line(Point point1, Point point2,String color){
        setColor(color);setPoint1(point1) ;setPoint2(point2);
    }
    Point getPoint1(){return point1;}
    Point getPoint2(){return point2;}
    String getColor(){return color;}
    void setPoint1(Point point1){
        this.point1 = new Point(point1.getX(),point1.getY());
    }
    void setPoint2(Point point2){
        this.point2 = new Point(point2.getX(),point2.getY());
    }
    void  setColor(String color){
        this.color = color;
    }
    double getDistance(){
        return Math.sqrt((point1.getX()- point2.getX())*(point1.getX()- point2.getX())+(point1.getY()- point2.getY())*(point1.getY()- point2.getY()));
    }
    void display(){
        System.out.printf("The line's color is:" +getColor()+
                "\nThe line's begin point's Coordinate is:\n" );
        point1.display();
        System.out.printf("The line's end point's Coordinate is:\n" );
        point2.display() ;
        System.out.printf("The line's length is:" );
        double num;
        String str1 = String.format("%.3f",getDistance());
        num= Double.parseDouble(str1);
        System.out.printf("%.2f\n",num);
    }



}
abstract class  Element{


    abstract void display();
}
class Plane extends Element{
    private String color;
    public Plane(){}
    public Plane(String color){
        setColor(color);
    }
    void display(){
        System.out.printf("The Plane's color is:"+getColor()+"\n");
    };
    void setColor(String color){this.color = color;}
    String getColor(){return color;}

}

7-3 点线面问题再重构(容器类)

在“点与线(继承与多态)”题目基础上,对题目的类设计进行重构,增加容器类保存点、线、面对象,并对该容器进行相应增、删、遍历操作。

在原有类设计的基础上,增加一个GeometryObject容器类,其属性为ArrayList<Element>类型的对象(若不了解泛型,可以不使用<Element>)
增加该类的add()方法及remove(int index)方法,其功能分别为向容器中增加对象及删除第index - 1(ArrayList中index>=0)个对象
在主方法中,用户循环输入要进行的操作(choice∈[0,4]),其含义如下:
    1:向容器中增加Point对象
    2:向容器中增加Line对象
    3:向容器中增加Plane对象
    4:删除容器中第index - 1个数据,若index数据非法,则无视此操作
    0:输入结束
示例代码如下:
       choice = input.nextInt();
        while(choice != 0) {
            switch(choice) {
            case 1://insert Point object into list 
              ...
                break;
            case 2://insert Line object into list
                ...
                break;
            case 3://insert Plane object into list
                ...
                break;
            case 4://delete index - 1 object from list
                int index = input.nextInt();
                ...
            }
            choice = input.nextInt();
        }
输入结束后,按容器中的对象顺序分别调用每个对象的display()方法进行输出。


以下情况为无效作业
    无法运行
    设计不符合所给类图要求
    未通过任何测试点测试
    判定为抄袭

输入格式:

switch(choice) {
            case 1://insert Point object into list 
              输入“点”对象的x,y值
                break;
            case 2://insert Line object into list
                输入“线”对象两个端点的x,y值
                break;
            case 3://insert Plane object into list
                输入“面”对象的颜色值
                break;
            case 4://delete index - 1 object from list
                输入要删除的对象位置(从1开始)
                ...
            }

输出格式:

Point、Line、Plane的输出参考题目2
删除对象时,若输入的index超出合法范围,程序自动忽略该操作

代码如下



import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    static double []num =new double[15];
    static Scanner input = new Scanner(System.in);
    public static void main(String[] args) {
        int choice = input.nextInt();
        GeometryObject geometryObject = new GeometryObject();
        String color;
        while(choice != 0) {
            switch(choice) {
                case 1:
                    getNum(2);
                    Element point = new Point(num[1],num[2]);
                    geometryObject.add(point);
                    break;
                case 2://insert Line object into list
                    getNum(4);
                    color = input.next();
                    Element line = new Line(new Point(num[1],num[2]),new Point(num[3],num[4] ),color);
                    geometryObject.add(line);
                    break;
                case 3://insert Plane object into list

                    color = input.next();
                    Element plane = new Plane(color);
                    geometryObject.add(plane);
                    break;
                case 4://delete index - 1 object from list
                    int index = input.nextInt();
                    geometryObject.remove(index);
                    break;
            }

            //System.out.printf(choice+"\n");
            choice = input.nextInt();

        }
        geometryObject.display();
    }
    static void getNum(int x) {
        for (int i = 1; i <= x; i++) {
            num[i] = input.nextDouble();
        }
    }


}
class Point extends Element{
    private double x,y;

    public Point(){

    }

    public Point(double x, double y){
        setX(x);setY(y);
    }
    void setX(double x){
        this.x =x;
    }
    void setY(double y){
        this.y = y;
    }
    double getX(){
        return this.x;
    }
    double getY(){
        return this.y;
    }
    void display(){
        double numx,numy;
        String str1 = String.format("%.3f",getX()),str2 = String.format("%.3f",getY());
        numx = Double.parseDouble(str1);numy = Double.parseDouble(str2);

        System.out.printf("(%.2f,%.2f)\n",numx,numy);
    }
}
class Line extends Element{
    Point point1,point2;
    String color;
    public Line(){}


    public Line(Point point1, Point point2,String color){
        setColor(color);setPoint1(point1) ;setPoint2(point2);
    }
    Point getPoint1(){return point1;}
    Point getPoint2(){return point2;}
    String getColor(){return color;}
    void setPoint1(Point point1){
        this.point1 = new Point(point1.getX(),point1.getY());
    }
    void setPoint2(Point point2){
        this.point2 = new Point(point2.getX(),point2.getY());
    }
    void  setColor(String color){
        this.color = color;
    }
    double getDistance(){
        return Math.sqrt((point1.getX()- point2.getX())*(point1.getX()- point2.getX())+(point1.getY()- point2.getY())*(point1.getY()- point2.getY()));
    }
    void display(){
        System.out.printf("The line's color is:" +getColor()+
                "\nThe line's begin point's Coordinate is:\n" );
        point1.display();
        System.out.printf("The line's end point's Coordinate is:\n" );
        point2.display() ;
        System.out.printf("The line's length is:" );
        double num;
        String str1 = String.format("%.3f",getDistance());
        num= Double.parseDouble(str1);
        System.out.printf("%.2f\n",num);
    }



}
abstract class  Element{


    abstract void display();
}
class Plane extends Element{
    private String color;
    public Plane(){}
    public Plane(String color){
        setColor(color);
    }
    void display(){
        System.out.printf("The Plane's color is:"+getColor()+"\n");
    };
    void setColor(String color){this.color = color;}
    String getColor(){return color;}

}
class GeometryObject{
    ArrayList<Element> elements = new ArrayList<>();
    void add(Element element){
        elements.add(element);
    }
    void remove(int x){
        if(x>elements.size())
            return;
        elements.remove(x-1);
    }
    void display(){
        for (Element ele:elements){
            ele.display();
        }
    }
}
posted @ 2022-12-19 16:13  未名hu  阅读(56)  评论(0)    收藏  举报