期中考试题目集分析

期中考试第一题

 

 

这道题目是期中考试第一题,本题没有什么算法难度,但要通过相关的类与类之间的设计满足题目要求,对于类的相关属性和行为是严格要求的,不能自己随意设计,而且相关的属性也应该使用private来修饰,除了类的行为外不能使用public,类与类之间的交流联系应该要尽可能的低,特别注意的是对于最后的答案输出应该要将所有的printd都放在line这个,因为这个类中的属性包含了point类,能够得到答案值,而point类中却没有,答案中所要的linedistance,所以不能输出,因为点与点之间不能区别出第一个点和第二个点,所以答案中的beginning和end不能区分,所以所有的输出应该放在最后的line进行输出,才能得到正确答案

  1 package 期中考试;
  2 
  3 import java.util.Scanner;
  4 
  5 public class Main {
  6     public static void main(String[] args) {
  7         Scanner input = new Scanner(System.in);
  8         double x1,y1,x2,y2;
  9         String color;
 10         x1= input.nextDouble();
 11         y1= input.nextDouble();
 12         x2= input.nextDouble();
 13         y2= input.nextDouble();
 14         if(x1>200||x1<=0||x2>200||x2<=0||y1>200||y1<=0||y2>200||y2<=0){
 15             System.out.println("Wrong Format");
 16             return;
 17         }
 18         color= input.next();
 19         //System.out.println("The line's color is:"+color);
 20         point point1=new point(x1,y1);
 21         point point2=new point(x2,y2);
 22         line line=new line(color,point1,point2);
 23         line.display();
 24 
 25     }
 26 }
 27 class point{
 28   private double x;
 29     private double y;
 30     public point(){
 31 
 32     }
 33     public point(double x1,double y1) {
 34         this.x = x1;
 35         this.y=y1;
 36     }
 37 
 38     public double getX1() {
 39         return x;
 40     }
 41 
 42     public double getY1() {
 43         return y;
 44     }
 45 
 46     public void setX1(double x1) {
 47         this.x = x1;
 48     }
 49 
 50     public void setY1(double y1) {
 51         this.y = y1;
 52     }
 53     public void display(){
 54 
 55     }
 56 
 57 }
 58 class line{
 59    private String color;
 60     private point point1;
 61     private  point point2;
 62     public  line(){}
 63     public  line(String color,point point1,point point2){
 64         this.color=color;
 65         this.point1=point1;
 66         this.point2=point2;
 67     }
 68 
 69     public point getPoint1() {
 70         return point1;
 71     }
 72 
 73     public point getPoint2() {
 74         return point2;
 75     }
 76 
 77     public String getColor() {
 78         return color;
 79     }
 80 
 81     public void setColor(String color) {
 82         this.color = color;
 83     }
 84 
 85     public void setPoint1(point point1) {
 86         this.point1 = point1;
 87     }
 88 
 89     public void setPoint2(point point2) {
 90         this.point2 = point2;
 91     }
 92    public double getdistance(){
 93           return Math.sqrt(Math.pow(point1.getX1()- point2.getX1(),2)+Math.pow(point1.getY1() -point2.getY1(),2));
 94    }
 95    public void  display(){
 96         System.out.println("The line's color is:"+color);
 97        System.out.println("The line's begin point's Coordinate is:");
 98        System.out.printf("(%.2f,%.2f)\n",point1.getX1(),point1.getY1());
 99        System.out.println("The line's end point's Coordinate is:");
100        System.out.printf("(%.2f,%.2f)\n",point2.getX1(),point2.getY1());
101        System.out.printf("The line's length is:%.2f",getdistance());
102    }
103 
104 }

期中考试第二题

 

 

 

这道题目是期中考试的第二题,这道题目是对第一题的迭代,整体的代码与算法与第一题并没有太大的区别,但是这道题目是多添加了一个plane(平面)类以及一个父类element并且该类是一个抽象类这个抽象类中只有一个方法display,该方法中也没有什么具体的东西,主要的东西都是要在子类中实现,实现具体的行为输出,然后再在主类中的main方法中实现相关调用,并且要特别注意答案输出的结果的先后顺序对于这个结果我们发现point类现在有了具体的输出,line类中的输出却并没有太大的变化依然同第一道题目一样,实现相关的输出,然而在plane这个平面类中却并没有太多的行为和属性,只有color(和line的颜色一样)以及也有print,最后答案的输出都是在主类中通过父类完成调用并且实现向下转型,将子类对象赋值给父类对象实现向下转型,最后完成答案的输出,当然也要注意答案中的非法数据判断

  1 package 期中考试2;
  2 
  3 import javax.lang.model.element.Element;
  4 import java.util.Scanner;
  5 
  6 public class Main {
  7     public static void main(String[] args) {
  8         Scanner input = new Scanner(System.in);
  9         double x1,y1,x2,y2;
 10         String color;
 11 
 12         x1= input.nextDouble();
 13         y1= input.nextDouble();
 14         x2= input.nextDouble();
 15         y2= input.nextDouble();
 16         if(x1>200||x1<=0||x2>200||x2<=0||y1>200||y1<=0||y2>200||y2<=0){
 17             System.out.println("Wrong Format");
 18             return;
 19         }
 20 
 21         color= input.next();
 22         point point1=new point(x1,y1);
 23         point point2=new point(x2,y2);
 24         plane plane=new plane(color);
 25         line line=new line(color,point1,point2);
 26         element element;
 27         element=  point1;
 28         element.display();
 29         element=point2;
 30         element.display();
 31         element=line;
 32         element.display();
 33         element=plane;
 34         element.display();
 35         //System.out.println("The line's color is:"+color);
 36 
 37 
 38     }
 39 }
 40 abstract class element{
 41 public void display(){
 42 
 43 }
 44 }
 45      class plane extends element{
 46     private String color;
 47     public plane(){}
 48     public plane(String color){
 49         this.color=color;
 50     }
 51 
 52     public void setColor(String color) {
 53         this.color = color;
 54     }
 55 
 56     public String getColor() {
 57         return color;
 58     }
 59 
 60     @Override
 61     public void display() {
 62         super.display();
 63         System.out.print("he Plane's color is:"+color);
 64     }
 65 }
 66         class point extends element{
 67     private double x;
 68     private double y;
 69     public point(){
 70 
 71     }
 72     public point(double x1,double y1) {
 73         this.x = x1;
 74         this.y=y1;
 75     }
 76 
 77     public double getX1() {
 78         return x;
 79     }
 80 
 81     public double getY1() {
 82         return y;
 83     }
 84 
 85     public void setX1(double x1) {
 86         this.x = x1;
 87     }
 88 
 89     public void setY1(double y1) {
 90         this.y = y1;
 91     }
 92 
 93     @Override
 94     public void display() {
 95 
 96         super.display();
 97 
 98     }
 99 }
100 class line extends element{
101     private String color;
102     private point point1;
103     private  point point2;
104     public  line(){}
105     public  line(String color,point point1,point point2){
106         this.color=color;
107         this.point1=point1;
108         this.point2=point2;
109     }
110 
111     public point getPoint1() {
112         return point1;
113     }
114 
115     public point getPoint2() {
116         return point2;
117     }
118 
119     public String getColor() {
120         return color;
121     }
122 
123     public void setColor(String color) {
124         this.color = color;
125     }
126 
127     public void setPoint1(point point1) {
128         this.point1 = point1;
129     }
130 
131     public void setPoint2(point point2) {
132         this.point2 = point2;
133     }
134     public double getdistance(){
135         return Math.sqrt(Math.pow(point1.getX1()- point2.getX1(),2)+Math.pow(point1.getY1() -point2.getY1(),2));
136     }
137 
138     @Override
139     public void display() {
140         super.display();
141         System.out.printf("(%.2f,%.2f)\n",point1.getX1(),point1.getY1());
142         System.out.printf("(%.2f,%.2f)\n",point2.getX1(),point2.getY1());
143 
144         System.out.println("The line's color is:"+color);
145         System.out.println("The line's begin point's Coordinate is:");
146         System.out.printf("(%.2f,%.2f)\n",point1.getX1(),point1.getY1());
147         System.out.println("The line's end point's Coordinate is:");
148         System.out.printf("(%.2f,%.2f)\n",point2.getX1(),point2.getY1());
149         System.out.printf("The line's length is:%.2f",getdistance());
150         System.out.print("he Plane's color is:"+color);
151     }
152 }

期中考试第三题

 

 

这道题目是对第二题的迭代,整体的题目的设计方法与第二题和第一题有较大的区别,但是基本的类的数量只是比第二题多了一个而已,新添加的geometobject主要是实现添加和删除而对于属性则是有了一个Java自带的Arrylist,要求添加的类型则是element,而对于element则是和第二题一样都是其他类的父类,但是对于point,line,以及plane却没有变化,依然和第二题一样,但是对于main方法却有一些变化,按照题目要求我们要对每次的输入进行判断是删除还是添加,并且以输入0为结束的标志,在输入结束后对list所有对象进行输出,输出时与前面的题目不一样,这道题目的输出主要是输入了什么,然后在对应的类当中进行输出,例如输入了一个点,那么就只要输入point中的display的,输入了两个点就输出line中的display,如果输入了颜色,那么就只要输出line中的display,完成输出,这道题目也是需要完成向下主转型的,然后再将对应的类添加到list中,感觉这道题与题目集四atm好像,但比那道题目简单,但是我却因为疏忽把这道题目的输出搞错了,将for循环不小心弄到while循环里面导致了错误,并且一直没有发现,还以为是自己的算法或者是添加转型出现了错误,所以通过这道题也认识到了不管是多简单的题目,我们都应该小心对待,不要犯低级错误,一定要注意看清楚循环括号位置。小心低级错误!!!!!!!!!!!

并且这道题目也要注意每次输入的非法数据判断

  1 package 期中考试3;
  2 
  3 import java.util.ArrayList;
  4 import java.util.Scanner;
  5 
  6 public class Main {
  7     public static void main(String[] args) {
  8         int choice;
  9         double x1,y1,x2,y2,x,y;
 10         int index,f=0;
 11         String color;
 12         point point1;
 13         point point2;
 14         element element;
 15         plane plane;
 16         line line;
 17         geometryobject geometryobject=new geometryobject();
 18         Scanner input = new Scanner(System.in);
 19         while (true) {
 20 
 21             choice = input.nextInt();
 22             if(choice==0) break;
 23             switch (choice) {
 24 
 25                 case 1://insert Point object into list
 26 
 27                     x=input.nextDouble();
 28                     y= input.nextDouble();
 29                     point1=new point(x,y);
 30                     element=point1;
 31                     geometryobject.add(element);
 32                     break;
 33                 case 2://insert Line object into list
 34                     x1= input.nextDouble();
 35                     y1= input.nextDouble();
 36                     x2=input.nextDouble();
 37                     y2=input.nextDouble();
 38                     color= input.next();
 39                     point1=new point(x1,y1);
 40                     point2=new point(x2,y2);
 41                     line=new line(color,point1,point2);
 42                     element= line;
 43                     geometryobject.add(element);
 44                     break;
 45                 case 3://insert Plane object into list
 46                     color=input.next();
 47                     plane=new plane(color);
 48                     element=plane;
 49                     geometryobject.add(element);
 50                     break;
 51                 case 4://delete index - 1 object from list
 52                     index=input.nextInt();
 53                     geometryobject.remove(index-1);
 54                 case 0:
 55                     break;
 56             }
 57             ArrayList<element> l = geometryobject.getlist();
 58 
 59         }
 60         for(int i=0;i<geometryobject.getlist().size();i++){
 61             geometryobject.getlist().get(i).display();
 62         }
 63     }
 64 }
 65 abstract class element{
 66     public void display(){
 67 
 68     }
 69 }
 70 class geometryobject{
 71     public geometryobject(){}
 72     private ArrayList<element> list=new ArrayList<>();
 73     public void add(element element){
 74         list.add(element);
 75     }
 76     public void remove(int index){
 77         list.remove(index);
 78     }
 79     public  ArrayList<element> getlist(){
 80         return list;
 81     }
 82 }
 83 class plane extends element {
 84     private String color;
 85     public plane(){}
 86     public plane(String color){
 87         this.color=color;
 88     }
 89 
 90     public void setColor(String color) {
 91         this.color = color;
 92     }
 93 
 94     public String getColor() {
 95         return color;
 96     }
 97 
 98     @Override
 99     public void display() {
100 
101         System.out.print("The Plane's color is:"+color);
102     }
103 }
104 class point extends element {
105     private double x;
106     private double y;
107     public point(){
108 
109     }
110     public point(double x1,double y1) {
111         this.x = x1;
112         this.y=y1;
113     }
114 
115     public double getX1() {
116         return x;
117     }
118 
119     public double getY1() {
120         return y;
121     }
122 
123     public void setX1(double x1) {
124         this.x = x1;
125     }
126 
127     public void setY1(double y1) {
128         this.y = y1;
129     }
130 
131     @Override
132     public void display() {
133 
134 
135         System.out.printf("(%.2f,%.2f)\n",getX1(),getY1());
136     }
137 }
138 class line extends element {
139     private String color;
140     private point point1;
141     private point point2;
142     public  line(){}
143     public  line(String color, point point1, point point2){
144         this.color=color;
145         this.point1=point1;
146         this.point2=point2;
147     }
148 
149     public point getPoint1() {
150         return point1;
151     }
152 
153     public point getPoint2() {
154         return point2;
155     }
156 
157     public String getColor() {
158         return color;
159     }
160 
161     public void setColor(String color) {
162         this.color = color;
163     }
164 
165     public void setPoint1(point point1) {
166         this.point1 = point1;
167     }
168 
169     public void setPoint2(point point2) {
170         this.point2 = point2;
171     }
172     public double getdistance(){
173         return Math.sqrt(Math.pow(point1.getX1()- point2.getX1(),2)+Math.pow(point1.getY1() -point2.getY1(),2));
174     }
175 
176 
177     public void display() {
178 
179 
180         System.out.println("The line's color is:"+color);
181         System.out.println("The line's begin point's Coordinate is:");
182         System.out.printf("(%.2f,%.2f)\n",point1.getX1(),point1.getY1());
183         System.out.println("The line's end point's Coordinate is:");
184         System.out.printf("(%.2f,%.2f)\n",point2.getX1(),point2.getY1());
185         System.out.printf("The line's length is:%.2f",getdistance());
186 
187     }
188 }

 ATM机的类设计

 

 个人感觉这道题目的难度较大,这道题目要求我们在写代码的时候必须要对整个代码有整体概念,所以要求我们必须先有类图,明白整个题目是由哪些点哪些类所构成,并且要梳理好每个类的所拥有的属性,并且明白每个属性存在的意义说是什么,有什么作用,怎样让这些类能够合理调用,并且减小类之间的耦合性,并且在对我们所得到的结果进行输出时,我们应该要进行分开,因为这道题目的输入有两种情况,应该分开讨论,例如account类在设计时应该要注意类与bank的关系做到合理调用,并且对于类也要区分它们的功能,判断它们是用来做什么的,如changemoney和present是功能类,个人感觉这道题目的主要难点在于对check,如何对输入的帐户进行匹配,匹配对应的用户名和帐户名,明白一对多和多对一的关系,当然也不应该想得太复杂,主要是在输入保存数据是清晰分配存储,然后在对应的存储位置进行搜索需要的结果,做到层层调用,层层检查,遇到不符合题目要求的数据,就可以输出对应的错误,然后就结束程序,进行下一次的输入,因为是要在while循环在实现重复多次操作的,并且在对帐户的余额进行修改时也应该有一个独立的类来实现该功能

 单向链表的设计

 

 整个链表的设计与之前的C语言差不多,但是由于语法的区别,所以二者的设计也还是有很多的不一样的,首先这次的链表的设计是实现增加删除和查询功能的,并且这次的设计是通过使用接口和泛型来实现的整体的设计还是有很大的区别的,并且我们要注意每个类但是有固定的属性的然后实现接口中的方法至于链表的设计,依然是头节点,和尾节点,以及临时节点,实现增加功能以及其它功能,由于Java中没有结构体的概念,但是我们依然可以使用类来实现类似于结构体的功能,区分为数据域和指针域,注意在删除的时,应该要找到待删除节点的前一个节点,整体链表概念依然是地址,并没有太大的差别,在输出的时侯也要注意答案的先后次序

package 链表实现;

public  class Node<E>  {
    private E o;

    public Node<E> next;
    public Node(){
        //this.o=o;
    }

    public void setO(E o) {
        this.o = o;
    }

    public E getO(){
        return o;
    }
}
package 链表实现;

import java.util.Scanner;
//import java.util.Scanner;
public class Main {
   public static void main (String[] args){

      LList<Integer> num = new LList<>() ;

      num.add(50);
      num.add(60);
      num.add(70);
      while (true){
         int ch=0;
         //System.out.println("**********************************************************");
         System.out.println("**********************-----请输入*您的选择-----************************");
         System.out.println("1.删除链表的节点"+"******************************************");
         System.out.println("2.指定位置增加(输入下标和要增加的数)"+"************************");
         System.out.println("3.尾部增加(直接输入要添加的数)"+"*****************************");
         System.out.println("4.打印链表中的数"+"******************************************");
         System.out.println("5.得到节点个数"+"*******************************************");
         System.out.println("6.得到指定节点的数"+"****************************************");
         System.out.println("7.退出系统操作"+"*******************************************");
         System.out.println("*********************************************************");
         Scanner input=new Scanner(System.in);
         ch=input.nextInt();
         if(ch==1){
            int m;
            m=input.nextInt();
            num.remove(m);
         }
         if(ch==2){
            int m,n;
            m=input.nextInt();
            n=input.nextInt();
            num.add(m,n);
         }
         if(ch==3){
            int m;
            m=input.nextInt();
            num.add(m);
         }
         if(ch==4){
            num.printList();
         }
         if(ch==6){
            int m;
            m=input.nextInt();
            System.out.println(num.get(m));
         }
         if(ch==5){
            //num.size();
            System.out.println(num.size());
         }
         if(ch==7){
            return;
         }
      }
   }
}
package 链表实现;

public  class LList<E> implements LinearListInterface<E>{
    E m;
    private Node<E> head=null,curr,tail;
    private int size=0;
    boolean empty;

    public LList() {
    head=new Node<>();
    }


    public boolean isEmpty(){
        if(head==null){
            empty=true;
        }else {
            empty=false;
        }
        return empty;
    }

    public int size(){
        Node<E> temp=head;
        int size1=0;
        while (true){
            if(temp.next==null){return size;}
          size++;
            temp=temp.next;
        }
        //return size;
    }

    public E get(int index){
        Node<E> temp=head;
        int size1=0;
        boolean flag=false;
        while (true){
            if(size1==index){
                return temp.getO();
            }
            if(temp.next==null){
                System.out.println("无法找到,您要查找的点");
                break;
            }
            temp=temp.next;
            size1++;
        }
        return m;
    }

    public void remove(int index){
        Node<E> temp=head;
        int size1=0;
        boolean flag=false;

        while (true){
            if(temp.next==null){
                break;
            }
            if(size1+1==index){flag=true; break; }
            temp=temp.next;
                size1++;
        }
        if(flag==true){temp.next=temp.next.next; size--;}else {System.out.println("无法找到要删除的");}
    }

    public void add(int index, E theElement){
        Node<E> temp=head;
        Node<E> t2=new Node<>();
        t2.setO(theElement);
        t2.next=null;
        int size1=0;
        while (true){
            if(size1+1==index){
                break;
            }
            size1++;
            temp=temp.next;
        }
        //temp.setO(theElement);
        t2.next=temp.next;
        temp.next=t2;
    }

    public void add(E  element){
    Node<E> temp=head;
    Node<E> t2=new Node<>();
    t2.setO(element);
    t2.next=null;

    while (true){
        if(head==null){
            temp=t2;
        }
        if(temp.next==null){
            break;
        }
        temp=temp.next;
    }
    temp.next=t2;
    }

    public void printList(){
        Node<E> temp=head;
        int size1=0;
        while (true){
            if(temp.next==null){break;}
            temp=temp.next;
            System.out.println(temp.getO());

        }
    }

}
package 链表实现;
public interface LinearListInterface<E> {

    public boolean isEmpty();

    public int size();

    public E get(int index);

    public void remove(int index);

    public void add(int index, E theElement);

    public void add(E  element);

    public void printList();
}

 

 

双向链表的实现

 

双向链表目前所了解的功能与单向链表差不多都是用来进行对链表中的数据进行增加删除和查询的,但是双向链表与单向链表不同的是对以上功能的实现方式不同,例如在进行删除时,单向链表需要将指针指向待删除节点的前一个节点,但是双向链表却可以直接到待删除的节点进行删除,因为双向链表中的每个节点都是有两个指针域的,分别是用来连接当前节点的前一个节点和当前节点的后一个节点的,一次可以通过当前节点访问到当前节点的前一个节点,因为有两个节点的原因,所以我们在删除和增加某个节点时对链表的建立都与单向链表不一样,但是整体链表的设计理念却是一样的,并没有什么太大的不同。但是还是要注意头节点和尾节点为空的时候.

package 双向链表实现;

public class DoubleLinkedList<E> implements DoubleLinkedListImpl<E> {
    private E e;
    private Node<E> head=new Node<>();//头结点,非第一个节点

    private Node<E> curr;//当前节点

    private Node<E> tail;//最后一个节点

    private int size=0;//当前链表节点数

    public boolean isEmpty(){
        if(size==0)
    return true;
        else
            return false;
    }

    public int getSize(){
        return size;
    }

    public E getData(int index){
        Node<E> temp=head;
        int size1=0;
        boolean flag=false;
        while (true){
            if(size1==index){
                return temp.getData();
            }
            if(temp.getNext()==null){
                System.out.println("无法找到,您要查找的点");
                break;
            }
            temp=temp.getNext();
            size1++;
        }
        return e;
    }

    public void remove(){
        remove(size);

    }

    public void remove(int index){
        Node<E> temp=head;
        int num=0;
        boolean flag=true;
        while (true){
            if(temp==null) break;
            if(num==index){
                flag=false;
                break;
            }
            num++;
            temp=temp.getNext();
        }
        if(flag==false){
            temp.getPrevious().setNext(temp.getNext());
            if(temp.getNext()!=null){
            temp.getNext().setPrevious(temp.getPrevious());}
        }
    }

    public void add(int index, E theElement){
        Node<E> temp=head;
        int num=0;
        Node<E> temp1=new  Node<>();
        temp1.setData(theElement);
        while (true){
            if(head==null){
                temp=temp1;
            }
            if(num+1==index){
                break;
            }
            num++;
            //size++;
            temp=temp.getNext();
        }
        temp1.setNext(temp.getNext());
        temp.setNext(temp1);
        temp1.setPrevious(temp);
//        t2.next=temp.next;
//        temp.next=t2;
    }

    public void add(E element){
        Node<E> temp=head;
        Node<E> t2=new Node<>();
        t2.setData(element);
        t2.setNext(null);

        while (true){
            if(head==null){
                temp=t2;
            }
            if(temp.getNext()==null){
                break;
            }
            temp=temp.getNext();
        }
        size++;
        temp.setNext(t2);
        t2.setPrevious(temp);
    }

    public void printList(){
        Node<E> temp=head;
        int size1=0;
        while (true){
            if(temp.getNext()==null){break;}
            temp=temp.getNext();
            System.out.println(temp.getData());

        }
    }

    public E getFirst(){
  // getData(1);
   return getData(1);
    }

    public E getLast(){
        getData(size);
        return e;
    }

}
package 双向链表实现;

public abstract  interface  DoubleLinkedListImpl<E> {


    public boolean isEmpty();

    public int getSize();

    public E getData(int index);

    public void remove();

    public void remove(int index);

    public void add(int index, E theElement);

    public void add(E element);

    public void printList();

    public E getFirst();

    public E getLast();

}
package 双向链表实现;

import java.util.Scanner;

public class Main {
    public static void main (String[] args){
        DoubleLinkedListImpl<Integer> num=new DoubleLinkedList<>();
        num.add(50);
        num.add(60);

        num.add(70);
        while (true){
            int ch;
            System.out.println("**********************************************************");
            System.out.println("**********************-----请输入您的选择-----************************");
            System.out.println("1.删除链表的节点"+"******************************************");
            System.out.println("2.指定位置增加(输入下标和要增加的数)"+"************************");
            System.out.println("3.尾部增加(直接输入要添加的数)"+"*****************************");
            System.out.println("4.打印链表中的数"+"******************************************");
            System.out.println("5.得到节点个数"+"*******************************************");
            System.out.println("6.得到指定节点的数"+"****************************************");
            System.out.println("7.得到首节点的数"+"****************************************");
            System.out.println("8.得到尾部节点的数"+"****************************************");
            System.out.println("9.删除尾节点的数"+"****************************************");
            System.out.println("10.退出系统操作"+"*******************************************");
            System.out.println("*********************************************************");
            Scanner input=new Scanner(System.in);
            ch=input.nextInt();
            if(ch==1){
                int m;
                m=input.nextInt();
                num.remove(m);
            }
            if(ch==2){
                int m,n;
                m=input.nextInt();
                n=input.nextInt();
                num.add(m,n);
            }
            if(ch==3){
                int m;
                m=input.nextInt();
                num.add(m);
            }
            if(ch==4){
                num.printList();
            }
            if(ch==6){
                int m;
                m=input.nextInt();
                System.out.println(num.getData(m));
            }
            if(ch==5){
                //num.size();
                System.out.println(num.getSize());
            }
            if(ch==7){
//                num.getFirst();
                System.out.println( num.getFirst());
                //return;
            }
            if(ch==8){
                num.getLast();
            }
            if(ch==9){
                num.remove();
            }
            if(ch==10){
                return;
            }
        }
        //num.printList();
    }
}
package 双向链表实现;

public class Node<E> {

    private E data;//数据域,类型为泛型E

    private Node<E> next;//后继引用(指针)

    private Node<E> previous;//前驱引用(指针)

    public E getData() {
        return data;
    }

    public Node<E> getPrevious() {
        return previous;
    }

    public Node<E> getNext() {
        return next;
    }

    public void setData(E data) {
        this.data = data;
    }

    public void setNext(Node<E> next) {
        this.next = next;
    }

    public void setPrevious(Node<E> previous) {
        this.previous = previous;
    }
}

 

 图形类的设计

四边形图形类的设计

 

这道题目由于种种原因自己并没有写出来,但是感觉自己的整体的算法设计并没有太大的问题,只是自己一开始在设计应该有的类时,并没有进行过多的设计,导致整个代码的重复的代码太多,最后也因此在pta无法提交,只能删掉一部分代码才可以提交,整体代码的量个人感觉还是挺大的,当然以后再遇到这种题目时应该要注意类与类的关系,注意类的设计,当然在写这道题目时,个人感觉难度最大的还是第四小问,计算交点的面积,我们可以通过判断直线上下两部分的点的位置,依次来计算交点,然后求面积,再计算点的位置时,我们可以通过将点代入直线方程中,然后计算这个直线方程最后得到的结果是大于0,还是小于0,因为当只有两个交点时可能会出现一个点在直线上面,另外两个点在直线下方,或者是一个点在下面另外四个点在直线的上面,通过这样的判断,我们就可以确定直线是与哪两条直线相交,并且能够求道交点,最后将得到的面积用来与四边形面积乡间,最后比较大小进行输出.

 

package pta63;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        String en = "";
        int i, j, k = 0, m = 2, n = 0, t = 0, flag = 9, q = 0;
        String str, str1;
        double[] num = new double[100];
        Scanner input = new Scanner(System.in);
        en = input.nextLine();
        str = en.substring(0, 2);
        str1 = en.substring(0, en.length());
        String ssss="[12345]\\:(((\\+|-)?[0-9]({\\d})?(\\.\\d+)?\\,((\\+|-)?[0-9]({\\d})?(\\.\\d+)?\\s)(\\d)";

        String regstr = "[12345]\\:[\\+|-]?([0]|([1-9]((\\d)?)+))(\\.\\d+)?\\,([+\\-]?([0]|([1-9]((\\d)?)+)))(\\.\\d+)?(\\s([+\\-" + "]?([0]|([1-9]((\\d)?)+)))(\\.\\d+)?\\,([+\\-]?([0]|([1-9]((\\d)?)+)))(\\.\\d+)?)+";
        if (str1.matches(regstr)) {
            flag = 0;
        } else {
            flag = 1;
        }
        if(flag==1) {System.out.println("Wrong Format"); return;}
        if(str.equals("1:")){
            for(i=0;i<en.length();i++){

                if((en.charAt(i)==',')){
                    n++;
                }
                if((en.charAt(i)==' ')){
                    q++;
                }

            }
            if(n!=4) {
                System.out.println("wrong number of points");
                return;
            }
            for(i=2;i<en.length();i++){
                if(en.charAt(i)==','||en.charAt(i)==' ') {
                    num[t] = Double.parseDouble(en.substring(m, i));
                    m = i + 1;
                    t++;
                }
            }
            str1=en.substring(m,i);
            num[t]=Double.parseDouble(str1);
            double k1;
            double k2;
            if(num[0]==num[4]&&num[1]==num[5]||num[2]==num[4]&&num[3]==num[5]||num[0]==num[6]&&num[1]==num[7]||num[2]==num[6]&&num[3]==num[7]||num[0]==num[2]&&num[1]==num[3])
            {System.out.println("points coincide"); return;}
            if(num[0]!=num[2])
                k1=kk(num[0],num[1],num[2],num[3]);
            else
                k1=999999.9;
            if(num[4]!=num[6])
                k2=kk(num[4],num[5],num[6],num[7]);
            else
                k2=99999.9;
            double b1=num[1]-k1*num[0];
            double b2=num[5]-num[4]*k2;
            double len1=len(num[0],num[1],num[2],num[3]);
            double len2=len(num[4],num[5],num[6],num[7]);
            double midx=(num[0]+num[4])/2;
            double midy=(num[1]+num[5])/2;
            if(issbx(num[0],num[1],num[2],num[3],num[4],num[5],num[6],num[7])||len(num[0],num[1],midx,midy)==len(num[4],num[5],midx,midy)&&len(num[2],num[3],midx,midy)==len(num[6],num[7],midx,midy)){System.out.print("true ");}
            else System.out.print("false ");
//            if(k1==k2&&Math.abs(len1-len2)<=0.000000000000001&&Math.abs(b1-b2)<=0.0001)
            if(len(num[0],num[1],midx,midy)==len(num[4],num[5],midx,midy)&&len(num[2],num[3],midx,midy)==len(num[6],num[7],midx,midy))
                System.out.print("true");
            else System.out.print("false");
        }
        if(str.equals("2:")){
            for(i=0;i<en.length();i++){

                if((en.charAt(i)==',')){
                    n++;
                }
                if((en.charAt(i)==' ')){
                    q++;
                }

            }
            if(n!=4) {
                System.out.println("wrong number of points");
                return;
            }
            for(i=2;i<en.length();i++){
                if(en.charAt(i)==','||en.charAt(i)==' ') {
                    num[t] = Double.parseDouble(en.substring(m, i));
                    m = i + 1;
                    t++;
                }
            }
            str1=en.substring(m,i);
            num[t]=Double.parseDouble(str1);
            double k1;
            double k2;
            double k3;
            double k4;
            double midx=(num[0]+num[4])/2;
            double midy=(num[1]+num[5])/2;
            if(num[0]==num[4]&&num[1]==num[5]||num[2]==num[4]&&num[3]==num[5]||num[0]==num[6]&&num[1]==num[7]||num[2]==num[6]&&num[3]==num[7]||num[0]==num[2]&&num[1]==num[3])
            {System.out.println("points coincide"); return;}
            if(issbx(num[0],num[1],num[2],num[3],num[4],num[5],num[6],num[7])||len(num[0],num[1],midx,midy)==len(num[4],num[5],midx,midy)&&len(num[2],num[3],midx,midy)==len(num[6],num[7],midx,midy)){}
            else {System.out.print("not a quadrilateral");return;}
            if(num[2]!=num[6]){
                k3=kk(num[2],num[3],num[6],num[7]);
            }else {k3=999999.9;}
            if(num[4]!=num[0]){
                k4=kk(num[0],num[1],num[4],num[5]);
            }else {k4=999999.9;}
            if(num[0]!=num[2])
                k1=kk(num[0],num[1],num[2],num[3]);
            else
                k1=999999.9;
            if(num[4]!=num[6])
                k2=kk(num[4],num[5],num[6],num[7]);
            else
                k2=99999.9;

            if(k3==-k4&&len(num[0],num[1],midx,midy)==len(num[4],num[5],midx,midy)&&len(num[2],num[3],midx,midy)==len(num[6],num[7],midx,midy)){
                System.out.print("true ");//判断菱形
            }else {System.out.print("false ");}

            if(len(num[0],num[1],midx,midy)==len(num[4],num[5],midx,midy)&&len(num[2],num[3],midx,midy)==len(num[6],num[7],midx,midy)&&len(num[2],num[3],midx,midy)==len(num[0],num[1],midx,midy)){
                System.out.print("true ");//判断长方形
            }else {System.out.print("false ");}

            if(k3==-k4&&len(num[0],num[1],midx,midy)==len(num[4],num[5],midx,midy)&&len(num[2],num[3],midx,midy)==len(num[6],num[7],midx,midy)&&len(num[0],num[1],midx,midy)==len(num[4],num[5],midx,midy)&&len(num[2],num[3],midx,midy)==len(num[6],num[7],midx,midy)&&len(num[2],num[3],midx,midy)==len(num[0],num[1],midx,midy)){

                System.out.print("true");//判断正方形
            }else {System.out.print("false");}
        }
        if(str.equals("3:")){
            for(i=0;i<en.length();i++){

                if((en.charAt(i)==',')){
                    n++;
                }
                if((en.charAt(i)==' ')){
                    q++;
                }

            }
            if(n!=4) {
                System.out.println("wrong number of points");
                return;
            }
            for(i=2;i<en.length();i++){
                if(en.charAt(i)==','||en.charAt(i)==' ') {
                    num[t] = Double.parseDouble(en.substring(m, i));
                    m = i + 1;
                    t++;
                }
            }
            str1=en.substring(m,i);
            num[t]=Double.parseDouble(str1);
            double midx=(num[0]+num[4])/2;
            double midy=(num[1]+num[5])/2;
            double z1,z2,z3,z4;
            double k1;
            double k2;
            double k3;
            double k4;
            if(num[0]==num[4]&&num[1]==num[5]||num[2]==num[4]&&num[3]==num[5]||num[0]==num[6]&&num[1]==num[7]||num[2]==num[6]&&num[3]==num[7]||num[0]==num[2]&&num[1]==num[3])
            {System.out.println("points coincide"); return;}
            if(issbx(num[0],num[1],num[2],num[3],num[4],num[5],num[6],num[7])||len(num[0],num[1],midx,midy)==len(num[4],num[5],midx,midy)&&len(num[2],num[3],midx,midy)==len(num[6],num[7],midx,midy)){}
            else {System.out.print("not a quadrilateral");return;}
            if(num[2]!=num[6]){
                k3=kk(num[2],num[3],num[6],num[7]);
            }else {k3=999999.9;}
            if(num[4]!=num[0]){
                k4=kk(num[0],num[1],num[4],num[5]);
            }else {k4=999999.9;}
            if(num[0]!=num[2])
                k1=kk(num[0],num[1],num[2],num[3]);
            else
                k1=999999.9;
            if(num[4]!=num[6])
                k2=kk(num[4],num[5],num[6],num[7]);
            else
                k2=99999.9;
            double b1=num[1]-k1*num[0];
            double b2=num[5]-num[4]*k2;
            double len1=len(num[0],num[1],num[2],num[3]);
            double len7=len(num[0],num[1],num[6],num[7]);
            double len8=len(num[4],num[5],num[2],num[3]);
            double len2=len(num[4],num[5],num[6],num[7]);
            double len3=len(num[2],num[3],num[6],num[7]);
            double len4=len(num[0],num[1],num[4],num[5]);
            double kdj1=kk(num[0],num[1],num[4],num[5]);
            double kdj2=kk(num[2],num[3],num[6],num[7]);
            double bdj1=kdj1*num[0]-num[1];
            double bdj2=kdj2*num[2]-num[3];
            double len5=Math.abs(kdj2*num[0]+bdj2-num[1])/(Math.sqrt(1+kdj2*kdj2));
            double len6=Math.abs(kdj2*num[4]+bdj2-num[5])/(Math.sqrt(1+kdj2*kdj2));
            double s;
            double sss1=sss(num[0],num[1],num[2],num[3],num[4],num[5])+sss(num[4],num[5],num[6],num[7],num[0],num[1]);
            double sss0=sss(num[2],num[3],num[4],num[5],num[6],num[7])+sss(num[6],num[7],num[0],num[1],num[2],num[3]);

            s=Math.min(sss1,sss0);
            double c=len1+len2+len7+len8;

            String str_d = String.valueOf(s);
            str_d = str_d.substring(str_d.indexOf(".") + 1);
            int len = str_d.length();
            len = len > 3 ? 3 : len;
            String area1 = String.format("%."+len+"f", s);
            String str_d1 = String.valueOf(c);
            str_d1 = str_d1.substring(str_d1.indexOf(".") + 1);
            int len11 = str_d1.length();
            len11 = len11 > 3 ? 3 : len11;
            String area11 = String.format("%."+len11+"f", c);


            if(Math.abs(sss1-sss0)<=0.1){
                System.out.println("true "+area11+" "+area1);
            }else {
                System.out.println("false "+area11+" "+area1);
            }
        }
        if(str.equals("4:")){
            for(i=0;i<en.length();i++){

                if((en.charAt(i)==',')){
                    n++;
                }
                if((en.charAt(i)==' ')){
                    q++;
                }

            }
            if(n!=6) {
                System.out.println("wrong number of points");
                return;
            }
            for(i=2;i<en.length();i++){
                if(en.charAt(i)==','||en.charAt(i)==' ') {
                    num[t] = Double.parseDouble(en.substring(m, i));
                    m = i + 1;
                    t++;
                }
            }
            str1=en.substring(m,i);
            num[t]=Double.parseDouble(str1);
            if(Cross1(num[0],num[1],num[2],num[3],num[4],num[5])<0&&Cross1(num[0],num[1],num[2],num[3],num[6],num[7])>0&&Cross1(num[0],num[1],num[2],num[3],num[8],num[9])>0&&Cross1(num[0],num[1],num[2],num[3],num[10],num[11])>=0||Cross1(num[0],num[1],num[2],num[3],num[4],num[5])>0&&Cross1(num[0],num[1],num[2],num[3],num[6],num[7])<0&&Cross1(num[0],num[1],num[2],num[3],num[8],num[9])<0&&Cross1(num[0],num[1],num[2],num[3],num[10],num[11])<=0){
                double x0= CrossX1(num[0],num[1],num[2],num[3],num[4],num[5],num[6],num[7]);
               double y0=CrossY1(num[0],num[1],num[2],num[3],num[4],num[5],num[6],num[7]);
            System.out.println(x0+" "+y0);
                double x1= CrossX1(num[0],num[1],num[2],num[3],num[8],num[9],num[10],num[11]);
                double y1=CrossY1(num[0],num[1],num[2],num[3],num[8],num[9],num[10],num[11]);
                double ssjx=sss(x0,y0,x1,y1,num[4],num[5]);
                double sss1=sss(num[4],num[5],num[6],num[7],num[8],num[9])+sss(num[8],num[9],num[10],num[11],num[4],num[5]);
                double sss0=sss(num[6],num[7],num[8],num[9],num[10],num[11])+sss(num[10],num[11],num[4],num[5],num[6],num[7]);
                double smin=Math.min(ssjx-Math.min(sss1,sss0),ssjx);
                double smax=Math.max(ssjx-Math.min(sss1,sss0),ssjx);
                String str_d = String.valueOf(smin);
                str_d = str_d.substring(str_d.indexOf(".") + 1);
                int len = str_d.length();
                len = len > 3 ? 3 : len;
                String area1 = String.format("%."+len+"f", smin);
                String str_d1 = String.valueOf(smax);
                str_d1 = str_d1.substring(str_d1.indexOf(".") + 1);
                int len11 = str_d1.length();
                len11 = len11 > 3 ? 3 : len11;
                String area11 = String.format("%."+len11+"f", smax);
                System.out.println(area1+" "+area11);
            }
            if(Cross1(num[0],num[1],num[2],num[3],num[4],num[5])>0&&Cross1(num[0],num[1],num[2],num[3],num[6],num[7])<0&&Cross1(num[0],num[1],num[2],num[3],num[8],num[9])>0&&Cross1(num[0],num[1],num[2],num[3],num[10],num[11])>=0||Cross1(num[0],num[1],num[2],num[3],num[4],num[5])<0&&Cross1(num[0],num[1],num[2],num[3],num[6],num[7])>0&&Cross1(num[0],num[1],num[2],num[3],num[8],num[9])<0&&Cross1(num[0],num[1],num[2],num[3],num[10],num[11])<=0) {
                double x0= CrossX1(num[0],num[1],num[2],num[3],num[4],num[5],num[6],num[7]);
                double y0=CrossY1(num[0],num[1],num[2],num[3],num[4],num[5],num[6],num[7]);
                System.out.println(x0+" "+y0);
                double x1= CrossX1(num[0],num[1],num[2],num[3],num[8],num[9],num[6],num[7]);
                double y1=CrossY1(num[0],num[1],num[2],num[3],num[8],num[9],num[6],num[7]);
                double ssjx=sss(x0,y0,x1,y1,num[6],num[7]);
                double sss1=sss(num[4],num[5],num[6],num[7],num[8],num[9])+sss(num[8],num[9],num[10],num[11],num[4],num[5]);
                double sss0=sss(num[6],num[7],num[8],num[9],num[10],num[11])+sss(num[10],num[11],num[4],num[5],num[6],num[7]);
                double smin=Math.min(ssjx-Math.min(sss1,sss0),ssjx);
                double smax=Math.max(ssjx-Math.min(sss1,sss0),ssjx);
                String str_d = String.valueOf(smin);
                str_d = str_d.substring(str_d.indexOf(".") + 1);
                int len = str_d.length();
                len = len > 3 ? 3 : len;
                String area1 = String.format("%."+len+"f", smin);
                String str_d1 = String.valueOf(smax);
                str_d1 = str_d1.substring(str_d1.indexOf(".") + 1);
                int len11 = str_d1.length();
                len11 = len11 > 3 ? 3 : len11;
                String area11 = String.format("%."+len11+"f", smax);
                System.out.println(area1+" "+area11);
            }
            if(Cross1(num[0],num[1],num[2],num[3],num[4],num[5])>0&&Cross1(num[0],num[1],num[2],num[3],num[6],num[7])>0&&Cross1(num[0],num[1],num[2],num[3],num[8],num[9])<0&&Cross1(num[0],num[1],num[2],num[3],num[10],num[11])>=0||Cross1(num[0],num[1],num[2],num[3],num[4],num[5])<0&&Cross1(num[0],num[1],num[2],num[3],num[6],num[7])<0&&Cross1(num[0],num[1],num[2],num[3],num[8],num[9])>0&&Cross1(num[0],num[1],num[2],num[3],num[10],num[11])<=0) {
                double x0= CrossX1(num[0],num[1],num[2],num[3],num[8],num[9],num[6],num[7]);
                double y0=CrossY1(num[0],num[1],num[2],num[3],num[8],num[9],num[6],num[7]);
                System.out.println(x0+" "+y0);
                double x1= CrossX1(num[0],num[1],num[2],num[3],num[8],num[9],num[10],num[11]);
                double y1=CrossY1(num[0],num[1],num[2],num[3],num[8],num[9],num[10],num[11]);
                double ssjx=sss(x0,y0,x1,y1,num[8],num[9]);
                double sss1=sss(num[4],num[5],num[6],num[7],num[8],num[9])+sss(num[8],num[9],num[10],num[11],num[4],num[5]);
                double sss0=sss(num[6],num[7],num[8],num[9],num[10],num[11])+sss(num[10],num[11],num[4],num[5],num[6],num[7]);
                double smin=Math.min(ssjx-Math.min(sss1,sss0),ssjx);
                double smax=Math.max(ssjx-Math.min(sss1,sss0),ssjx);
                String str_d = String.valueOf(smin);
                str_d = str_d.substring(str_d.indexOf(".") + 1);
                int len = str_d.length();
                len = len > 3 ? 3 : len;
                String area1 = String.format("%."+len+"f", smin);
                String str_d1 = String.valueOf(smax);
                str_d1 = str_d1.substring(str_d1.indexOf(".") + 1);
                int len11 = str_d1.length();
                len11 = len11 > 3 ? 3 : len11;
                String area11 = String.format("%."+len11+"f", smax);
                System.out.println(area1+" "+area11);
            }
            if(Cross1(num[0],num[1],num[2],num[3],num[4],num[5])>0&&Cross1(num[0],num[1],num[2],num[3],num[6],num[7])>0&&Cross1(num[0],num[1],num[2],num[3],num[8],num[9])>0&&Cross1(num[0],num[1],num[2],num[3],num[10],num[11])<=0||Cross1(num[0],num[1],num[2],num[3],num[4],num[5])<0&&Cross1(num[0],num[1],num[2],num[3],num[6],num[7])<0&&Cross1(num[0],num[1],num[2],num[3],num[8],num[9])<0&&Cross1(num[0],num[1],num[2],num[3],num[10],num[11])>=0) {
                double x0= CrossX1(num[0],num[1],num[2],num[3],num[8],num[9],num[10],num[11]);
                double y0=CrossY1(num[0],num[1],num[2],num[3],num[8],num[9],num[10],num[11]);
                System.out.println(x0+" "+y0);
                double x1= CrossX1(num[0],num[1],num[2],num[3],num[4],num[5],num[10],num[11]);
                double y1=CrossY1(num[0],num[1],num[2],num[3],num[4],num[5],num[10],num[11]);
                double ssjx=sss(x0,y0,x1,y1,num[10],num[11]);
                double sss1=sss(num[4],num[5],num[6],num[7],num[8],num[9])+sss(num[8],num[9],num[10],num[11],num[4],num[5]);
                double sss0=sss(num[6],num[7],num[8],num[9],num[10],num[11])+sss(num[10],num[11],num[4],num[5],num[6],num[7]);
                double smin=Math.min(ssjx-Math.min(sss1,sss0),ssjx);
                double smax=Math.max(ssjx-Math.min(sss1,sss0),ssjx);
                String str_d = String.valueOf(smin);
                str_d = str_d.substring(str_d.indexOf(".") + 1);
                int len = str_d.length();
                len = len > 3 ? 3 : len;
                String area1 = String.format("%."+len+"f", smin);
                String str_d1 = String.valueOf(smax);
                str_d1 = str_d1.substring(str_d1.indexOf(".") + 1);
                int len11 = str_d1.length();
                len11 = len11 > 3 ? 3 : len11;
                String area11 = String.format("%."+len11+"f", smax);
                System.out.println(area1+" "+area11);
            }
            if(Cross1(num[0],num[1],num[2],num[3],num[4],num[5])>0&&Cross1(num[0],num[1],num[2],num[3],num[6],num[7])>0&&Cross1(num[0],num[1],num[2],num[3],num[8],num[9])<0&&Cross1(num[0],num[1],num[2],num[3],num[10],num[11])<=0||Cross1(num[0],num[1],num[2],num[3],num[4],num[5])<0&&Cross1(num[0],num[1],num[2],num[3],num[6],num[7])<0&&Cross1(num[0],num[1],num[2],num[3],num[8],num[9])>0&&Cross1(num[0],num[1],num[2],num[3],num[10],num[11])>=0) {
                double x0= CrossX1(num[0],num[1],num[2],num[3],num[8],num[9],num[10],num[11]);
                double y0=CrossY1(num[0],num[1],num[2],num[3],num[8],num[9],num[10],num[11]);
                System.out.println(x0+" "+y0);
                double x1= CrossX1(num[0],num[1],num[2],num[3],num[4],num[5],num[10],num[11]);
                double y1=CrossY1(num[0],num[1],num[2],num[3],num[4],num[5],num[10],num[11]);
                double ssjx=sss(x0,y0,x1,y1,num[10],num[11]);
                double sss1=sss(num[4],num[5],num[6],num[7],num[8],num[9])+sss(num[8],num[9],num[10],num[11],num[4],num[5]);
                double sss0=sss(num[6],num[7],num[8],num[9],num[10],num[11])+sss(num[10],num[11],num[4],num[5],num[6],num[7]);
                double smin=Math.min(ssjx-Math.min(sss1,sss0),ssjx);
                double smax=Math.max(ssjx-Math.min(sss1,sss0),ssjx);
                String str_d = String.valueOf(smin);
                str_d = str_d.substring(str_d.indexOf(".") + 1);
                int len = str_d.length();
                len = len > 3 ? 3 : len;
                String area1 = String.format("%."+len+"f", smin);
                String str_d1 = String.valueOf(smax);
                str_d1 = str_d1.substring(str_d1.indexOf(".") + 1);
                int len11 = str_d1.length();
                len11 = len11 > 3 ? 3 : len11;
                String area11 = String.format("%."+len11+"f", smax);
                System.out.println(area1+" "+area11);
            }

            }
        if(str.equals("5:")){
            for(i=0;i<en.length();i++){

                if((en.charAt(i)==',')){
                    n++;
                }
                if((en.charAt(i)==' ')){
                    q++;
                }

            }
            if(n!=4) {
                System.out.println("wrong number of points");
                return;
            }
            for(i=2;i<en.length();i++){
                if(en.charAt(i)==','||en.charAt(i)==' ') {
                    num[t] = Double.parseDouble(en.substring(m, i));
                    m = i + 1;
                    t++;
                }
            }
            str1=en.substring(m,i);
            num[t]=Double.parseDouble(str1);
            if(issbx(num[8],num[9],num[2],num[3],num[4],num[5],num[6],num[7])){
                if(Cross(num[0],num[1],num[2],num[3],num[4],num[5])==0||Cross(num[0],num[1],num[6],num[7],num[4],num[5])==0||Cross(num[0],num[1],num[2],num[3],num[8],num[9])==0){System.out.println("on the quadrilateral");return;}
                if(Cross(num[0],num[1],num[2],num[3],num[4],num[5])<0&&Cross(num[0],num[1],num[8],num[9],num[6],num[7])>0||Cross(num[0],num[1],num[2],num[3],num[4],num[5])>0&&Cross(num[0],num[1],num[8],num[9],num[6],num[7])<0){System.out.println("in the quadrilateral");return;}
                System.out.println("in the quadrilateral");
            }else {System.out.println("in the triangle");}

        }
    }
    public static double kk(double x1,double y1,double x2,double y2){
        // return Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));

            return (y1-y2)/(x1-x2);

    }
    public static double len(double x1,double y1,double x2,double y2){
        return Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));
    }
    public static boolean issbx(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4){
        if((y4-y3)*(x4-x2)==(y4-y2)*(x4-x3)){return false;}
        if((y4-y2)*(x4-x1)==(y4-y1)*(x4-x2)){return false;}
        if((y4-y3)*(x4-x1)==(y4-y1)*(x4-x3)){return false;}
        if((y3-y2)*(x3-x1)==(y3-y1)*(x3-x2)){return false;}
        return true;
    }
    public static boolean issjx(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4){
        if(x1==x2&&y1==y2&&x1!=x3&&y1!=y3&&x1!=x4&&y1!=y4&&x2!=x3&&y2!=y3&&x2!=x4&&y2!=y4&&x4!=x3&&y4!=y3) return true;
        if(x1!=x2&&y1!=y2&&x1==x3&&y1==y3&&x1!=x4&&y1!=y4&&x2!=x3&&y2!=y3&&x2!=x4&&y2!=y4&&x4!=x3&&y4!=y3) return true;
        if(x1!=x2&&y1!=y2&&x1!=x3&&y1!=y3&&x1==x4&&y1==y4&&x2!=x3&&y2!=y3&&x2!=x4&&y2!=y4&&x4!=x3&&y4!=y3) return true;
        if(x1!=x2&&y1!=y2&&x1!=x3&&y1!=y3&&x1!=x4&&y1!=y4&&x2==x3&&y2==y3&&x2!=x4&&y2!=y4&&x4!=x3&&y4!=y3) return true;
        if(x1!=x2&&y1!=y2&&x1!=x3&&y1!=y3&&x1!=x4&&y1!=y4&&x2!=x3&&y2!=y3&&x2==x4&&y2==y4&&x4!=x3&&y4!=y3) return true;
        if(x1!=x2&&y1!=y2&&x1!=x3&&y1!=y3&&x1!=x4&&y1!=y4&&x2!=x3&&y2!=y3&&x2!=x4&&y2!=y4&&x4==x3&&y4==y3) return true;
        return false;
    }
    public static boolean istu(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4){
        double z1,z2,z3,z4;
        z1 = ((x2 - x1) * (y4 - y1) - (x4 - x1) * (y2 - y1));

        z2 = ((x4 - x1) * (y3 - y1) - (x3 - x1) * (y4 - y1));

        z3 = ((x4 - x2) * (y3 - y2) - (x3 - x2) * (y4 - y2));

        z4 = ((x3 - x2) * (y1 - y2) - (x1 - x2) * (y3 - y2));

        return (z1 * z2 > 0) && (z3 * z4 > 0);

    }

    public static double sss(double x1,double y1,double x2,double y2,double x3,double y3){
        return Math.abs((x1 * y2 + x2 * y3 + x3 * y1 - x2 * y1 - x3 * y2 - x1 * y3) / 2.0);
    }
    
    public static  double Cross(double x1,double y1,double x2,double y2,double x3,double y3)
        {
            double k1=0.0;
            double b1=0.0;


                k1=kk( x1, y1, x2, y2);
                b1=k1*x1-y1;
                return k1*x3+b1-y3;

        }
    public static  double Cross1(double x1,double y1,double x2,double y2,double x3,double y3)
    {
        double k1=0.0;
        double b1=0.0;
        double k2=0.0;
        double b2=0.0;
        int book=0;
        int flag=0;

            k1=kk( x1, y1, x2, y2);
            b1=k1*x1-y1;
            double m=(k1*x3+b1-y3);
           // System.out.println(x3+" "+y3);
           return (k1*x3+b1-y3);
       // return (x1-x3)*(y2-y3)-(y1-y3)*(x2-x3) ;//x3和y3位于直线的那一侧
    }
    public static  double CrossX1(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4) {
        double k1=0.0;
        double b1=0.0;
        double k2=0.0;
        double b2=0.0;
        int book=0;
        int flag=0;

        if(x1!=x2){
        k1=kk( x1, y1, x2, y2);
        b1=k1*x1-y1;
        flag=1;}
        if(x3!=x4){

        k2=kk( x3, y3, x4, y4);
        b2=k2*x2-y2;book=1;}
        if(book==1&&flag==1){
        return (b2-b1)/(k1-k2);}
        if(book==0&&flag==1){
            return x2;
        }
        if(book==1&&flag==0){
            return x1;
        }
        return 0.0;

    }
    public static  double CrossY1(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4) {
        double k1=0.0;
        double b1=0.0;
        double k2=0.0;
        double b2=0.0;
        int book=0;
        int flag=0;
        if(x1!=x2){
            k1=kk( x1, y1, x2, y2);
            b1=k1*x1-y1;
            flag=1;}
        if(x3!=x4){
            k2=kk( x3, y3, x4, y4);
            b2=k2*x2-y2;book=1;}
        if(book==1&&flag==1){
            return k1*((b2-b1)/(k1-k2))+b1;}
        if(book==0&&flag==1){
            return k2*x2+b2;
        }
      return k1*x1+b1;

    }
}