Blog-2

前言

这六-九周的大作业,题量与难度都很大,知识点也涵盖的很多。
题目集4:点线形系列的计算,难度十分大。主要考了字符串的读取、正则表达式的运用、以及属性、方法与类的运用。
题目集5: 点线形系列5-凸五边形的计算,难度比前一个题目集又难许多。考察的知识点也更加全面,比如不仅考察了编程思想、设计代码的能力,还考察了我们对数学图形和图形所涵盖的特点以及知识的掌握。
题目集期中考试:点线面的运用,类设计、继承与多态、容器类的问题,但大多都是前几次大作业中有涉及到的。

设计与分析

题目集4-点线形系列4-凸四边形的计算

要点:此题考察的是将给出的字符串于所输入的空格来进行分割,期间还穿插着合法数的判断,之后根据逗号识别出相应的有关x,y轴的点位,从而分析出各个点的坐标、正则表达式的运用,以及类与选择。
我的想法:先将所给字符串分割出需要代入运算的数据部分,进行合法性的判断,如果数据合法,将会对字符串中":"之前的数据进行提取,然后判断运行的那一段代码,所代入的数据利用.split()进行分割,再利用Double.parseDouble()将所需运算的数据存入double型的x1,x2,x3,x4,y1,y2,y3,y4,其中字符串会根据首个字符来进行不同的分割以及转化存入相对应的x1,x2,x3,x4,y1,y2,y3,y4,x3,x4,y3,y4,然后进行数学计算,将计算出的结果进行判断,输出对应的结果。

部分代码类展示


class Points {
    private String s;
    private int choice;
    private String coord[];
    public double[] x=null;
    public double[] y=null;
    Points(String s,int choice){
        this.s=s;
        this.choice=choice;
    }
    public static int getChoice(String s) {
        int choice = s.charAt(0)-48;
        return choice;
    }
    
    public void choose() {
        coord=s.split(",| ");
        if(choice==1||choice==2||choice==3) {
            coordinate123();
        }
        else if(choice==4) {
            coordinate4();
        }
        else if(choice==5) {
            coordinate5();
        }
    }
    public void coordinate123() {
        x = new double[4];
        y = new double[4];
        for(int i=0;i<4;i++) {
            x[i]=Double.parseDouble(coord[2*i]);
            y[i]=Double.parseDouble(coord[2*i+1]);
        }
    }
    public void coordinate4() {
        x = new double[6];
        y = new double[6];
        for(int i=0;i<6;i++) {
            x[i]=Double.parseDouble(coord[2*i]);
            y[i]=Double.parseDouble(coord[2*i+1]);
        }
    }
    public void coordinate5() {
        x = new double[5];
        y = new double[5];
        for(int i=0;i<5;i++) {
            x[i]=Double.parseDouble(coord[2*i]);
            y[i]=Double.parseDouble(coord[2*i+1]);
        }
    }
    public double[] getX() {
        return x;
    }
    public double[] getY() {
        return y;
    }
}


class First {
    private double[] x = new double[4];
    private double[] y = new double[4];
    double[] line =new double[4];
    First(double[] x,double[] y) {
        this.x=x;
        this.y=y;
    }
    public void judgerepeat() {
        Judgerepeat c=new Judgerepeat(x,y);
        c.judgerepeat();
        quadrilateral();
        Line d=new Line(x,y);
        line=d.line();
        parallelogram();
    }
    public void quadrilateral() {
        if(((y[0]-y[1])*(x[0]-x[2])==(y[0]-y[2])*(x[0]-x[1]))||
           ((y[0]-y[1])*(x[0]-x[3])==(y[0]-y[3])*(x[0]-x[1]))||
           ((y[0]-y[2])*(x[0]-x[3])==(y[0]-y[3])*(x[0]-x[2]))||
           ((y[1]-y[2])*(x[1]-x[3])==(y[1]-y[3])*(x[1]-x[2])))System.out.print("false ");
        else {
            if(!Line.intersect(x[0],y[0],x[3],y[3],x[1],y[1],x[2],y[2])) {
                System.out.print("true ");
            }
            else System.out.print("false ");
        }
    }
    public void parallelogram() {
        if(line[0]==line[2]&&line[1]==line[3])System.out.print("true");
        else System.out.print("false");
    }
}

class Second {
    private double[] x = new double[4];
    private double[] y = new double[4];
    double[] line =new double[4];
    double[] diagonal=new double[2];
    private boolean judge1=false;
    private boolean judge2=false;
    private boolean judge3=false;
    Second(double[] x,double[] y) {
        this.x=x;
        this.y=y;
    }
    public void judgerepeat() {
        Judgerepeat c=new Judgerepeat(x,y);
        c.judgerepeat();
        quadrilateral();
        Line d=new Line(x,y);
        line=d.line();
        diagonal=d.diagonal();
        lozenge();
        rectangle();
        square();
    }
    public void quadrilateral() {
        if(((y[0]-y[1])*(x[0]-x[2])==(y[0]-y[2])*(x[0]-x[1]))||
           ((y[0]-y[1])*(x[0]-x[3])==(y[0]-y[3])*(x[0]-x[1]))||
           ((y[0]-y[2])*(x[0]-x[3])==(y[0]-y[3])*(x[0]-x[2]))||
           ((y[1]-y[2])*(x[1]-x[3])==(y[1]-y[3])*(x[1]-x[2]))) {
                System.out.print("not a quadrilateral");
                System.exit(0);
           }
        else {
            if(Line.intersect(x[0],y[0],x[3],y[3],x[1],y[1],x[2],y[2])) {
                System.out.print("not a quadrilateral");
                System.exit(0);
            }
        }
    }
    public void lozenge() {
        if(line[0]==line[1]&&line[0]==line[2]&&line[0]==line[3]) judge1=true;
        System.out.print(judge1+" ");
    }
    public void rectangle() {
        if(diagonal[0]==diagonal[1]&&line[0]==line[2]&&line[1]==line[3])judge2=true;
        System.out.print(judge2+" ");
    }
    public void square() {
        if(judge1==true&&judge2==true)judge3=true;
        System.out.print(judge3);
    }
}
class Third {
    private double[] x = new double[4];
    private double[] y = new double[4];
    private boolean judge1=false;//0,2
    private boolean judge2=false;//1,3
    Third(double[] x,double[] y) {
        this.x=x;
        this.y=y;
    }
    public void judgerepeat() {
        Judgerepeat c=new Judgerepeat(x,y);
        c.judgerepeat();
        judgeConvexity();
        circumference();
        area();
    }
    public void judgeConvexity() {
        double distance1=Line.distance(x[1],y[1],x[0],y[0],x[2],y[2]);
        double distance2=Line.distance(x[3],y[3],x[0],y[0],x[2],y[2]);
        double distance3=Line.distance(x[0],y[0],x[1],y[1],x[3],y[3]);
        double distance4=Line.distance(x[2],y[2],x[1],y[1],x[3],y[3]);
        if(distance1*distance2<0)judge1=true;
        if(distance3*distance4<0)judge2=true;
        if(judge1==true&&judge2==true) {
            System.out.print("true ");
        }
        else System.out.print("false ");
    }
    public void circumference() {
        double line1=Math.sqrt((x[0]-x[1])*(x[0]-x[1])+(y[0]-y[1])*(y[0]-y[1]));
        double line2=Math.sqrt((x[1]-x[2])*(x[1]-x[2])+(y[1]-y[2])*(y[1]-y[2]));
        double line3=Math.sqrt((x[2]-x[3])*(x[2]-x[3])+(y[2]-y[3])*(y[2]-y[3]));
        double line4=Math.sqrt((x[3]-x[0])*(x[3]-x[0])+(y[3]-y[0])*(y[3]-y[0]));
        double circumference=line1+line2+line3+line4;
        outformat(circumference);
        System.out.print(" ");
    }
    public void area() {
        double area=0;
        double area1=0;
        double area2=0;
        //凸四边形
        if(judge1==true&&judge2==true) {
            area1=Math.abs((x[1]*y[2]+x[2]*y[3]+x[3]*y[1]-x[1]*y[3]-x[2]*y[1]-x[3]*y[2])/2);
            area2=Math.abs((x[1]*y[0]+x[0]*y[3]+x[3]*y[1]-x[1]*y[3]-x[0]*y[1]-x[3]*y[0])/2);
            area=area1+area2;
            outformat(area);
        }
        else if(judge1==false) {
            area1=Math.abs((x[1]*y[3]+x[3]*y[0]+x[0]*y[1]-x[1]*y[0]-x[3]*y[1]-x[0]*y[3])/2);
            area2=Math.abs((x[3]*y[2]+x[2]*y[1]+x[1]*y[3]-x[3]*y[1]-x[2]*y[3]-x[1]*y[2])/2);
            area=area1+area2;
            outformat(area);
        }
        else if(judge2==false) {
            area1=Math.abs((x[1]*y[2]+x[2]*y[0]+x[0]*y[1]-x[1]*y[0]-x[2]*y[1]-x[0]*y[2])/2);
            area2=Math.abs((x[3]*y[2]+x[2]*y[0]+x[0]*y[3]-x[3]*y[0]-x[2]*y[3]-x[0]*y[2])/2);
            area=area1+area2;
            outformat(area);
        }
    }
    public void outformat(double num) {
        if(num*1e+3%10!=0) {
            String num1=String.format("%.3f",num);
            System.out.print(num1);
        }
        else System.out.print(num);
    }
}

class Line {
    public double[] line =new double[4];
    public double[] diagonal=new double[2];
    public double[] x=new double[4];
    public double[] y=new double[4];
    Line(double[] x,double[] y) {
        this.x=x;
        this.y=y;
    }
    public double[] line() {
        for(int i=0;i<4;i++) {
            int j=(i+1)%4;
            line[i]=Math.sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        }
        return line;
    }
    public double[] diagonal() {
        diagonal[0]=Math.sqrt((x[0]-x[2])*(x[0]-x[2])+(y[0]-y[2])*(y[0]-y[2]));
        diagonal[1]=Math.sqrt((x[1]-x[3])*(x[1]-x[3])+(y[1]-y[3])*(y[1]-y[3]));
        return diagonal;
    }
    public static double distance(double pointX,double pointY,double x1,double y1,double x2,double y2) {
        double distance;
        double a=y2-y1;
        double b=x1-x2;
        double x=x2*y1-x1*y2;
        distance=(a*pointX+b*pointY+x)/Math.pow(a*a+b*b,0.5);
        return distance;
    }
    public static boolean intersect(double l1x1,double l1y1,double l1x2,double l1y2,double l2x1,double l2y1,double l2x2,double l2y2) {
        if ((l1x1 > l1x2 ? l1x1 : l1x2) < (l2x1 < l2x2 ? l2x1 : l2x2) ||
            (l1y1 > l1y2 ? l1y1 : l1y2) < (l2y1 < l2y2 ? l2y1 : l2y2) ||
            (l2x1 > l2x2 ? l2x1 : l2x2) < (l1x1 < l1x2 ? l1x1 : l1x2) ||
            (l2y1 > l2y2 ? l2y1 : l2y2) < (l1y1 < l1y2 ? l1y1 : l1y2)){
            return false;
                }
        else if ((((l1x1 - l2x1)*(l2y2 - l2y1) - (l1y1 - l2y1)*(l2x2 - l2x1))*((l1x2 - l2x1)*(l2y2 - l2y1) - (l1y2 - l2y1)*(l2x2 - l2x1))) > 0 ||
                 (((l2x1 - l1x1)*(l1y2 - l1y1) - (l2y1 - l1y1)*(l1x2 - l1x1))*((l2x2 - l1x1)*(l1y2 - l1y1) - (l2y2 - l1y1)*(l1x2 - l1x1))) > 0){
                return false;
                }
        else return true;
    }
}


题目集5-点线形系列5-凸五边形的计算

要点:这次的题目集中的两道题目都十分的难,对数学知识的需求大,对图形的性质要熟练掌握。
题目后期要求求面积,故先写出一个求交点的函数,对于求交点,还是要巧妙的使用向量积。首先给出用向量积求出线段是否相交的方法:图形表示
行列式
部分代码块如下展示

class Point {
public double x;
public double y;
public Point() {

}

public Point(double x,double y) {
this.x=x;
this.y=y;
}

/* 设置坐标x,将输入参数赋值给属性x */
public void setX(double x) {
this.x = x;
}

/* 设置坐标y,将输入参数赋值给属性y */
public void setY(double y) {
this.y = y;
}

/* 获取坐标x,返回属性x的值 */
public double getX() {
return x;
}

/* 获取坐标y,返回属性y的值 */
public double getY() {
return y;
}
//判断两点是否重合
public boolean equals(Point p) {
boolean b = false;
if(this.x==p.getX()&&this.y==p.getY()) {
b=true;
}
return b;
}

/* 计算当前点和输入点p之间的距离 */
public double getDistance(Point p) {
return 0;
}
}
class Line {
private Point p1;//线上的第一个点
private Point p2;//线上的第二个点
public Line(double x1, double y1, double x2, double y2) {
Point p1 = new Point(x1, y1);
Point p2 = new Point(x2, y2);
LineInputError.pointsCoincideError(p1, p2);//两点是否重合,重合则报错并退出
this.p1 = p1;
this.p2 = p2;
}

public Line(Point p1, Point p2) {
LineInputError.pointsCoincideError(p1, p2);//两点是否重合,重合则报错并退出
this.p1 = p1;
this.p2 = p2;
}

/* 获取线条的斜率 */
public Double getSlope() {
// (x1-x2=0)注意考虑斜率不存在即返回double类型无穷大"Infinite"
return (p2.getY() - p1.getY()) / (p2.getX() - p1.getX());
}
/* 判断x是否在线上 */
public boolean isOnline(Point x) {
//System.out.println("isOnline");
//System.out.println(p1.x + " " + p1.y + " " + p2.x + " " + p2.y + " " + x.x + " " + x.y + " ");
// 点重合
if ((x.getX() == p1.getX() && x.getY() == p1.getY()) || (x.getX() == p2.getX() && x.getY() == p2.getY())) {
return true;
}
Line l = new Line(p1, x);
if (l.getSlope().isInfinite() && this.getSlope().isInfinite()) {
return true;
}

题目集-期中考试

7-1 点与线(类设计)

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

设计一个类表示平面直角坐标系上的线Line,私有属性除了标识线段两端的点point1、point2外,还有一个字符串类型的color,用于表示该线段的颜色,同样,除构造方法以及属性的getter与setter方法外,定义一个用于计算该线段长度的方法getDistance(),还有一个用于显示信息的方法display(),用来输出线段的相关信息
在这里插入图片描述
要点:其中,我用display()来按格式输出,在line类中用 getdistance()方法获取两点距离,将输入的两个点分别传入point类的两个对象 p1,p2中。

import java.util.*;
public class Main {
    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        Scanner input = new Scanner(System.in);
        String[] str = new String[5];

        for(int i = 0;i<5;i++) {
            str[i] = input.next();
        }

        for(int i = 0;i<4;i++) {
            if(Double.parseDouble(str[i])<=0||Double.parseDouble(str[i])>200) {
                System.out.println("Wrong Format");
                System.exit(0);
            }
        }
        Point point1 = new Point(Double.parseDouble(str[0]),Double.parseDouble(str[1]));
        Point point2 = new Point(Double.parseDouble(str[2]),Double.parseDouble(str[3]));
        Line line = new Line(point1,point2,str[4]);
        line.display();
    }

}

class Point{
    private double x, y;
    public Point() {
        super();
        // TODO 自动生成的构造函数存根
    }

    public Point(double x, double y) {
        super();
        this.x = x;
        this.y = y;
    }

    public void display() {
        System.out.println("("+String.format("%.2f", x)+","+String.format("%.2f", y)+")");
    }

    public double getX() {
        return x;
    }

    public void set1(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void set2(double y) {
        this.y = y;
    }
}

class Line{
    private Point point1,point2;
    private String color;
    public Line() {
        super();
        // TODO 自动生成的构造函数存根
    }
    public Line(Point point1, Point point2, String color) {
        super();
        this.point1 = point1;
        this.point2 = point2;
        this.color = color;
    }
    public Point getP1() {
        return point1;
    }
    public void setP1(Point point1) {
        this.point1 = point1;
    }
    public Point getP2() {
        return point2;
    }
    public void setP2(Point point2) {
        this.point2 = point2;
    }
    public String getColor() {
        return color;
    }
    public void setColor(String color) {
        this.color = color;
    }

    public double getDistance() {
        return Math.pow( Math.pow((point1.getX()-point2.getX()), 2) + Math.pow((point1.getY()-point2.getY()), 2), 0.5);
    }

    public void display() {
        System.out.println("The line's color is:"+color);
        System.out.println("The line's begin point's Coordinate is:");
        point1.display();
        System.out.println("The line's end point's Coordinate is:");
        point2.display();
        System.out.println("The line's length is:"+String.format("%.2f", getDistance()));
    }
}
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()方法,从而实现多态特性。

在这里插入图片描述
要点:父类中只有一个display()方法,其他类都继承Element类;

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        Scanner input = new Scanner(System.in);
        String[] str = new String[5];

        for(int i = 0;i<5;i++) {
            str[i] = input.next();
        }

        for(int i = 0;i<4;i++) {
            if(Double.parseDouble(str[i])<=0||Double.parseDouble(str[i])>200) {
                System.out.println("Wrong Format");
                System.exit(0);
            }
        }

        Point point1 = new Point(Double.parseDouble(str[0]),Double.parseDouble(str[1]));
        Point point2 = new Point(Double.parseDouble(str[2]),Double.parseDouble(str[3]));
        Line line = new Line(point1,point2,str[4]);
        Plane plane = new Plane(str[4]);
        Element element;

        element = point1;//起点
        element.display();

        element = point2;//终点
        element.display();

        element = line;//线段
        element.display();

        element = plane;//面
        element.display();

    }

}

class Point extends Element{
    private double x, y;

    public Point() {
        super();
        // TODO 自动生成的构造函数存根
    }
    public Point(double x, double y) {
        super();
        this.x = x;
        this.y = y;
    }
    @Override
    public void display() {
        System.out.println("("+String.format("%.2f", x)+","+String.format("%.2f", y)+")");
    }
    public double getX() {
        return x;
    }
    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }
}
class Line extends Element{
    private Point point1,point2;
    private String color;
    public Line() {
        super();
        // TODO 自动生成的构造函数存根
    }
    public Line(Point point1, Point point2, String color) {
        super();
        this.point1 = point1;
        this.point2 = point2;
        this.color = color;
    }
    public Point getPoint1() {
        return point1;
    }
    public void setPoint1(Point point1) {
        this.point1 = point1;
    }
    public Point getPoint2() {
        return point2;
    }
    public void setPoint2(Point point2) {
        this.point2 = point2;
    }
    public String getColor() {
        return color;
    }
    public void setColor(String color) {
        this.color = color;
    }

    public double getDistance() {
        return Math.pow( (point1.getX()-point2.getX())*(point1.getX()-point2.getX()) +(point1.getY()-point2.getY())*(point1.getY()-point2.getY()), 0.5);
    }
    @Override
    public void display() {
        System.out.println("The line's color is:"+color);
        System.out.println("The line's begin point's Coordinate is:");
        point1.display();
        System.out.println("The line's end point's Coordinate is:");
        point2.display();
        System.out.println("The line's length is:"+String.format("%.2f", getDistance()));
    }
}
class Plane extends Element{
    private String color;
    public Plane() {
        super();
        // TODO 自动生成的构造函数存根
    }
    public Plane(String color) {
        super();
        this.color = color;
    }
    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }
    @Override
    public void display() {
        // TODO 自动生成的方法存根
        System.out.println("The Plane's color is:" + color);
    }
}
abstract class  Element{
    public abstract void display();

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

在“点与线(继承与多态)”题目基础上,对题目的类设计进行重构,增加容器类保存点、线、面对象,并对该容器进行相应增、删、遍历操作。
在原有类设计的基础上,增加一个GeometryObject容器类,其属性为ArrayList类型的对象(若不了解泛型,可以不使用)
增加该类的add()方法及remove(int index)方法,其功能分别为向容器中增加对象及删除第index - 1(ArrayList中index>=0)个对象
在主方法中,用户循环输入要进行的操作(choice∈[0,4]),其含义如下:
1:向容器中增加Point对象
2:向容器中增加Line对象
3:向容器中增加Plane对象
4:删除容器中第index - 1个数据,若index数据非法,则无视此操作
0:输入结束
在这里插入图片描述

import java.util.*;
public class Main {
    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        Scanner in = new Scanner(System.in);
        String str1;
        double x1,y1,x2,y2;
        GeometryObject obj = new GeometryObject();
        int choice = in.nextInt();
        while(choice!=0) {
            switch(choice) {
                case 1://insert Point object into list
                    x1 = Double.parseDouble(in.next());
                    y1 = Double.parseDouble(in.next());

                    if(x1<=0||x1>200||y1<=0||y1>200) {
                        System.out.println("Wrong Format");
                        System.exit(0);
                    }
                    Point point1 = new Point(x1,y1);
                    obj.add(point1);
                    break;
                case 2://insert Line object into list
                    x1 = Double.parseDouble(in.next());
                    y1 = Double.parseDouble(in.next());
                    x2 = Double.parseDouble(in.next());
                    y2 = Double.parseDouble(in.next());
                    str1 = in.next();
                    Point point2 = new Point(x1,y1);
                    Point point3 = new Point(x2,y2);
                    Line line = new Line(point2,point3,str1);

                    obj.add(line);
                    break;
                case 3://insert Plane object into list
                    str1 = in.next();
                    Plane plane = new Plane(str1);

                    obj.add(plane);
                    break;
                case 4://delete index - 1 object from list
                    int i = in.nextInt();
                    obj.remove(i);
                    break;
            }
            choice = in.nextInt();
        }
        for(Element e : obj.getList() )
        {
            e.display();
        }

    }

}

class Point extends Element{
    private double x, y;

    public Point() {
        super();
        // TODO 自动生成的构造函数存根
    }

    public Point(double x, double y) {
        super();
        this.x = x;
        this.y = y;
    }
    @Override
    public void display() {
        System.out.println("("+String.format("%.2f", x)+","+String.format("%.2f", y)+")");
    }

    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }
}

class Line extends Element{
    private Point point1,point2;
    private String color;
    public Line() {
        super();
        // TODO 自动生成的构造函数存根
    }
    public Line(Point point1, Point point2, String color) {
        super();
        this.point1 = point1;
        this.point2 = point2;
        this.color = color;
    }
    public Point getPoint1() {
        return point1;
    }
    public void setPoint1(Point point1) {
        this.point1 = point1;
    }
    public Point getPoint2() {
        return point2;
    }
    public void setPoint2(Point point2) {
        this.point2 = point2;
    }
    public String getColor() {
        return color;
    }
    public void setColor(String color) {
        this.color = color;
    }

    public double getDistance() {
        return Math.pow( (point1.getX()-point2.getX())*(point1.getX()-point2.getX()) +(point1.getY()-point2.getY())*(point1.getY()-point2.getY()), 0.5);
    }
    @Override
    public void display() {
        System.out.println("The line's color is:"+color);
        System.out.println("The line's begin point's Coordinate is:");
        point1.display();
        System.out.println("The line's end point's Coordinate is:");
        point2.display();
        System.out.println("The line's length is:"+String.format("%.2f", getDistance()));
    }
}

class Plane extends Element{
    private String color;

    public Plane() {
        super();
        // TODO 自动生成的构造函数存根
    }

    public Plane(String color) {
        super();
        this.color = color;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    @Override
    public void display() {
        // TODO 自动生成的方法存根
        System.out.println("The Plane's color is:" + color);
    }

}
class GeometryObject{
    private ArrayList<Element> list = new ArrayList<Element>();

    public GeometryObject() {
        super();
        // TODO 自动生成的构造函数存根
    }

    public void add(Element element) {
        list.add(element);
    }

    public void remove(int index) {
        if(index>0&&index<=list.size())
            list.remove(index-1);
    }

    public ArrayList<Element> getList() {
        return list;
    }

}
abstract class  Element{
    public abstract void display();

}

踩坑心得

对测试的每一个测试点有的都不清楚,有的时候都是碰碰撞撞碰运气,还有之前对于图形的掌握还不够,导致最开始设计的时候,处处报错。

总结

在这几次大作业中我有巨大的收获。第四次与第五次的PTA作业都建立在点线系列的基础上,对点线及多边形的判定与多种相关的计算达到练习与巩固的效果。题目中对数学的侧重较多,对数学逻辑思维要求较高,因此对将数学逻辑转化为程序逻辑的要求也更高。而期中考试则是更倾向编程逻辑的题目,考察了继承、多态及容器。
所以,经过这几次作业及考试,让我懂得了编程题不一定只是单纯的知识点考察类型题,更是对数理逻辑思维的锻炼,以及对综合能力的考察,希望在今后的学习里,能记住这几次作业的经验教训,不断提高自己。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值