编程语言
首页 > 编程语言> > java

java

作者:互联网

· 前言:

         1.题目集四前言

  本次题目共分3到练习题,分别考察判断、循环、数组的建立、运用,加强了我对数组中数据的应用、查找、判断,题目集一的难度相对比较简单一些,非是困难程度,题目集一是侧重于对基础知识点的掌握,加强了我的java基础。加强了我对调用数据的应用,学会了如何在文字中提出数字,并进行计算,排序。坐标的输入,读取,计算,判断最终出值与输出的关系。学会(静态、公有方法),存款,取款等操作。

        2.期中考试

学会了建立多类,本次3题的难度大于题目集一题目的难度,其中知识的考查包括题目集一知识,多些为数组中转化的运用,指定数组输出,判断指定输出,内容判断,内容提取等等,练习程序多种运用写法,加强运用性,本次题目集的重点为第二题,本题目的难度略大于其他题目难度,起初并不知道如何去写,在书上学习和上网查询后也掌握了后了解怎样进行编程,考察了我们对于字符串数组,以及字符串.length()方法的用法,相对简单,本次题目加强了我对java的多方面运用,对java用法更灵活。

      3.期中考试

本次题目集的难度高于前两次的题目集难度,考察坐标的输入问题,对数据中数组的读取,第一题的难度主要为点与点之间距离计算,与输入"+,-"的坐标判断并能否运行,解决后其他难度就降低了,第二,第三题的主要问题和第一题基本一样,判断不同,为点线距离问题,三角形判断问题,考察多态性以及使用方法,本题目集的第二,第三题的难度相对第一题难度有所提高,主要考察我们对所建立的使用与调用问题。

    4期中考试

第三题原型与第一、二题的基础,并加强难度,改变代码,在“点与线(继承与多态)”题目基础上,增加容器类保存点、线、面对象,并对该容器进行相应增、删、遍历操作。此题的难度在于如何建立容器,在容器中建立各个对象,主要考察我们继承与多态,此题难度高于前两道题,略显困难。

·让我对类的聚合关系理解更加深刻,还有类的继承和多态,本次考察主要向我们渗透了一些关于Java的设计原则,让我们能更加深刻的思考类与类之间的关系,从而深入的了解面向对象的设计原则,这些都是这四次习题集考察的亮点。

· 设计与分析:

 

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true) {
            String a=sc.nextLine();
            if(a.equals("end"))
                break; 
            String[] split=a.split("\\D+");
            int i;
            long sum = 0;
            for(i=0;i<split.length;i++){
                if(!split[i].equals(""))
                {
                    int digit=Integer.parseInt(split[i]);
                    sum+=digit;
                }
            }
            System.out.println(sum);
        }
    }
}

本代码为题目集四7-1,主考察我们文字中提取数字,并进行运算,其中主要运用正则表达式,通过本次题目我了解并学会了正则表达式,正则表达式是解决此题的关键,依赖性也较大,使类与类之间的联系更紧切,此题大部分运用数组并对数组中数据的查找,数组的储存,中字符串的调用,输出等等。

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
    Scanner sc=new Scanner(System.in); 
    Double x1 = sc.nextDouble();
    Double y1 = sc.nextDouble();
    Double x2 = sc.nextDouble();
    Double y2 = sc.nextDouble();
    String color = sc.next();
    Point point1 = new Point(x1, y1);
    Point point2 = new Point(x1, y2);
    Line line = new Line(point1,point2,color);
       if(x1<=0||x1>200||x2<=0||x2>200||y1<=0||y1>200||y2<=0||y2>200)
       {
           System.out.println("Wrong Format");
       }
       else
       {   
        Main point = null;
        line.display();
       }
    }

    private String getcolor;
    private Point point2;
    private Object point1;
    
       public void display() {
           System.out.println("The line's color is:"+this.getcolor);
                System.out.println("The line's begin point's Coordinate is:"+String.format("%.2f", ((Point) this.point1).getX())+","+String.format("%.2f",((Point) this.point1).getY()));
                System.out.println("The line's end point's Coordinate is:"+String.format("%.2f",((Point) this.point2).getX())+","+String.format("%.2f",((Point) this.point2).getY()));
                System.out.println("The line's length is:"+Math.sqrt((((Point) point1).getX()-point2.getX())*(((Point) point1).getX()-point2.getX())+(((Point) point1).getY()-point2.getY())*(((Point) point1).getY()-point2.getY())));
       }
       }
class Line{
     Point point1;
     Point point2;
     String color;
     public Line(Point p1,Point p2,String color) {
         this.point1 = p1;
         this.point2 = p2;
         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.sqrt((point1.getX()-point2.getX())*(point1.getX()-point2.getX())+(point1.getY()-point2.getY())*(point1.getY()-point2.getY()));
    }
    public void display() {
      
    }
} 
class Point {
    double x;
    double y;// x,y为点的坐标
    private Object point1;
    private Point point2;
    //求两点之间的距离
    public Point(double x,double y) {
       
        this.x = x;
        this.y = 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;
    }
    public void display() {
        
    }
    }

此题为期中考试第一题,主考察类设计,建立多个类,运行多个类,其中有对颜色的输入,对相对颜色的输出,输入横坐标、纵坐标、终点的横坐标、纵坐标,判断两点之间的距离,输出长度值,这就是本题考查的重点。

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
    Scanner sc=new Scanner(System.in); 
    Double x1 = sc.nextDouble();
    Double y1 = sc.nextDouble();
    Double x2 = sc.nextDouble();
    Double y2 = sc.nextDouble();
    String color = sc.next();
    Point point1 = new Point(x1, y1);
    Point point2 = new Point(x1, y2);
    Line line = new Line(point1,point2,color);
       if(x1<=0||x1>200||x2<=0||x2>200||y1<=0||y1>200||y2<=0||y2>200)
       {
           System.out.println("Wrong Format");
       }
       else
       {   
        Main point = null;
        line.display();
       }
    }

    private String getcolor;
    private Point point2;
    private Object point1;
    
       public void display() {
           System.out.println("The line's color is:"+this.getcolor);
                System.out.println("The line's begin point's Coordinate is:"+String.format("%.2f", ((Point) this.point1).getX())+","+String.format("%.2f",((Point) this.point1).getY()));
                System.out.println("The line's end point's Coordinate is:"+String.format("%.2f",((Point) this.point2).getX())+","+String.format("%.2f",((Point) this.point2).getY()));
                System.out.println("The line's length is:"+Math.sqrt((((Point) point1).getX()-point2.getX())*(((Point) point1).getX()-point2.getX())+(((Point) point1).getY()-point2.getY())*(((Point) point1).getY()-point2.getY())));
       }
       }
class Line{
     Point point1;
     Point point2;
     String color;
     public Line(Point p1,Point p2,String color) {
         this.point1 = p1;
         this.point2 = p2;
         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.sqrt((point1.getX()-point2.getX())*(point1.getX()-point2.getX())+(point1.getY()-point2.getY())*(point1.getY()-point2.getY()));
    }
    public void display() {
      
    }
} 
class Point {
    double x;
    double y;// x,y为点的坐标
    private Object point1;
    private Point point2;
    //求两点之间的距离
    public Point(double x,double y) {
       
        this.x = x;
        this.y = 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;
    }
    public void display() {
        
    }
    }

此题为期中考试第二题,此题主考察继承与多态,在第一题的基础上改进,基础也是建立多种类,在类的基础上进行继承与多态,此题输出与第一题相似,也是输出颜色,计算输出距离,输出颜色,以实现继承与多态的技术性需求。

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
    Scanner sc=new Scanner(System.in); 
    Double x1 = sc.nextDouble();
    Double y1 = sc.nextDouble();
    Double x2 = sc.nextDouble();
    Double y2 = sc.nextDouble();
    String color = sc.next();
    Point point1 = new Point(x1, y1);
    Point point2 = new Point(x1, y2);
    Line line = new Line(point1,point2,color);
       if(x1<=0||x1>200||x2<=0||x2>200||y1<=0||y1>200||y2<=0||y2>200)
       {
           System.out.println("Wrong Format");
       }
       else
       {   
        Main point = null;
        line.display();
       }
    }

    private String getcolor;
    private Point point2;
    private Object point1;
    
       public void display() {
           System.out.println("The line's color is:"+this.getcolor);
                System.out.println("The line's begin point's Coordinate is:"+String.format("%.2f", ((Point) this.point1).getX())+","+String.format("%.2f",((Point) this.point1).getY()));
                System.out.println("The line's end point's Coordinate is:"+String.format("%.2f",((Point) this.point2).getX())+","+String.format("%.2f",((Point) this.point2).getY()));
                System.out.println("The line's length is:"+Math.sqrt((((Point) point1).getX()-point2.getX())*(((Point) point1).getX()-point2.getX())+(((Point) point1).getY()-point2.getY())*(((Point) point1).getY()-point2.getY())));
       }
       }

本题为期中考试第三题,此题建立在第一、二题的基础上。此题因为时间问题和知识运用不够熟练,并没在pta联系中提交,有后余时间将其完成。本题考察点与线间的距离运算问题,本题目与数学结合,难度为输入数字正确进入相应判断运行公式中,正确输出,建立不同的数据类型,调用建立函数,进入计算运行,其他问题为情况不符合情况,判断问题的否定输出等等。本题出现多次Blog,多次看书,在网上查找学习资料,学习,了解,最后进行编程。

下面是我从网上寻找的降低圈复杂度的方法,在今后的学习或者在解决PTA题目时会学着慢慢的渗透和尝试降低圈复杂度的方法。

•Simplifying Conditional Expressions(简化条件表达式)

Decompose Conditional(分解条件式)

Consolidate Conditional Expression(合并条件式)

Consolidate Duplicate Conditional Fragments(合并重复的条件片断)

标签:java,String,Point,color,point1,point2,public
来源: https://www.cnblogs.com/javabook/p/16251341.html