第二次博客作业

发布时间:2022-06-08 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了第二次博客作业脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
  • 前言
  • 设计与分析
  • 踩坑心得
  • 改进建议
  • 总结
  • 前言:

 我认为这几次pta的图形类设计的题目,难度系数对我来说还是比较高的,

主要不是难在对类的构造以及搭建上面,主要是难在一些测试点上,因为能力有限,

所以很多测试点不知道为什么没有通过,盲目的寻找很难发现自己究竟犯了什么错。

超星中链表类练习题目对我来说难度还是比较适中的,毕竟这是老师在课堂上讲过的题目,

而且主题框架已经跟我们打好了,特别是第2次双向链表的练习,

基本上主体框架已经不需要我们再去钻研,我们只需要考虑对前节点的连接和后节点的继承问题。

对于期中考试,我认为非常的失败,通过本次期中考试,我也发现了我自己很多的不足之处。

首先就是我的编码速度实在是太慢了,导致连题目都没有写完,然后我对题目的理解包括审题能力也有待提高,因为在第一题的时候看错了条件,导致浪费了大量时间,以至于影响了后面的编码心态。

前面所有的练习所涉及到的知识点主要包括继承,多态以及接口和一点点范型。

题量不大,但是都很精髓

 

  • 设计与分析:

 题目集04----2

第二次博客作业

 

 从提交列表可以明显看出,正常计算的测试点都能通过,但是格式错误一直没有办法解决,

这说明我在字符串的处理方面还是比较欠缺的,这是我的一大漏洞。

  1 import java.util.Scanner;
  2 
  3 public class Main {
  4     public static void main(String[] @R_126_2604@s) {
  5         Scanner input = new Scanner(System.in);
  6         String str;
  7         String[] str1;
  8         String[] str2;
  9         String[] str3;
 10         String[] str4;
 11         String[] str5;
 12         String[] str6;
 13         int t=0;
 14         str = input.nextLine();
 15         for(int i=0;i<str.length();i++) {
 16             if(str.charAt(i)==':') {
 17                 t=0;
 18                 break;
 19             }else {
 20                 t=1;
 21             }
 22         }
 23         if(t==1) {
 24             System.out.PRintln("Wrong Format");
 25             System.exIT(0);
 26         }
 27         str1=str.split(":");
 28         for(int i=0;i<str.length();i++) {
 29             if(str.charAt(i)==' ') {
 30                 t=0;
 31                 break;
 32             }else {
 33                 t=1;
 34             }
 35         }
 36         if(t==1) {
 37             System.out.println("Wrong Format");
 38             System.exit(0);
 39         }
 40         str2=str1[1].split(" ");
 41         str3=str2[0].split(",");
 42         str4=str2[1].split(",");
 43 
 44         double x1 = Double.parseDouble(str3[0]);
 45         double x2 = Double.parseDouble(str4[0]);
 46         double y1 = Double.parseDouble(str3[1]);
 47         double y2 = Double.parseDouble(str4[1]);
 48 
 49         if(str.charAt(0)=='1') {
 50             if(str2.length<=2) {
 51                 double k = (y1-y2)/(x1-x2);
 52                 if(x1==x2&&y1==y2) {
 53                     System.out.println("points coincide");
 54                 }else if(x1==x2) {
 55                     System.out.println("SloPE does not exist");
 56                 }else {
 57                     System.out.println(k);
 58                 }
 59             }else {
 60                 System.out.println("wrong number of points");
 61             }
 62         }
 63         if(str.charAt(0)=='2') {
 64             if(str2.length==3) {
 65                 str5=str2[2].split(",");
 66                 double x3 = Double.parseDouble(str5[0]);
 67                 double y3 = Double.parseDouble(str5[1]);
 68                 double result =Math.abs((y2-y3)*x1+(x3-x2)*y1+x2*y3-y2*x3)/Math.sqrt((y2-y3)*(y2-y3) +(x2-x3)*(x2-x3));
 69                 if(x3==x2&amp;&y3==y2) {
 70                     System.out.println("points coincide");
 71                 }else
 72                     System.out.println(result);
 73             }else {
 74                 System.out.println("wrong number of points");
 75             }
 76         }
 77         if(str.charAt(0)=='3') {
 78             if(str2.length==3) {
 79                 str5=str2[2].split(",");
 80                 double x3 = Double.parseDouble(str5[0]);
 81                 double y3 = Double.parseDouble(str5[1]);
 82                 double result =Math.abs((y2-y3)*x1+(x3-x2)*y1+x2*y3-y2*x3)/Math.sqrt((y2-y3)*(y2-y3) +(x2-x3)*(x2-x3));
 83                 if(x3==x2&&y3==y2||x1==x2&&y1==y2||x1==x3&&y1==y3) {
 84                     System.out.println("points coincide");
 85                 }
 86                 else if(result == 0){
 87                     System.out.println("true");
 88                 }
 89                 else
 90                     System.out.println("false");
 91             }
 92             else {
 93                 System.out.println("wrong number of points");
 94             }
 95         }
 96         if(str.charAt(0)=='4') {
 97             if(str2.length==4) {
 98                 str5=str2[2].split(",");
 99                 str6=str2[3].split(",");
100                 double x3 = Double.parseDouble(str5[0]);
101                 double y3 = Double.parseDouble(str5[1]);
102                 double x4 = Double.parseDouble(str6[0]);
103                 double y4 = Double.parseDouble(str6[1]);
104                 double k = (y1-y2)/(x1-x2);
105                 double k1 = (y4-y3)/(x4-x3);
106                 if((x1==x2&&y1==y2)||(x3==x4&&y3==y4)){
107                     System.out.println("points coincide");
108                 }
109                 else if(k==k1||x1==x2&&x2==x3&&x3==x4)
110                     System.out.println("true");
111                 else
112                     System.out.println("false");
113             }else {
114                 System.out.println("wrong number of points");
115             }
116         }
117         if(str.charAt(0)=='5') {
118             if(str2.length==4) {
119                 str5=str2[2].split(",");
120                 str6=str2[3].split(",");
121                 double x3 = Double.parseDouble(str5[0]);
122                 double y3 = Double.parseDouble(str5[1]);
123                 double x4 = Double.parseDouble(str6[0]);
124                 double y4 = Double.parseDouble(str6[1]);
125                 double max1;
126                 double max2;
127                 double max3;
128                 double max4;
129                 double min1;
130                 double min2;
131                 double min3;
132                 double min4;
133                 if(x1 > x2){
134                     max1 = x1;
135                     min1 = x2;
136                 }
137                 else{
138                     max1 = x2;
139                     min1 = x1;
140                 }
141 
142                 if(x3 > x4){
143                     max2 = x3;
144                     min2 = x4;
145                 }
146                 else{
147                     max2 = x4;
148                     min2 = x3;
149                 }
150 
151                 if(y1 > y2){
152                     max3 = y1;
153                     min3 = y2;
154                 }
155                 else{
156                     max3 = y2;
157                     min3 = y1;
158                 }
159 
160                 if(y3 > y4){
161                     max4 = y3;
162                     min4 = y4;
163                 }
164                 else{
165                     max4 = y4;
166                     min4 = y3;
167                 }
168 
169                 double k1 = (y1-y2)/(x1-x2);
170                 double k2 = (y4-y3)/(x4-x3);
171                 double b1 = y1-k1*x1;
172                 double b2 = y3-k2*x3;
173                 float xj = (float) ((float)-(b2-b1)/(k2-k1));
174                 float yj = (float) ((float)k1*xj+b1);
175                 if(x1==x2&&y1==y2||x3==x4&&y3==y4) {
176                     System.out.println("points coincide");
177                 }else if(k1==k2||x1==x2&&x2==x3&&x3==x4)
178                     System.out.println("is parallel lines,have no intersection point");
179                 else if(xj > min1 && xj < max1 && yj > min3 && yj < max3||xj > min2 && xj < max2 && yj > min4 && yj < max4)
180                     System.out.println(xj+","+yj+" true");
181                 else
182                     System.out.println(xj+","+yj+" false");
183             }
184             else {
185                 System.out.println("wrong number of points");
186             }
187         }
188     }
189 }

题目集04----3

第二次博客作业

 

 该题跟上一题也是一样的,其余问题基本都能处理,但唯独格式错误一直无法解决,

这说明我在字符串处理方面还有很大的进步空间

  1 import java.text.DecimalFormat;
  2 import java.util.Scanner;
  3 
  4 public class  Main {
  5 
  6     public static void main(String[] args) {
  7         Scanner input =new Scanner(System.in);
  8         String str;
  9         String[] str1;
 10         String[] str2;
 11         String[] str3;
 12         String[] str4;
 13         String[] str5;
 14         String[] str6;
 15         int t=0;
 16         str=input.nextLine();
 17         for(int i=0;i<str.length();i++) {
 18             if(str.charAt(i)==':') {
 19                 t=0;
 20                 break;
 21             }else {
 22                 t=1;
 23             }
 24         }
 25         if(t==1) {
 26             System.out.println("Wrong Format");
 27             System.exit(0);
 28         }
 29         str1=str.split(":");
 30         str2=str1[1].split(" ");
 31         str3=str2[0].split(",");
 32         str4=str2[1].split(",");
 33 
 34         double x1 = Double.parseDouble(str3[0]);
 35         double y1 = Double.parseDouble(str3[1]);
 36         double x2 = Double.parseDouble(str4[0]);
 37         double y2 = Double.parseDouble(str4[1]);
 38         str5=str2[2].split(",");
 39         double x3 = Double.parseDouble(str5[0]);
 40         double y3 = Double.parseDouble(str5[1]);
 41         double result =Math.abs((y2-y3)*x1+(x3-x2)*y1+x2*y3-y2*x3)/Math.sqrt((y2-y3)*(y2-y3) +(x2-x3)*(x2-x3));
 42         if(result==0) {
 43             System.out.println("data error");
 44             System.exit(0);
 45         }
 46         if((x1==x2&&y1==y2)||(x1==x3&&y1==y3)||(x3==x2&&y3==y2)) {
 47             System.out.println("points coincide");
 48             System.exit(0);
 49         }
 50         double sqrt = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
 51         double v = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3);
 52         if(str.charAt(0)=='1') {
 53             if(str2.length==3) {
 54                 if(str3.length==2&&str4.length==2&&str5.length==2) {
 55                     double l2 = Math.sqrt(v);
 56                     double l3 = Math.sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
 57                     if( sqrt + l2 > l3 && sqrt + l3 > l2 && l2 + l3 > sqrt) {
 58                         if(sqrt ==l2|| sqrt ==l3||l2==l3) {
 59                             if(sqrt ==l2&&l2==l3) {
 60                                 System.out.println("true true");
 61                             }else {
 62                                 System.out.println("true false");
 63                             }
 64                         }
 65                         else {
 66                             System.out.println("false false");
 67                         }
 68 
 69                     }else {
 70                         System.out.println("data error");
 71                     }
 72                 }else {
 73                     System.out.println("Wrong Format");
 74                 }
 75             }else {
 76                 System.out.println("wrong number of points");
 77             }
 78         }
 79         if(str.charAt(0)=='2') {
 80             if(str2.length==3) {
 81                 if(str3.length==2&&str4.length==2&&str5.length==2) {
 82                     double l2 = Math.sqrt(v);
 83                     double l3 = Math.sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
 84                     double c = (sqrt +l2+l3);
 85                     double p = (sqrt +l2+l3)/2;
 86                     double s = Math.sqrt(p*(p- sqrt)*(p-l2)*(p-l3));
 87                     double xj = (sqrt +l2+l3)/3;
 88                     double yj = (sqrt +l2+l3)/3;
 89                     String str_d = String.valueOf(xj);
 90                     for(int i=0;i<str_d.length();i++) {
 91                         if(str_d.charAt(i)=='.') {
 92                             break;
 93                         }
 94                     }
 95                     new DecimalFormat("0.000000").format(xj);
 96                     if( sqrt + l2 > l3 && sqrt + l3 > l2 && l2 + l3 > sqrt) {
 97                         System.out.println(c+" "+s+" "+xj+","+yj);
 98                     }else {
 99                         System.out.println("data error");
100                     }
101                 }else {
102                     System.out.println("Wrong Format");
103                 }
104             }else {
105                 System.out.println("wrong number of points");
106             }
107         }
108         if(str.charAt(0)=='3') {
109             if(str2.length==3) {
110                 if(str3.length==2&&str4.length==2&&str5.length==2) {
111                     double l2 = Math.sqrt(v);
112                     double l3 = Math.sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
113                     if( sqrt + l2 > l3 && sqrt + l3 > l2 && l2 + l3 > sqrt) {
114                         if((sqrt * sqrt +l2*l2-l3*l3)<1e-16||(sqrt * sqrt +l3*l3-l2*l2)<1e-16||(l2*l2+l3*l3- sqrt * sqrt)<1e-16) {
115                             System.out.println("false true false");
116                         } if((sqrt * sqrt +l2*l2<l3*l3)||(sqrt * sqrt +l3*l3<l2*l2)||(l2*l2+l3*l3< sqrt * sqrt)) {
117                             System.out.println("true false false");
118                         } if((sqrt * sqrt +l2*l2>l3*l3)&&(sqrt * sqrt +l3*l3>l2*l2)&&(l2*l2+l3*l3> sqrt * sqrt)) {
119                             System.out.println( "false false true");
120                         }
121                     }else {
122                         System.out.println("data error");
123                     }
124 
125                 }else {
126                     System.out.println("Wrong Format");
127                 }
128 
129             }else {
130                 System.out.println("wrong number of points");
131             }
132         }
133         if(str.charAt(0)=='4') {
134             if(str2.length==4) {
135                 str6=str2[3].split(",");
136                 double x4 = Double.parseDouble(str6[0]);
137                 double y4 = Double.parseDouble(str6[1]);
138                 double k = (y1-y2)/(x1-x2);
139                 double k1 = (y4-y3)/(x4-x3);
140                 if(x3 == x4 && y3 == y4){
141                     System.out.println("points coincide");
142                 }
143                 else if(k==k1)
144                     System.out.println("true");
145                 else
146                     System.out.println("false");
147             }else {
148                 System.out.println("wrong number of points");
149             }
150         }
151         if(str.charAt(0)=='5') {
152             if(str2.length==4) {
153                 str6=str2[3].split(",");
154                 double x4 = Double.parseDouble(str6[0]);
155                 double y4 = Double.parseDouble(str6[1]);
156                 double k1 = (y1-y2)/(x1-x2);
157                 double k2 = (y4-y3)/(x4-x3);
158                 double b1 = y1-k1*x1;
159                 double b2 = y3-k2*x3;
160                 double xj = -(b2-b1)/(k2-k1);
161                 double yj = k1*xj+b1;
162                 if(k1==k2)
163                     System.out.println("is parallel lines,have no intersection point");
164                 else if(yj==k1*xj+b1||yj==k2*xj+b2)
165                     System.out.println(xj+","+yj+" true");
166                 else
167                     System.out.println(xj+","+yj+" false");
168             }else {
169                 System.out.println("wrong number of points");
170             }
171         }
172     }
173 }

 

 双向链表

  1 package LinkedList;
  2 
  3 import java.util.NoSuchElementException;
  4 public class DoubleLinkedList<E> implements DoubleLinkedListImpl<E> {
  5 
  6     private Node<E> head;//头结点,非第一个节点
  7 
  8     private Node<E> curr;//当前节点
  9 
 10     private Node<E> tail;//最后一个节点
 11 
 12     private int size;//当前链表节点数
 13 
 14 
 15     @override
 16     public boolean iSEMpty() {
 17         return this.size <= 0;
 18     }
 19 
 20     @Override
 21     public int getSize() {
 22         return this.size;
 23     }
 24 
 25     private Node node(int index) {
 26         if (index >= this.size)
 27             return null;
 28         int len = this.size;
 29         if (index < len) {
 30             if (index > len / 2) {
 31                 Node curr = tail;
 32                 int step = len - index - 1;
 33                 while (step-- > 0) {
 34                     curr = curr.previous;
 35                 }
 36                 return curr;
 37             } else {
 38                 Node curr = head;
 39                 int step = index;
 40                 while (step-- > 0) {
 41                     curr = curr.next;
 42                 }
 43                 return curr;
 44             }
 45         }
 46         return null;
 47     }
 48     @Override
 49     public E getData(int index) {
 50         Node node = node(index);
 51         if (node != null)
 52             return (E) node.data;
 53         else {
 54             try {
 55                 throw new NullPointerException();
 56             } catch (NullPointerException e) {
 57                 System.out.println("Null:no such element");
 58                 return null;
 59             }
 60 
 61         }
 62     }
 63 
 64     @Override
 65     public void remove() {
 66         final Node<E> l = tail;
 67         if (l == null)
 68             throw new NoSuchElementException();
 69         return ;
 70 
 71     }
 72 
 73     @Override
 74     public void remove(int index) {
 75 
 76     }
 77 
 78     //链表头部添加元素
 79     public void addFirst(E element) {
 80         Node node = new Node(null,null,element);    //节点对象
 81         node.next = this.head;
 82         this.head = node;
 83         this.size++;
 84     }
 85 
 86     @Override
 87     public void add(int index, E theElement) {
 88         if (index == 0) {
 89             this.adDFirst(theElement);
 90             return;
 91         }
 92 
 93         Node preNode = this.head;
 94         for (int i = 0; i < index - 1; i++) {
 95             preNode = preNode.next;
 96         }
 97 
 98         Node node = new Node(null,null,theElement);
 99         node.next = preNode.next;
100         preNode.next = node;
101         this.size++;
102     }
103 
104     @Override
105     public void add(E data) {
106         if (head == null) {
107             Node node = new Node(null, null, data);
108             head = node;
109             tail = node;
110         } else {
111             Node node = new Node(null, tail, data);
112             tail.next = node;
113             tail = node;
114         }
115         this.size++;
116     }
117 
118     @Override
119     public void printList() {
120         int count = this.size;
121         Node curr = head;
122         System.out.print("打印链表元素:");
123 
124         while (count-- > 0) {
125             System.out.print("  " + curr.data);
126             curr = curr.next;
127         }
128 
129         System.out.println();
130 
131     }
132 
133     @Override
134     public E getFirst() {
135         final Node<E> f = head;
136         if (f == null)
137             throw new NoSuchElementException();
138         return f.data;
139 
140     }
141 
142     @Override
143     public E getLast() {
144         final Node<E> l = tail;
145         if (tail == null)
146             throw new NoSuchElementException();
147         return l.data;
148 
149     }
150 }
151 
152 package LinkedList;
153 
154 public interface DoubleLinkedListImpl<E> {
155 
156     /**
157      * 判断链表是否为空
158      *
159      * @return
160      */
161 
162     public boolean isEmpty();
163 
164 
165     /**
166      * 获取当前链表节点数量
167      *
168      * @return 节点数
169      */
170 
171     public int getSize();
172 
173 
174     /**
175      * 获取链表中第index个位置的节点的data值
176      *
177      * @param index:节点在链表中的位置
178      * @return:返回该节点的data值
179      */
180 
181     public E getData(int index);
182 
183 
184     /**
185      * 删除链表最后一个节点
186      */
187 
188     public void remove();
189 
190 
191     /**
192      * 删除链表中第index位置的节点
193      *
194      * @param index:节点在链表中的位置
195      */
196 
197     public void remove(int index);
198 
199 
200     /**
201      * 在链表的第index个位置之前插入一个节点,值为theElement,index∈[1,size]
202      *
203      * @param index:插入节点在链表中的位置
204      * @param theElement:新插入节点的data值
205      */
206 
207     public void add(int index, E theElement);
208 
209 
210     /**
211      * 在链表尾插入节点,插入节点data值为element
212      *
213      * @param element
214      */
215 
216     public void add(E element);
217 
218 
219     /**
220      * 输出链表
221      */
222 
223     public void printList();
224 
225 
226     /**
227      * 获取第一个节点的data值
228      *
229      * @return
230      */
231 
232     public E getFirst();
233 
234 
235     /**
236      * 获取链表最后一个节点的data值
237      *
238      * @return
239      */
240 
241     public E getLast();
242 
243 }
244 
245 package LinkedList;
246 
247 public class Node<E> {
248 
249     public E data;//数据域,类型为泛型E
250 
251     public Node<E> next;//后继引用(指针)
252 
253     public Node<E> previous;//前驱引用(指针)
254 
255     public Node(Node next, Node previous, E data) {
256         super();
257         this.next = next;
258         this.previous = previous;
259         this.data = data;
260     }
261 
262 
263 }

期中考试----1

第二次博客作业

 

 

  1 import java.lang.*;
  2 import java.util.*;
  3 import java.util.Scanner;
  4 public class Main {
  5     public static void main(String[] args) {
  6         Scanner in = new Scanner(System.in);
  7         double x1 = in.nextDouble();
  8         double y1 = in.nextDouble();
  9         double x2 = in.nextDouble();
 10         double y2 = in.nextDouble();
 11         String color = in.next();
 12         if(x1<=0||x1>200||y1<=0||y1>200||x2<=0||x2>200||y2<=0||y2>200){
 13             System.out.println("Wrong Format");
 14         }
 15         else{
 16             Point point1 = new Point(x1,y1);
 17             Point point2 = new Point(x2,y2);
 18             Line b = new Line(point1,point2,color);
 19             b.display();
 20         }
 21     }
 22 }
 23 class Point{//表示平面直角坐标系上的点
 24     private  double x;
 25     private  double y;
 26 
 27     Point(){
 28 
 29     }
 30 
 31     Point(double x,double y){
 32         this.x = x;
 33         this.y = y;
 34     }
 35 
 36     double getX(){//构造方法以及属性
 37         return this.x;
 38     }
 39 
 40     void setX(double x){//构造方法以及属性
 41         this.x = x;
 42     }
 43 
 44     double getY(){//构造方法以及属性
 45         return this.y;
 46     }
 47 
 48     void setY(double y){//构造方法以及属性
 49         this.y = y;
 50     }
 51 
 52     void display(){//用于显示信息的方法
 53         System.out.println("The line's begin point's Coordinate is:"+"("+String.format("%.2f",x)+","+String.format("%.2f",y)+")");
 54     }
 55 
 56 }
 57 
 58 class Line{
 59     private Point point1;
 60     private Point point2;
 61     private String color;
 62 
 63     Line(){
 64 
 65     }
 66 
 67     Line(Point point1,Point point2,String color){
 68         this.point1 = point1;
 69         this.point2 = point2;
 70         this.color = color;
 71 
 72     }
 73 
 74     Point getPoint1(){
 75         return this.point1;
 76     }
 77 
 78     void setPoint1(Point point1){
 79         this.point1 = point1;
 80     }
 81 
 82     Point getPoint2(){
 83         return this.point2;
 84     }
 85 
 86     void setPoint2(Point point2){
 87         this.point2 = point2;
 88     }
 89 
 90     String getColor(){
 91         return this.color;
 92     }
 93 
 94     void setColor(String color){
 95         this.color = color;
 96     }
 97 
 98     double getDistance(){
 99         return Math.sqrt(Math.abs((point1.getX() - point2.getX())* (point1.getX() - point2.getX())+(point1.getY() - point2.getY())* (point1.getY() - point2.getY())));
100     }
101 
102     void display(){
103         System.out.println("The line's color is:"+color);
104         System.out.println("The line's begin point's Coordinate is:");
105         System.out.println("("+String.format("%.2f",point1.getX())+","+String.format("%.2f",point1.getY())+")");
106         System.out.println("The line's end point's Coordinate is:");
107         System.out.println("("+String.format("%.2f",point2.getX())+","+String.format("%.2f",point2.getY())+")");
108         System.out.println("The line's length is:"+String.format("%.2f",getDistance()));
109     }
110 
111 }

期中考试----2

第二次博客作业

 

 

  1 import java.lang.*;
  2 import java.util.Scanner;
  3 public class Main {
  4     public static void main(String[] args) {
  5         Scanner in = new Scanner(System.in);
  6         double x1 = in.nextDouble();
  7         double y1 = in.nextDouble();
  8         double x2 = in.nextDouble();
  9         double y2 = in.nextDouble();
 10         String color = in.next();
 11         if(x1<=0||x1>200||y1<=0||y1>200||x2<=0||x2>200||y2<=0||y2>200){
 12             System.out.println("Wrong Format");
 13         }
 14         else{
 15             Point point1 = new Point(x1,y1);
 16             Point point2 = new Point(x2,y2);
 17             Line line = new Line(point1,point2,color);
 18             Plane plane = new Plane(color);
 19             Element element = new Element();
 20 
 21             element = point1;//起点Point
 22             element.display();
 23 
 24             element = point2;//终点Point
 25             element.display();
 26 
 27             element = line;//线段
 28             element.display();
 29 
 30             element = plane;//
 31             element.display();
 32 
 33         }
 34     }
 35 }
 36 
 37 class Element{
 38 
 39     void display(){
 40 
 41     }
 42 
 43 }
 44 class Plane extends Element{
 45     private String color;
 46 
 47     Plane(){
 48 
 49     }
 50 
 51     Plane(String color){
 52         this.color = color;
 53     }
 54 
 55     String getColor(){
 56         return this.color;
 57     }
 58 
 59     void setColor(String color){
 60         this.color = color;
 61     }
 62 
 63     void display(){
 64         System.out.println("The Plane's color is:"+color);
 65     }
 66 }
 67 
 68 class Point extends Element{//表示平面直角坐标系上的点
 69     private  double x;
 70     private  double y;
 71 
 72     Point(){
 73 
 74     }
 75 
 76     Point(double x,double y){
 77         this.x = x;
 78         this.y = y;
 79     }
 80 
 81     double getX(){//构造方法以及属性
 82         return this.x;
 83     }
 84 
 85     void setX(double x){//构造方法以及属性
 86         this.x = x;
 87     }
 88 
 89     double getY(){//构造方法以及属性
 90         return this.y;
 91     }
 92 
 93     void setY(double y){//构造方法以及属性
 94         this.y = y;
 95     }
 96 
 97     void display(){//用于显示信息的方法
 98         System.out.println("("+String.format("%.2f",x)+","+String.format("%.2f",y)+")");
 99     }
100 
101 }
102 
103 class Line extends  Element{
104     private Point point1;
105     private Point point2;
106     private String color;
107 
108     Line(){
109 
110     }
111 
112     Line(Point point1,Point point2,String color){
113         this.point1 = point1;
114         this.point2 = point2;
115         this.color = color;
116 
117     }
118 
119     Point getPoint1(){
120         return this.point1;
121     }
122 
123     void setPoint1(Point point1){
124         this.point1 = point1;
125     }
126 
127     Point getPoint2(){
128         return this.point2;
129     }
130 
131     void setPoint2(Point point2){
132         this.point2 = point2;
133     }
134 
135     String getColor(){
136         return this.color;
137     }
138 
139     void setColor(String color){
140         this.color = color;
141     }
142 
143     double getDistance(){
144         return Math.sqrt(Math.abs((point1.getX() - point2.getX())* (point1.getX() - point2.getX())+(point1.getY() - point2.getY())* (point1.getY() - point2.getY())));
145     }
146 
147     void display(){
148         System.out.println("The line's color is:"+color);
149         System.out.println("The line's begin point's Coordinate is:");
150         System.out.println("("+String.format("%.2f",point1.getX())+","+String.format("%.2f",point1.getY())+")");
151         System.out.println("The line's end point's Coordinate is:");
152         System.out.println("("+String.format("%.2f",point2.getX())+","+String.format("%.2f",point2.getY())+")");
153         System.out.println("The line's length is:"+String.format("%.2f",getDistance()));
154     }
155 
156 }

期中考试----3

第二次博客作业

 

 

  • 踩坑心得:

 

第二次博客作业

 

 7-2计算交点的时候出现了一点问题,当时少考虑了重合情况,导致计算交点出现了报错

做双向链表的题目的时候,增加操作也出现了一点问题,不能进行@R_360_1958@增加,后面重新开辟节点,解决了这个问题

至于期中考试嘛,我做第1题的时候,题目理解错了,导致卡了很久,

而且第1题当时有一个输入问题就是next和nextline当时我用了nextline导致数据没有读取进去,后面改成了next解决了

  • 改进建议:

具体怎么改进,我自己本身也不是很清楚,但我觉得代码风格一定要简约,

同时对函数的构造以及类的分类必须清晰,要不然一旦出现格式错误,

很难在短时间内发现自己代内部的问题,

在构造类的过程中,命名尽量贴合实际,切记不要随意命名,变量名也应尽量切合题意,

这样做可以极大程度的方便后续代码的维护以及修改。

同时在书写代码的时候,量在关键处,尤其是逻辑紧密的地方加上一定量的注释,

这样做既可以方便自己后续的阅读,也可以方便别人对代码进行理解

而且要加强对字符串这方面的练习,包括正则表达式的练习,在这方面还有着较大的漏洞

  • 总结:

通过这几次PTA中的图形类设计的题目,以及超星中链表类练习题目以及期中考试的三道练习题,

我发现了自己许多的不足之处,包括编码能力,编码速度以及对字符串的处理,都存在很大的问题,

也越来越让我感到有种压迫感。时间很紧啊,三门数学还在等我,需要更好的对时间进行规划,

对时间进行更有效的利用,同时要找到更利于自己的学习方法以及思路。

 

脚本宝典总结

以上是脚本宝典为你收集整理的第二次博客作业全部内容,希望文章能够帮你解决第二次博客作业所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。