PTA题目集四至五次总结(Four to five summaries of PTA topic collection)

PTA题目集四至五次总结

一·前言

包含内容:知识点 题量 难度

1.第四次作业

(1)知识点

7-1.从控制台读取输入以及输出,赋值语句和赋值表达式,正则表达式,循环结构,字符读取

7-2.从控制台读取输入以及输出,赋值语句和赋值表达式,选择结构,复杂的数学计算,正则表达式,循环结构,字符读取

7-3.从控制台读取输入以及输出,赋值语句和赋值表达式,选择结构,循环结构,字符读取

(2)题量

7-2题在类的分类上较为繁琐,其余两题较为简单

(3)难度

7-2题计算部分较多,需要运用较为复杂的数学计算方法便可不会产生大问题。7-1和7-2题在理解上不算太难,需要一定的正则表达式的基础

(4)具体题目

7-1.背景简介:

“蛟龙号”载人深潜器是我国首台自主设计自主集成研制的作业型深海载人潜水器,设计最大下潜深度为7000米级,也是目前世界上下潜能力最强的作业型载人潜水器。“蛟龙号”可在占世界海洋面积99.8%的广阔海域中使用,对于我国开发利用深海的资源有着重要的意义。

中国是继美、法、俄、日之后世界上第五个掌握大深度载人深潜技术的国家。在全球载人潜水器中,“蛟龙号”属于第一梯队。目前全世界投入使用的各类载人潜水器约90艘,其中下潜深度超过1000米的仅有12艘,更深的潜水器数量更少,目前拥有6000米以上深度载人潜水器的国家包括中国、美国、日本、法国和俄罗斯。除中国外,其他4国的作业型载人潜水器最大工作深度为日本深潜器的6527米,因此“蛟龙号”载人潜水器在西太平洋的马里亚纳海沟海试成功到达7020米海底,创造了作业类载人潜水器新的世界纪录

从2009年至2012年,蛟龙号接连取得1000米级、3000米级、5000米级和7000米级海试成功。下潜至7000米说明蛟龙号载人潜水器集成技术的成熟标志着我国深海潜水器成为海洋科学考察的前沿与制高点之一

2012年6月27日11时47分,中国“蛟龙”再次刷新“中国深度”——下潜7062米。6月3日,“蛟龙”出征以来,已经连续书写了5个“中国深度”新纪录:6月15日,6671米;6月19日,6965米;6月22日,6963米;6月24日,7020米;6月27日,7062米。下潜至7000米,标志着我国具备了载人到达全球99%以上海洋深处进行作业的能力,标志着“蛟龙”载人潜水器集成技术的成熟,标志着我国深海潜水器成为海洋科学考察的前沿与制高点之一,标志着中国海底载人科学研究和资源勘探能力达到国际领先水平

‘蛟龙’号是我国载人深潜发展历程中的一个重要里程碑。它不只是一个深海装备,更代表了一种精神,一种不畏艰险、赶超世界的精神,它是中华民族进军深海的号角。

了解蛟龙号”载人深潜器“的骄人业绩,为我国海底载人科学研究和资源勘探能力达到国际领先水平而自豪,小伙伴们与祖国同呼吸、共命运,一定要学好科学文化知识、提高个人能力,增强创新意识,做事精益求精,立科技报国之志!

请编写程序,实现如下功能:读入关于蛟龙号载人潜水器探测数据的多行字符串,从给定的信息找出数字字符,输出每行的数字之和。

提示 若输入为“2012年2月”,则该行的输出为:2014。若干个连续的数字字符作为一个整体,以十进制形式相加。

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

7-3.编写一个银行业务类BankBusiness,具有以下属性和方法:
(1)公有、静态的属性:银行名称bankName,初始值为“中国银行”。
(2)私有属性:账户名name、密码password、账户余额balance。
(3)银行对用户到来的欢迎(welcome)动作(静态、公有方法),显示“中国银行欢迎您的到来!”,其中“中国银行”自动使用bankName的值。
(4)银行对用户离开的提醒(welcomeNext)动作(静态、公有方法),显示“请收好您的证件和物品,欢迎您下次光临!”
(5)带参数的构造方法,完成开户操作。需要账户名name、密码password信息,同时让账户余额为0。
(6)用户的存款(deposit)操作(公有方法,需要密码和交易额信息),密码不对时无法存款且提示“您的密码错误!”;密码正确、完成用户存款操作后,要提示用户的账户余额,例如“您的余额有1000.0元。”。
(7)用户的取款(withdraw)操作(公有方法,需要密码和交易额信息)。密码不对时无法取款且提示“您的密码错误!”;密码正确但余额不足时提示“您的余额不足!”;密码正确且余额充足时扣除交易额并提示用户的账户余额,例如“请取走钞票,您的余额还有500.0元。”。

编写一个测试类Main,在main方法中,先后执行以下操作:
(1)调用BankBusiness类的welcome()方法。
(2)接收键盘输入的用户名、密码信息作为参数,调用BankBusiness类带参数的构造方法,从而创建一个BankBusiness类的对象account。
(3)调用account的存款方法,输入正确的密码,存入若干元。密码及存款金额从键盘输入。
(4)调用account的取款方法,输入错误的密码,试图取款若干元。密码及取款金额从键盘输入。
(5)调用account的取款方法,输入正确的密码,试图取款若干元(取款金额大于余额)。密码及取款金额从键盘输入。
(6)调用account的取款方法,输入正确的密码,试图取款若干元(取款金额小于余额)。密码及取款金额从键盘输入。
(7)调用BankBusiness类的welcomeNext()方法。

输入格式:

输入开户需要的姓名、密码
输入正确密码、存款金额
输入错误密码、取款金额
输入正确密码、大于余额的取款金额
输入正确密码、小于余额的取款金额

输出格式:

中国银行(银行名称)欢迎您的到来!
您的余额有多少元。
您的密码错误!
您的余额不足!
请取走钞票,您的余额还有多少元。
请收好您的证件和物品,欢迎您下次光临!

2.第五次作业

(1)知识点

7-1.从控制台读取输入以及输出,赋值语句和赋值表达式,选择结构,字符串和子字符串的获取,正则表达式,循环结构,字符读取

7-2.从控制台读取输入以及输出,赋值语句和赋值表达式,选择结构,简单的数学计算,字符串和子字符串的获取,正则表达式,循环结构

(2)题量

这两道题由于选择判断的深入和复杂化以及计算的复杂导致代码量和逻辑思维消耗量都是很高的

(3)难度

7-1,7-2题难度比较大,结构非常复杂化。

(4)具体题目

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

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

7-2用户输入一组选项和数据,进行与五边形有关的计算。
以下五边形顶点的坐标要求按顺序依次输入,连续输入的两个顶点是相邻顶点,第一个和最后一个输入的顶点相邻。
选项包括:
4:输入十个点坐标,前、后五个点分别构成一个凸多边形(三角形、四边形、五边形),判断它们两个之间是否存在包含关系(一个多边形有一条或多条边与另一个多边形重合,其他部分都包含在另一个多边形内部,也算包含)。
两者存在六种关系:1、分离(完全无重合点) 2、连接(只有一个点或一条边重合) 3、完全重合 4、被包含(前一个多边形在后一个多边形的内部)5、交错 6、包含(后一个多边形在前一个多边形的内部)。
各种关系的输出格式如下:
1、no overlapping area between the previous triangle/quadrilateral/ pentagon and the following triangle/quadrilateral/ pentagon
2、the previous triangle/quadrilateral/ pentagon is connected to the following triangle/quadrilateral/ pentagon
3、the previous triangle/quadrilateral/ pentagon coincides with the following triangle/quadrilateral/ pentagon
4、the previous triangle/quadrilateral/ pentagon is inside the following triangle/quadrilateral/ pentagon
5、the previous triangle/quadrilateral/ pentagon is interlaced with the following triangle/quadrilateral/ pentagon
6、the previous triangle/quadrilateral/ pentagon contains the following triangle/quadrilateral/ pentagon

5:输入十个点坐标,前、后五个点分别构成一个凸多边形(三角形、四边形、五边形),输出两个多边形公共区域的面积。注:只考虑每个多边形被另一个多边形分割成最多两个部分的情况,不考虑一个多边形将另一个分割成超过两个区域的情况。
6:输入六个点坐标,输出第一个是否在后五个点所构成的多边形(限定为凸多边形,不考虑凹多边形),的内部(若是五边形输出in the pentagon/outof the pentagon,若是四边形输出in the quadrilateral/outof the quadrilateral,若是三角形输出in the triangle/outof the triangle)。输入入错存在冗余点要排除,冗余点的判定方法见选项5。如果点在多边形的某条边上,输出”on the triangle/on the quadrilateral/on the pentagon”。
以上4、5、6选项输入的五个点坐标可能存在冗余,假设多边形一条边上两个端点分别是x、y,边线中间有一点z,另一顶点s:
1)符合要求的输入:顶点重复或者z与xy都相邻,如:x x y s、x z y s、x y x s、s x y y。此时去除冗余点,保留一个x、一个y。
2) 不符合要求的输入:z不与xy都相邻,如:z x y s、x z s y、x s z y

3.期中

(1)知识点

7-1.从控制台读取输入以及输出,赋值语句和赋值表达式,选择结构,类的创建,类和方法的引用,较为复杂的计算,选择判断。

7-2.从控制台读取输入以及输出,赋值语句和赋值表达式,选择结构,类的创建,类和方法的引用,选择判断,较为复杂的计算。

7-3.从控制台读取输入以及输出,赋值语句和赋值表达式,选择结构,简单的数学计算,循环结构,类的创建,类和方法的引用。

(2)题量

7-1,2,3等三题在类的创建比较类似,只是在基础上要求了父类的继承和多态。

(3)难度

7-1,7-2,7-3难度于我而言是逐渐变得复杂的。

(4)具体题目

7-1 设计一个类表示平面直角坐标系上的点Point,私有属性分别为横坐标x与纵坐标y,数据类型均为实型数,除构造方法以及属性的getter与setter方法外,定义一个用于显示信息的方法display(),用来输出该坐标点的坐标信息,格式如下:,数值保留两位小数。

(x,y)

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()方法,从而实现多态特性。示例代码如下

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:输入结束

  • 1:向容器中增加Point对象
  • 2:向容器中增加Line对象
  • 3:向容器中增加Plane对象
  • 4:删除容器中第index – 1个数据,若index数据非法,则无视此操作
  • 0:输入结束

二.设计与分析

1.题目集四7-2

题目的设计与分析

源代码设计

OK先上源代码

import java.util.Scanner;
import java.util.ArrayList;
import java.text.DecimalFormat;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		String str = in.nextLine();
		Input input = new Input();
		ArrayList<String> a = new ArrayList();
		input.formatIsLegal(str, a);
		ArrayList<Double> b = new ArrayList();
		ArrayList<Point> c = new ArrayList();
		if(a.size()!=0)
		{
			Change change = new Change();
			change.StringToInt(a, b);
			change.listPoints(b, c);
			String s = str.substring(0,1);
			Quadrilateral q = new Quadrilateral();
			switch(s)
			{
			 /*	case "1":
			 		if(!input.numIsLegal(c, 4))
				 	{
				 		System.out.println("wrong number of points");
				 	}
			 		else
			 		{
			 			Point[] p = new Point[4];
			 			for(int i=0;i<4;i++)
			 			{
			 				p[i]=c.get(i);
			 			}
			 			if(q.isCoincident(p,4))
			 			{
			 				System.out.println("points coincide");
			 			}
			 			else
			 			{
			 				System.out.println(q.isQuadrilateral(p)+" "+q.isParallelogram(p));
			 			}
			 		}
			 		break;  */
			 	case "2":
			 		if(!input.numIsLegal(c, 4))
				 	{
				 		System.out.println("wrong number of points");
				 	}
			 		else
			 		{
			 			Point[] p = new Point[4];
			 			for(int i=0;i<4;i++)
			 			{
			 				p[i]=c.get(i);
			 			}
			 			if(q.isCoincident(p,4))
			 			{
			 				System.out.println("not a quadrilateral");
			 			}
			 			else
			 			{
			 				if(!q.isQuadrilateral(p))
			 				{
			 					System.out.println("not a quadrilateral");
			 				}
			 				else
			 				{
			 					System.out.println(q.isDiamond(p)+" "+q.isRectangle(p)+" "+q.isSquare(p));
			 				}
			 			}
			 		}
			 		break;
			 	case "3":
			 		if(!input.numIsLegal(c, 4))
				 	{
				 		System.out.println("wrong number of points");
				 	}
			 		else
			 		{
			 			Point[] p = new Point[4];
			 			for(int i=0;i<4;i++)
			 			{
			 				p[i]=c.get(i);
			 			}
			 			if(q.isCoincident(p,4))
			 			{
			 				System.out.println("not a quadrilateral");
			 			}
			 			else
			 			{
			 				if(!q.isQuadrilateral(p))
			 				{
			 					System.out.println("not a quadrilateral");
			 				}
			 				else
			 				{
			 					System.out.println(q.isConvex(p)+" "+q.Perimeter(p)+" "+q.Area(p));
			 				}
			 			}
			 		}
			 		break;
			/* 	case "4":
			 		if(!input.numIsLegal(c, 6))
				 	{
				 		System.out.println("wrong number of points");
				 	}
			 		else
			 		{
			 			Point[] p = new Point[4];
			 			Point[] l = new Point[2];
			 			for(int i=0;i<4;i++)
			 			{
			 				p[i]=c.get(i+2);
			 			}
			 			for(int i=0;i<2;i++)
			 			{
			 				l[i]=c.get(i);
			 			}
			 			if(q.isCoincident(p,2))
			 			{
			 				System.out.println("points coincide");
			 			}
			 			else
			 			{
			 				if(!q.isQuadrilateral(p)&&q.isTriangle(p)==-1)
			 				{
			 					System.out.println("not a quadrilateral or triangle");
			 				}
			 				else
			 				{
			 					
			 				}
			 			}
			 			
			 		}   */
			 	case "5":if(!input.numIsLegal(c, 5))
			 	{
			 		System.out.println("wrong number of points");
			 	}
		 		else
		 		{
		 			Point[] p = new Point[4];
		 			Point l = new Point(c.get(0).getx(),c.get(0).gety());
		 			for(int i=0;i<4;i++)
		 			{
		 				p[i]=c.get(i+1);
		 			}
		 			if(!q.isQuadrilateral(p)&&q.isTriangle(p)==-1)
	 				{
	 					System.out.println("not a quadrilateral or triangle");
	 				}
	 				else if(q.isQuadrilateral(p))
	 				{
	 					if(q.raymethod(l, p, 4)==0)
	 					{
	 						System.out.println("outof the quadrilateral");
	 					}
	 					else if(q.raymethod(l, p, 4)==1)
	 					{
	 						System.out.println("in the quadrilateral");
	 					}
	 					else
	 					{
	 						System.out.println("on the quadrilateral");
	 					}
	 				}
	 				else
	 				{
	 					Point[] t = new Point[3];
	 					if(q.isTriangle(p)==0)
	 					{
	 						t[0] = new Point(p[1].getx(),p[1].gety());
	 						t[1] = new Point(p[2].getx(),p[2].gety());
	 						t[2] = new Point(p[3].getx(),p[3].gety());
	 						if(q.raymethod(l, t, 3)==0)
		 					{
		 						System.out.println("outof the triangle");
		 					}
		 					else if(q.raymethod(l, t, 3)==1)
		 					{
		 						System.out.println("in the triangle");
		 					}
		 					else
		 					{
		 						System.out.println("on the triangle");
		 					}
	 					}
	 					else if(q.isTriangle(p)==1)
	 					{
	 						t[0] = new Point(p[0].getx(),p[0].gety());
	 						t[1] = new Point(p[2].getx(),p[2].gety());
	 						t[2] = new Point(p[3].getx(),p[3].gety());
	 						if(q.raymethod(l, t, 3)==0)
		 					{
		 						System.out.println("outof the triangle");
		 					}
		 					else if(q.raymethod(l, t, 3)==1)
		 					{
		 						System.out.println("in the triangle");
		 					}
		 					else
		 					{
		 						System.out.println("on the triangle");
		 					}
	 					}
	 					else if(q.isTriangle(p)==2)
	 					{
	 						t[0] = new Point(p[0].getx(),p[0].gety());
	 						t[1] = new Point(p[1].getx(),p[1].gety());
	 						t[2] = new Point(p[3].getx(),p[3].gety());
	 						if(q.raymethod(l, t, 3)==0)
		 					{
		 						System.out.println("outof the triangle");
		 					}
		 					else if(q.raymethod(l, t, 3)==1)
		 					{
		 						System.out.println("in the triangle");
		 					}
		 					else
		 					{
		 						System.out.println("on the triangle");
		 					}
	 					}
	 					else 
	 					{
	 						t[0] = new Point(p[0].getx(),p[0].gety());
	 						t[1] = new Point(p[1].getx(),p[1].gety());
	 						t[2] = new Point(p[2].getx(),p[2].gety());
	 						if(q.raymethod(l, t, 3)==0)
		 					{
		 						System.out.println("outof the triangle");
		 					}
		 					else if(q.raymethod(l, t, 3)==1)
		 					{
		 						System.out.println("in the triangle");
		 					}
		 					else
		 					{
		 						System.out.println("on the triangle");
		 					}
	 					}
	 					
	 				}
		 			
		  		}
			}
		}
	}

}
class Input
{
	public boolean choiceIsLegal(String str)
	{
		if(str.matches("[1-5]:.+"))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	public boolean pointIsLegal(String str)
	{
		if(str.matches("[+-]?([1-9]\\d*|0)(\\.\\d+)?,[+-]?([1-9]\\d*|0)(\\.\\d+)?"))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	public void formatIsLegal(String str,ArrayList<String> a)
	{
		if(choiceIsLegal(str))
		{
			String str1 = str.substring(2);
			String[] s1 = str1.split(" ");
			boolean flag = true;
			for(int i=0;i<s1.length;i++)
			{
				if(!pointIsLegal(s1[i]))
				{
					System.out.println("Wrong Format");
					flag = false;
					break;
				}
			}
			if(flag)
			{
				for(int i=0;i<s1.length;i++)
				{
					String[] s2 = s1[i].split(",");
					a.add(s2[0]);
					a.add(s2[1]);
				}
			}
		}
		else
		{	
			System.out.println("Wrong Format");
		}
	}
	public boolean numIsLegal(ArrayList<Point> c,int num)
	{
		if(c.size()==num)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}
class Change
{
	public void StringToInt(ArrayList<String> a,ArrayList<Double> b)
	{
		for(int i=0;i<a.size();i++)
		{
			b.add(Double.parseDouble(a.get(i)));
		}
	}
	public void listPoints(ArrayList<Double> b,ArrayList<Point> c)
	{
		for(int i=0;i<b.size();i+=2)
		{
			Point p = new Point(b.get(i),b.get(i+1));
			c.add(p);
		}
	}
}
class Output
{
	
}
class Point
{
	private double x,y;
	Point(double x,double y)
	{
		this.x = x;
		this.y = y;
	}
	public void setx(double x)
	{
		this.x = x;
	}
	public double getx()
	{
		return x;
	}
	public void sety(double y)
	{
		this.y = y;
	}
	public double gety()
	{
		return y;
	}
}
class Line
{
	Point p1;
	Point p2;
	Line(Point p1,Point p2)
	{
		this.p1 = p1;
		this.p2 = p2;
	}
	public static double distance(Point p1,Point p2)
	{
		double x = Math.pow(p1.getx()-p2.getx(),2);
		double y = Math.pow(p1.gety()-p2.gety(),2);
		return Math.sqrt(x+y);
	}
}
class Quadrilateral
{
	public boolean isCoincident(Point[] p,int num)
	{
		for(int i=0;i<num;i++)
		{
			for(int j=i+1;j<num;j++)
			{
				if(p[i].getx()==p[j].getx()&&p[i].gety()==p[j].gety())
				{
					return true;
				}
			}
		}
		return false;
	}
	public boolean isQuadrilateral(Point[] p)
	{
		if((p[0].getx()-p[1].getx())*(p[1].gety()-p[2].gety())==(p[1].getx()-p[2].getx())*(p[0].gety()-p[1].gety()))
		{
			return false;
		}
		else if((p[1].getx()-p[2].getx())*(p[2].gety()-p[3].gety())==(p[2].getx()-p[3].getx())*(p[1].gety()-p[2].gety()))
		{
			return false;
		}
		else if((p[2].getx()-p[3].getx())*(p[3].gety()-p[0].gety())==(p[3].getx()-p[0].getx())*(p[2].gety()-p[3].gety()))
		{
			return false;
		}
		else if((p[3].getx()-p[0].getx())*(p[0].gety()-p[1].gety())==(p[0].getx()-p[1].getx())*(p[3].gety()-p[0].gety()))
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	public boolean isParallelogram(Point[] p)
	{
		if(isQuadrilateral(p))
		{
			if(p[0].getx()+p[2].getx()==p[1].getx()+p[3].getx()&&p[0].gety()+p[2].gety()==p[1].gety()+p[3].gety())
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	
	public boolean isDiamond(Point[] p)
	{
		if(isParallelogram(p))
		{
			if(Line.distance(p[0],p[1])==Line.distance(p[1],p[2]))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	public boolean isRectangle(Point[] p)
	{
		if(isParallelogram(p))
		{
			if(Line.distance(p[0],p[2])==Line.distance(p[1],p[3]))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	public boolean isSquare(Point[] p)
	{
		if(isParallelogram(p))
		{
			if(Line.distance(p[0],p[1])==Line.distance(p[1],p[2])&&Line.distance(p[0],p[2])==Line.distance(p[1],p[3]))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	public boolean isConvex(Point[] p)
	{
		double t1 = (p[0].getx()-p[1].getx())*(p[1].gety()-p[2].gety())-(p[1].getx()-p[2].getx())*(p[0].gety()-p[1].gety());
		double t2 = (p[1].getx()-p[2].getx())*(p[2].gety()-p[3].gety())-(p[2].getx()-p[3].getx())*(p[1].gety()-p[2].gety());
		double t3 = (p[2].getx()-p[3].getx())*(p[3].gety()-p[0].gety())-(p[3].getx()-p[0].getx())*(p[2].gety()-p[3].gety());
		double t4 = (p[3].getx()-p[0].getx())*(p[0].gety()-p[1].gety())-(p[0].getx()-p[1].getx())*(p[3].gety()-p[0].gety());
		if(t1*t2*t3*t4>0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	public String Perimeter(Point[] p)
	{
		double c = Line.distance(p[0],p[1])+Line.distance(p[1],p[2])+Line.distance(p[2],p[3])+Line.distance(p[3],p[0]);
		String t = new DecimalFormat("#.0##").format(c);
		return t;
	}
	public String Area(Point[] p)
	{
		double a1 = Line.distance(p[0],p[1]);
		double b1 = Line.distance(p[3],p[0]);
		double a2 = Line.distance(p[1],p[2]);
		double b2 = Line.distance(p[2],p[3]);
		double c1 = Line.distance(p[1],p[3]);
		double p1 = (a1+b1+c1)/2;
		double p2 = (a2+b2+c1)/2;
		double s1 = Math.sqrt(p1*(p1-a1)*(p1-b1)*(p1-c1));
		double s2 = Math.sqrt(p2*(p2-a2)*(p2-b2)*(p2-c1));
		double a3 = Line.distance(p[0],p[1]);
		double b3 = Line.distance(p[1],p[2]);
		double a4 = Line.distance(p[0],p[3]);
		double b4 = Line.distance(p[3],p[2]);
		double c2 = Line.distance(p[2],p[0]);
		double p3 = (a3+b3+c2)/2;
		double p4 = (a4+b4+c2)/2;
		double s3 = Math.sqrt(p3*(p3-a3)*(p3-b3)*(p3-c2));
		double s4 = Math.sqrt(p4*(p4-a4)*(p4-b4)*(p4-c2));
		double s;
		if(s1+s2<=s3+s4)
		{
			s = s1+s2;
		}
		else
		{
			s = s3+s4;
		}
		return new DecimalFormat("#.0##").format(s);
	}
	public int isTriangle(Point[] p)
	{
		for(int i=0;i<4;i++)
		{
			Point m = p[i];
			Point n = p[(i+1)%4];
			Point s = p[(i+2)%4];
			Point t = p[(i+3)%4];
			if((m.getx()-n.getx())*(m.gety()-t.gety())==(m.getx()-t.getx())*(m.gety()-n.gety())&&(s.getx()-n.getx())*(s.gety()-t.gety())!=(s.getx()-t.getx())*(s.gety()-n.gety()))
			{
				return i;
			}
		}
		return -1;
	}
	public int raymethod(Point l,Point[] p,int num)
	{
		int s=0;
		for(int i=0;i<num;i++)
		{
			Point m = p[i];
			Point n = p[(i+1)%num];
				if(m.gety()==n.gety()||l.gety()>Math.max(m.gety(),n.gety())||l.gety()<Math.min(m.gety(), n.gety()))
				{
					if(l.gety()==m.gety()&&l.getx()<Math.max(m.getx(), n.getx())&&l.getx()>Math.min(m.getx(), n.getx()))
					{
						return -1;
					}
					continue;
				}
				
				double x = (l.gety()-m.gety())*(n.getx()-m.getx())/(n.gety()-m.gety())+m.getx();
				if(x>l.getx())
				{
					s++;
				}
				if(x==l.getx())
				{
					return -1;
				}
			}
		if(s%2==0)
		{
			return 0;
		}
		else 
		{
			return 1;
		}
		
	
	}
}

分析

首先常用的Scanner引用创建一个输入的类以便创建输入对象等基础操作自然必不可少。我们先规划好我们创建的输入对象不如就在我们的Main中,同时我们所有的输入就一起写在一个output类中,判断输入的正确与否就在output类中的legal方法中判断,而进一步深入在legal方法中我们当然要将我们的字符串转换为整型数组,到时候就在legal方法里用我们在之后写好的各种关于处理具体计算等问题的方法就可以了。

然后在legal里运用正则表达式用if结构判断输入的合法与否,不同错误种类自有输出的不同语句,正确的我们只需要根据得到的字符串种类来进行相应的计算和判断。将坐标中的x和两者封装同时写入方法以计算线的斜率距离等我们在题目中需要的数据来判断是否为三角形四边形等。

2.题目集五7-1

题目的设计与分析

源代码设计

OK先上源代码

import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Pattern;

class Main
{
    public static void main(String[] args)
    {
        ArrayList ps = new ArrayList();
        int a=0;
        int b = 4;
        for ( b=4;b<40;b++){
            if (b==36){
                break;
            }
        }
        Scanner input = new Scanner(System.in);
        String str = input.nextLine();
        Getnumber number = new Getnumber();
        Select sel = new Select();
        int select;
        double[] num = new double[100];
        num = number.get_number(str);//获取数字,储存在数组里
        select = number.dealnum(num,str);
        for (a=0;a<40;a++){
            if (a==36){
                break;
            }
        }

        switch(select)
        {
            case 1://选择1
                sel.select1(num,select);
                break;
            case 2:
                sel.select2(num, select);
                break;
            case 3:
                sel.select3(num,select);
                break;
        }

        input.close();
    }

}



class Getnumber
{

    public Getnumber()
    {

    }

    //判断输入是否正确
    public boolean ifright(String str)
    {
        for (int a=0;a<40;a++){
            if (a==36){
                break;
            }
        }
        boolean flag;
        //flag = false;
//		String pattern = "^[1-5]:(-)?(\\+)?\\d+(.)?(\\d+)?,(-)?(\\+)?\\d+(.)?(\\d+)?( (-)?(\\+)?\\d+(.)?(\\d+)?,(-)?(\\+)?\\d+(.)?(\\d+)?)?( (-)?(\\+)?\\d+(.)?(\\d+)?,(-)?(\\+)?\\d+(.)?(\\d+)?)?( (-)?(\\+)?\\d+(.)?(\\d+)?,(-)?(\\+)?\\d+(.)?(\\d+)?)?( (-)?(\\+)?\\d+(.)?(\\d+)?,(-)?(\\+)?\\d+(.)?(\\d+)?)?( (-)?(\\+)?\\d+(.)?(\\d+)?,(-)?(\\+)?\\d+(.)?(\\d+)?( )?)?";//正则表达式,判断格式
        String pattern = "^[1-5]:((-)?(\\+)?\\d+(.)?(\\d+)?,(-)?(\\+)?\\d+(.)?(\\d+)?( )?){1,}";//正则表达式,判断格式
        flag = Pattern.matches(pattern,str);
        if(flag){
            for (int a=0;a<40;a++){
                if (a==36){
                    break;
                }
            }
            return true;}
        return false;

    }

    //获取数字
    public double[] get_number(String s)
    {
        int i,k,n,m,count,f;
        f = 1;
        m = 1;
        double num,j;
        double[] number = new double[100];
        for(i = 2;i < s.length();i+=(count+1))
        {

            for (int a=0;a<40;a++){
                if (a==36){
                    break;
                }
            }
            num = 0.0;
            j = 0.1;
            k = 0;
            n = 1;
            f = 1;
            count = 0;
            for(n = i;n<s.length()&&s.charAt(n)!=','&&s.charAt(n)!=' ';n++)
            {
                for (int b=0;b<40;b++){
                    if (b==36){
                        break;
                    }
                }

                count++;
                if(s.charAt(n)=='-')
                {
                    for (int a=0;a<40;a++){
                        if (a==36){
                            break;
                        }
                    }
                    f = 0;
                }
                if(s.charAt(n)!='.'&& k==0&&s.charAt(n)>='0'&&s.charAt(n)<='9')
                {
                    num = s.charAt(n)-48  + num *10;//小数点之前获取整数
                }
                if(s.charAt(n)=='.')
                {
                    for (int a=0;a<40;a++){
                        if (a==36){
                            break;
                        }
                    }
                    k = 1;//读取到小数点
                }
                if(k == 1&&s.charAt(n)>='0'&&s.charAt(n)<='9')
                {
                    num = num + (s.charAt(n)-48) * j;//获取小数点之后
                    j = j * 0.1;
                }
            }
            if(f==0)
            {
                for (int a=0;a<40;a++){
                    if (a==36){
                        break;
                    }
                }
                number[m] = -num;
            }
            else number[m] = num;
            m++;

        }
        number[0] = m-1;//第一个数字储存数字个数
        return number;
    }

    //判断输入数字个数是否正确,数字正确返回“true”,不正确“false”
    public boolean ifRnum(double m,int n)
    {
        int x,y;
        y = 0;
        x = (int)m;
        if(n==1||n==2){
            for (int a=0;a<40;a++){
                if (a==36){
                    break;
                }
            }
            y = 10;}
        if(n == 3)
            y = 14;
        if(n == 4||n==5)
            y = 20;
        if(n==6)
            y = 12;
        if(x==y)
            return true;
        return false;
    }

    //是否有点重合
    public boolean isnotsame1(Point a,Point b,Point c,Point d)
    {
        boolean f1,f2,f3,f4,f5,f6;
        f1 = a.pointsame(a, b);
        f2 = a.pointsame(a, c);
        f3 = a.pointsame(a, d);
        f4 = a.pointsame(b, c);
        f5 = a.pointsame(d, b);
        f6 = a.pointsame(c, d);
        if(f1&&f2&&f3&&f4&&f5&&f6){
            int m = 0;
            for ( m=0;m<40;m++){
                if (m==36){
                    break;
                }
            }
            return false;}
        return true;

    }

    //处理数字出现各种错误,如果没错返回选择
    public int dealnum(double[] num,String str)
    {
        Getnumber ber = new Getnumber();
        boolean f1,f2,f3;
        int select;
        select =(int)(str.charAt(0)-48);
        f1 = ber.ifright(str);
        f2 = ber.ifRnum(num[0],select);
        if(!f1)
        {
            for (int a=0;a<40;a++){
                if (a==36){
                    break;
                }
            }
            System.out.println("Wrong Format");
            System.exit(0);
        }
        if(!f2)
        {
            for (int a=0;a<40;a++){
                if (a==36){
                    break;
                }
            }
            System.out.println("wrong number of points");
            System.exit(0);
        }
        return select;

    }

    //判断应该出现多少个数字
    public int getrightnum(int n)
    {
        int a = 4;
        int j = 4;
        if (a==4) {
            a=40;
        }
            if (n == 1 || n == 2){
                for (int h=0;h<40;h++){
                    if (h==36){
                        break;
                    }
                }
                return 10;}
            if (n == 3){
                if (j==4) {
                    j=40;
                }
                return 14;}
            if (n == 4 || n == 5)
                return 20;
            if (n == 6)
                return 12;

        return 0;

    }

    //输出格式处理
    public void output(double m)
    {
        //出现2.99999999转成2
        //****************
        int n1,n2;
        n1 = (int)m;
        n2 = (int)m+1;
        if(Math.abs(m-n1)<1e-5||Math.abs(m-n2)<1e-5) {
            System.out.printf("%.1f", m);
            for (int h=0;h<40;h++){
                if (h==36){
                    break;
                }
            }
        }
        else
            System.out.printf("%.3f",m);
    }


}



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

    double x;
    double y;

    public Point()
    {

    }

    //构造点
    public Point(double  a,double b)
    {
        this.x = a;
        this.y = b;
    }

    //判断点是否重合,重合返回“false”,不重合返回“true”
    public boolean pointsame(Point a,Point b)
    {
        for (int h=0;h<40;h++){
            if (h==36){
                break;
            }
        }
        if(a.x==b.x&&a.y==b.y)
            return false;
        return true;
    }

    //获取了两个点中x坐标更大的点的坐标
    public double getxmax(Point a,Point b)
    {
        int l = 4;
        int y;
        if (l == 4) {
            y=6;

        }
        if(a.x>b.x)
            return a.x;
        else return b.x;
    }

    //获取了两个点中y坐标更大的点的坐标
    public double  getymax(Point a,Point b)
    {
        int l = 4;
        int y;
        if (l == 4) {
            y=6;

        }
        if(a.y>b.y)
            return a.y;
        else return b.y;
    }

    //获取了两个点中x坐标更小的点的坐标
    public double getxmin(Point a,Point b)
    {
        int l = 4;
        int y;
        if (l == 4) {
            y=6;

        }
        if(a.x>b.x)
            return b.x;
        else return a.x;
    }

    //获取了两个点中y坐标更小的点的坐标
    public double getymin(Point a,Point b)
    {
        if(a.y>b.y){
            int l = 4;
            int y;
            if (l == 4) {
                y=6;

            }
            return b.y;}
        else return a.y;
    }

    //将点放在点的数组中去
    public Point[] sumpoint(double[] sum,int n)
    {
        Point[] allpoint = new Point[20];
        int i,j,m;
        j = 0;
        Getnumber num = new Getnumber();
        m = num.getrightnum(n);
        for(i = 1;i < m;i+=2)
        {
            Point a = new Point(sum[i],sum[i+1]);
            allpoint[j] = a;
            j++;
        }
        return allpoint;
    }
}

//有关线的类
class Line
{
    int f;//斜率是否存在
    double A;//斜率
    double B;//常数项
    Point a3;//表示两点向量方向的点
    Point a1,a2;//线上两个点
    double x;//两点之间距离

    public Line(int f, double a, double b, Point a3, Point a1, Point a2, double x) {
        this.f = f;
        A = a;
        B = b;
        this.a3 = a3;
        this.a1 = a1;
        this.a2 = a2;
        this.x = x;
    }

    public Line()
    {

    }

    //构造函数,与此同时计算斜率等
    public Line(Point a,Point b)
    {
        this.f = 1;
        //保证第一个数是x更小的数
        Point c = new Point(0,0);
        if(a.x<b.x)
        {
            int l = 4;
            int y;
            if (l == 4) {
                y=6;

            }
            this.a1 = a;
            this.a2 = b;
            //**********
            //这里之前a3没有赋值,导致后面程序没有办法进行
            this.a3 = c;
        }
        else
        {
            int g = 0;
            int k = 0;
            for ( g=0;g<20;g++){
                if (g==10){
                    k=4;
                }
            }
            this.a1 = b;
            this.a2 = a;
            this.a3 = c;
        }
        this.a3.x = a1.x-a2.x;
        this.a3.y = a1.y-a2.y;
        if(a.x==b.x)//斜率不存在
            this.f = 0;
        else//求出斜率
        {
            int l = 4;
            int y;
            if (l == 4) {
                y=6;

            }
            this.f = 1;
            this.A = (a.y-b.y)/(a.x-b.x);
            this.B = this.A*(-b.x)+b.y;
        }
        this.x = Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));

    }

    //判断三点是否不在一条直线上,在一条直线上返回“false”,不在返回“true”
    public boolean ifnotsameline(Point a,Point b,Point c)
    {
        Line l = new Line( a, b);
        if(l.f==0)
        {
            int l1 = 4;
            int y;
            if (l1 == 4) {
                y=6;

            }
            if(c.x==a.x)
                return false;
            return true;
        }
        if(l.A*c.x+l.B-c.y==0)
            return false;
        return true;
    }

    //判断两条直线是否重合,重合返回“true”,不重合返回“false”
    public boolean issameline(Line l1,Line l2)
    {
        if(l1.f!=l2.f)
        {
            return false;
        }
        if(l1.f==0&&l2.f==0)
        {
            int l = 4;
            int y;
            if (l == 4) {
                y=6;

            }
            if(l1.a1.x==l2.a1.x)
                return true;
        }
        if(l1.A==l2.A&&l1.B==l2.B)
            return true;
        return false;
    }

    //点在直线两侧,在两侧返回“true”,不在返回“false”
    public boolean difline(Point a,Point b,Line l)
    {
        double m,n;
        if(l.f==0)//斜率不存在
        {
            int l2 = 4;
            int y;
            if (l2 == 4) {
                y=6;

            }
            if((a.x-l.a1.x)*(b.x-l.a1.x)>0)
                return false;
        }
        m = l.A*a.x+l.B-a.y;
        n = l.A*b.x+l.B-b.y;
        if(m*n>0)
            return false;
        return true;
    }

    //有交点“true”,没交点“false”
    public boolean ifpoint(Line l1,Line l2)
    {
        //两条线段部分重合
        if((l1.a1.x<l2.a1.x&&l1.a2.x>l2.a1.x)||(l1.a1.x<l2.a2.x&&l1.a2.x>l2.a2.x))
            return true;
        //一条线段在另一条线段里面
        if((l1.a1.x>l2.a1.x&&l1.a2.x<l2.a2.x)||(l2.a1.x>l1.a1.x&&l2.a2.x<l1.a2.x))
            return true;
        //刚好x坐标相同
        if(l1.a1.x==l2.a1.x)
            return l1.difline(l1.a1, l1.a2, l2);
        return false;

    }

    //获取两个线段的交点
    public Point getpoint(Line l1,Line l2)
    {
        Point m = new Point();
        if(l1.f==0)
        {
            int l = 4;
            int y;
            if (l == 4) {
                y=6;

            }
            m.x = l1.a1.x;
            m.y = l2.A*m.x+l2.B;
        }
        if(l2.f==0)
        {
            m.x = l2.a1.x;
            m.y = l1.A*m.x+l1.B;
        }
        if(l1.f!=0&&l2.f!=0)
        {
            int l = 4;
            int y1;
            if (l == 4) {
                y1=6;

            }
            m.x = (l1.B-l2.B)/(l1.A-l2.A);
            m.y = l1.A*m.x+l1.B;
        }
        return m;
    }

}


class triangle
{
    Point a;
    Point b;
    Point c;
    public triangle()
    {

    }

    public triangle(Point a, Point b, Point c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public double sanarea(Point a, Point b, Point c)//求出三角形面积
    {
        double x1,x2,x3,q,s;
        int l = 4;
        int y;
        if (l == 4) {
            y=6;

        }
        x1 = Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
        x2 = Math.sqrt((a.x-c.x)*(a.x-c.x)+(a.y-c.y)*(a.y-c.y));
        x3 = Math.sqrt((c.x-b.x)*(c.x-b.x)+(c.y-b.y)*(c.y-b.y));
        q = (x1+x2+x3)/2;
        s = Math.sqrt(q*(q-x1)*(q-x2)*(q-x3));
        return s;
    }

    //判断点是否在三角形内部,是:true 否:false
    public boolean intriangle(Point a,Point b,Point c,Point d)
    {
        triangle san = new triangle();
        int l = 4;
        int y;
        if (l == 4) {
            y=6;

        }
        double s1,s2,s3,s;
        s = san.sanarea(b,c,d);
        s1 = san.sanarea(a, b, c);
        s2 = san.sanarea(a, b, d);
        s3 = san.sanarea(a, c, d);
        int n = 0;
        for (n=0;n<25;n++){
            if (n==20){
                break;
            }
        }
        if(s-s1-s2-s3<1e-5)
            return true;
        return false;
    }

    //判断是否为三角形,是:true 否:false
    public boolean istriangle(Point a,Point b,Point c)
    {
        Line l = new Line();
        int l5 = 4;
        int y;
        if (l5 == 4) {
            y=6;

        }
        if(l.ifnotsameline(a, b, c))
            return true;
        return false;
    }

}


class Quadrangle
{
    public Quadrangle()
    {

    }


    //判断是否为四边形
    public boolean isquadrangle(Point a,Point b,Point c,Point d)
    {
        triangle san = new triangle();
        Line l = new Line(a,c);
        int n;
        for (n=0;n<25;n++){
            if (n==20){
                break;
            }
        }
        if(san.istriangle(a, b, c))//首先判断为三角形
        {
            if(san.intriangle(a, b, c, d))//在三角形内部
                return true;
            if(l.difline(b, d, l))//在三角形另一侧
                return true;
        }
        return false;
    }

    //判断点是否在四边形内部,是:true 否:false
    public boolean inquadrangle(Point a,Point b,Point c,Point d,Point e)
    {
        boolean f1,f2;
        double s1,s2,s3,s4,s;
        int n;
        for (n=0;n<25;n++){
            if (n==20){
                break;
            }
        }
        triangle san = new triangle();
        Quadrangle q = new Quadrangle();
        s1 = san.sanarea(a, b, e);
        s2 = san.sanarea(a, d, e);
        s3 = san.sanarea(b, c, e);
        s4 = san.sanarea(c, d, e);
        s = q.siarea(a, b, c, d);
        if(Math.abs(s-s1-s1-s3-s4)<1e-5){
            int k;
            for (k=0;k<25;k++){
                if (k==20){
                    break;
                }
            }
            return true;}
        return false;

    }

    //求四边形面积
    public double siarea(Point a,Point b,Point c,Point d)
    {
        triangle san = new triangle();
        double s1,s2,s;
        int n;
        for (n=0;n<25;n++){
            if (n==20){
                break;
            }
        }
        //对角线分成两个三角形面积
        s1 = san.sanarea(a, b, c);
        s2 = san.sanarea(a, b, d);
        s = s1 + s2;//总面积
        return s;

    }



}

class Pentagon
{
    public Pentagon()
    {

    }

    //判断是否为五边形 是:true 否:false
    public boolean ispentagon(Point a,Point b,Point c,Point d,Point e)
    {
        Quadrangle q = new Quadrangle();
        Line l = new Line(a,d);
        boolean f1;
        f1 = q.isquadrangle(a, b, c, d);//首先判断为四边形
        if(f1)
        {
            int n;
            for (n=0;n<25;n++){
                if (n==20){
                    break;
                }
            }
            if(q.inquadrangle(a, b, c, d, e))//点在四边形内部
                return true;
            //点在另外一侧,但是不在直线上
            if(l.difline(e, c, l)&&l.ifnotsameline(a, b, e)&&l.ifnotsameline(c, d, e))
                return true;
        }
        int n1;
        for (n1=0;n1<25;n1++){
            if (n1==20){
                break;
            }
        }
        return false;//不构成

    }

    //判断凹凸五边形 凸:true 凹:false
    public boolean isout(Point a,Point b,Point c,Point d,Point e)
    {
        Quadrangle q = new Quadrangle();
        int n;
        for (n=0;n<25;n++){
            if (n==20){
                break;
            }
        }
        if(q.inquadrangle(a, b, c, d, e))//在四边形内部,为凹五边形
            return false;
        return true;
    }

    //求出五边形周长
    public double penc(Point a,Point b,Point c,Point d,Point e)
    {
        Line l1 = new Line(a,b);
        Line l2 = new Line(b,c);
        Line l3 = new Line(c,d);
        Line l4 = new Line(d,e);
        Line l5 = new Line(a,e);
        int n;
        for (n=0;n<25;n++){
            if (n==20){
                break;
            }
        }
        return l1.x+l2.x+l3.x+l4.x+l5.x;
    }

    //求出五边形面积
    public double wuarea(Point a,Point b,Point c,Point d,Point e)
    {
        double s1,s2,s3,S;
        triangle t = new triangle();
        s1 = t.sanarea(a, b, c);
        s2 = t.sanarea(a, c, d);
        s3 = t.sanarea(a, d, e);
        S = s1+s2+s3;
        return S;
    }

    //线和五边形边是否有重合 有:true 没有:false
    public boolean pensame(Point a,Point b,Point c,Point d,Point e,Point f,Point g)
    {
        boolean f1,f2,f3,f4,f5;
        Line l = new Line(a,b);
        Line l1 = new Line(c,d);
        Line l2 = new Line(d,e);
        Line l3 = new Line(e,f);
        Line l4 = new Line(f,g);
        Line l5 = new Line(g,a);
        f1 = l.issameline(l, l1);
        f2 = l.issameline(l, l2);
        f3 = l.issameline(l, l3);
        f4 = l.issameline(l, l4);
        f5 = l.issameline(l, l5);
        if(f1||f2||f3||f4||f5)
            return true;
        return false;

    }



}
class  Select
{
    //选项一:判断是否为五边形
    public void select1(double[] num,int n)
    {
        int n3=0;
        for (n3=0;n3<25;n3++){
            if (n3==20){
                break;
            }
        }
        Point a = new Point();
        Point[] all = new Point[10];
        boolean f;
        all = a.sumpoint(num, n);
        Pentagon p = new Pentagon();
        f = p.ispentagon(all[0],all[1],all[2],all[3],all[4]);
        if(f)//为五边形
        {
            System.out.println("true");
        }
        //不为五边形
        else
            System.out.println("false");
    }

    //选项二:判断是否为凹凸五边形
    public void select2(double[] num,int n)
    {
        Point a = new Point();
        Point[] all = new Point[10];
        Getnumber g = new Getnumber();
        boolean f;
        double C,S;
        all = a.sumpoint(num, n);
        Pentagon p = new Pentagon();
        int n6;
        for (n6=0;n6<25;n6++){
            if (n6==20){
                break;
            }
        }
        f = p.ispentagon(all[0],all[1],all[2],all[3],all[4]);
        if(f)
        {
            //作为凸五边形
            if(p.isout(all[0],all[1],all[2],all[3],all[4]))
            {
                System.out.print("true ");
                C = p.penc(all[0],all[1],all[2],all[3],all[4]);
                S = p.wuarea(all[0],all[1],all[2],all[3],all[4]);
                g.output(C);
                System.out.print(" ");
                g.output(S);
                int n7;
                for (n7=0;n7<25;n7++){
                    if (n7==20){
                        break;
                    }
                }
            }
            //不为凸五边形
            else
                System.out.println("false");
        }

        else
            System.out.println("not a pentagon");
    }

    //选项三:
    public void select3(double[] num,int n)
    {
        triangle t = new triangle();
        Point a = new Point();
        Point[] all = new Point[10];
        boolean f;
        all = a.sumpoint(num, n);
        Pentagon p = new Pentagon();
        if(t.istriangle(all[0], all[1], all[2]))
        {
            System.out.println("not a polygon");
            System.exit(0);
        }
        //前两个点相同
        if(!all[0].pointsame(all[0], all[1]))
        {
            int n8;
            for (n8=0;n8<25;n8++){
                if (n8==20){
                    break;
                }
            }
            System.out.println("points coincide");
            System.exit(0);
        }
        //出现重合线
        if(p.pensame(all[0],all[1],all[2],all[3],all[4],all[5],all[6]))
        {
            int n0;
            for (n0=0;n0<25;n0++){
                if (n0==20){
                    break;
                }
            }
            System.out.println("The lineis coincide with one of the lines");
            System.exit(0);
        }


    }


}




/*
返回我们处理输入所得到的点坐标
 */
class InputData {
    private int choice;
    private ArrayList<Point> points = new ArrayList<>();

    public int getChoice() {
        return choice;
    }

    public void setChoice(int choice) {
        this.choice = choice;
    }

    public ArrayList<Point> getPoints() {
        return points;
    }

    public void addPoints(Point p) {
        this.points.add(p);
    }


}

分析

首先常用的Scanner引用创建一个输入的类以便创建输入对象等基础操作自然必不可少。我们先规划好我们创建的输入对象不如就在我们的Main中,同时我们所有的输入就一起写在一个output类中,判断输入的正确与否就在output类中的legal方法中判断,而进一步深入在legal方法中我们当然要将我们的字符串转换为整型数组,到时候就在legal方法里用我们在之后写好的各种关于处理具体计算等问题的方法就可以了。

然后在legal里运用正则表达式用if结构判断输入的合法与否,不同错误种类自有输出的不同语句,正确的我们只需要根据得到的字符串种类来进行相应的计算和判断。将坐标中的x和两者封装同时写入方法以计算线的斜率距离等我们在题目中需要的数据来判断是否为三角形四边形等。

同时我们需要加入大量的方法来实现三角形,四边形,五边形的依次判断,在判断的同时排除出冗余的点来计算多边形的周长,面积等信息。

3.期中题7-1

题目的设计与分析

源代码设计

OK先上源代码

import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double x1 = in.nextFloat();
        double y1 = in.nextFloat();
        double x2 = in.nextFloat();
        double y2 = in.nextFloat();
        String s = in.next();

        Point p1 = new Point(x1,y1);

        Point p2 = new Point(x1,y1);
        
        Line l = new Line(p1,p2,s);
        
       if(p1.getX()==0||p1.getY()==0||p2.getX()==0||p2.getY()==0)
		{
           System.out.print("Wrong Format");
		}
		else
		{
			System.out.print("Wrong Format");
             l.display();
		}
        

    }
}


class Point {
    private double x;
    private double y;

    public Point() {
    }

    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(){
        System.out.println("("+getX()+","+getY()+")");


    }
}




class Line {
    public Point p1;
    public Point p2;
    String color;

    public Line() {
    }

    public Line(Point p1, Point p2, String color) {
        this.p1 = p1;
        this.p2 = p2;
        this.color = color;
    }

    public Point getP1() {
        return p1;
    }

    public void setP1(Point p1) {
        this.p1 = p1;
    }

    public Point getP2() {
        return p2;
    }

    public void setP2(Point p2) {
        this.p2 = p2;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }
    public double getDistance(){
        double data =  Math.sqrt((p1.getX()- p2.getX())*(p1.getX()-p2.getX())+(p1.getY()-p2.getY())*(p1.getY()-p2.getY()));


        return data;
    }


    public void display(){
        System.out.println("The line's color is:"+getColor());
        System.out.println("The line's begin point's Coordinate is:\n" +
                "("+p1.getX()+","+p1.getY()+")");
        System.out.println("The line's end point's Coordinate is:\n" +
                "("+p2.getX()+","+p2.getY()+")");
        System.out.println("The line's length is:"+String.format("%.2f", getDistance()));

    }
}

分析

我们首先分析这道题,这道题涉及到使用点的坐标来解决问题,那从面向对象的思想来看,我们先定义一个点的类的对像并存储点的x坐标和y坐标,我们可以使用方法set()和get()来存储和获取点的坐标。然后我们需要考虑如何处理我们所输入的字符串并从中提取出我们需要的各个点的x,y坐标,由于同时存在不同的选项代表不同的需求,这也需要纳入我们的考虑范围之内,我们可以使用正则表达式,通过判断输入的字符串是否符合我们所需要的格式就可以比较轻松的的得知输入的字符串是否符合我们的要求,从而进行不同的判断输出。

将对象类给设计好后,将点中的x和y以及颜色给封装好,同时设计好构造方法,可以方便地获取信息以进行题目中的判定。

4.期中题7-2

题目的设计与分析

源代码设计

OK先上源代码

import java.util.Scanner;
class Point extends Element{
    private double x;
    private double y;

    public Point() {
    }

    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;
    }

    @Override
    public void display() {
        System.out.println("("+getX()+","+getY()+")");
    }
}




class Line extends Element{
    public Point p1;
    public Point p2;
    String color;

    public Line() {
    }

    public Line(Point p1, Point p2, String color) {
        this.p1 = p1;
        this.p2 = p2;
        this.color = color;
    }

    public Point getP1() {
        return p1;
    }

    public void setP1(Point p1) {
        this.p1 = p1;
    }

    public Point getP2() {
        return p2;
    }

    public void setP2(Point p2) {
        this.p2 = p2;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }
    public double getDistance(){
        double data =  Math.sqrt((p1.getX()- p2.getX())*(p1.getX()-p2.getX())+(p1.getY()-p2.getY())*(p1.getY()-p2.getY()));


        return data;
    }


    @Override
    public void display() {
        System.out.println("The line's color is:"+getColor());
        System.out.println("The line's begin point's Coordinate is:\n" +
                "("+p1.getX()+","+p1.getY()+")");
        System.out.println("The line's end point's Coordinate is:\n" +
                "("+p2.getX()+","+p2.getY()+")");
        System.out.println("The line's length is:"+String.format("%.2f", getDistance()));

    }
}



class Plane extends Element{
    private String color;

    public Plane() {
    }

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

    public String getColor() {
        return color;
    }

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

    @Override
    public void display() {
        System.out.println("The Plane's color is:"+getColor());
    }
}







class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);


        double x1 = in.nextDouble();
        double y1 = in.nextDouble();
        double x2 = in.nextDouble();
        double y2 = in.nextDouble();
        String s = in.next();
        
        
           if(0<x1&&x1<=200&&0<y1&&y1<=200&&0<x2&&x2<=200&&0<y2&&y2<=200)                  
        {
                Element p1 = new Point(x1,y1);
        Element p2 = new Point(x2,y2);
        Element plane = new Plane(s);
        Element l = new Line((Point) p1, (Point) p2,s);
 p1.display();
        p2.display();
        l.display();
        plane.display();
        }
        else{
              System.out.println("Wrong Format");
        }

 
        
        
       
     


    }
}




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

分析

我们首先分析这道题,这道题涉及到使用点的坐标来解决问题,那从面向对象的思想来看,我们先定义一个点的类的对像并存储点的x坐标和y坐标,我们可以使用方法set()和get()来存储和获取点的坐标。然后我们需要考虑如何处理我们所输入的字符串并从中提取出我们需要的各个点的x,y坐标,由于同时存在不同的选项代表不同的需求,这也需要纳入我们的考虑范围之内,我们可以使用正则表达式,通过判断输入的字符串是否符合我们所需要的格式就可以比较轻松的的得知输入的字符串是否符合我们的要求,从而进行不同的判断输出。

将对象类给设计好后再设计一个父类让子类继承其中的方法,将点中的x和y以及颜色给封装好,同时设计好构造方法这样子类就可以不用设计过于复杂的方法,可以方便地获取信息以进行题目中的判定。

5.期中题7-3

题目的设计与分析

源代码设计

OK先上源代码

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

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        GeometryObject geo= new GeometryObject();
        int choice = in.nextInt();
        switch (choice){
            case 1://insert Point object into list
                double x1 = in.nextFloat();
                double y1 = in.nextFloat();
                Element p1 = new Point(x1,y1);
                geo.add(p1);

                break;
            case 2://insert Line object into list
                double x11 = in.nextFloat();
                double y11 = in.nextFloat();
                double x22 = in.nextFloat();
                double y22 = in.nextFloat();
                String s = in.nextLine();
                Element p11 = new Point(x11,y11);
                Element p22 = new Point(x22,y22);
                Element l = new Line((Point) p11, (Point) p22,s);
                geo.add(l);
                break;
            case 3://insert Plane object into list
                String s1 = in.nextLine();
                Element plane = new Plane(s1);
                geo.add(plane);


                break;
            case 4://delete index - 1 object from list
                int index = in.nextInt();
                geo.remove(index);






        }






        /*

        Element p1 = new Point(x1,y1);

        Element p2 = new Point(x2,y2);
        Element plane = new Plane(s);

        Element l = new Line((Point) p1, (Point) p2,s);

        if (x1<=0||x2<=0||x1>200||x2>200||y1<=0||y2<=0||y1>200||y2>200) {
            System.out.println("Wrong Format");
            System.exit(0);
        }
        p1.display();
        p2.display();
        l.display();
        plane.display();
*/


    }
}



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

    public Point() {
    }

    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;
    }

    @Override
    public void display() {
        System.out.println("("+getX()+","+getY()+")");
    }
}



 class Line extends Element{
    public Point p1;
    public Point p2;
    String color;

    public Line() {
    }

    public Line(Point p1, Point p2, String color) {
        this.p1 = p1;
        this.p2 = p2;
        this.color = color;
    }

    public Point getP1() {
        return p1;
    }

    public void setP1(Point p1) {
        this.p1 = p1;
    }

    public Point getP2() {
        return p2;
    }

    public void setP2(Point p2) {
        this.p2 = p2;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }
    public double getDistance(){
        double data =  Math.sqrt((p1.getX()- p2.getX())*(p1.getX()-p2.getX())+(p1.getY()-p2.getY())*(p1.getY()-p2.getY()));


        return data;
    }


    @Override
    public void display() {
        System.out.println("The line's color is:"+getColor());
        System.out.println("The line's begin point's Coordinate is:\n" +
                "("+p1.getX()+","+p1.getY()+")");
        System.out.println("The line's end point's Coordinate is:\n" +
                "("+p2.getX()+","+p2.getY()+")");
        System.out.println("The line's length is:"+String.format("%.2f", getDistance()));

    }
}



class Plane extends Element{
    private String color;

    public Plane() {
    }

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

    public String getColor() {
        return color;
    }

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

    @Override
    public void display() {
        System.out.println("The Plane's color is:"+getColor());
    }
}






class GeometryObject {
    ArrayList<Element> array = new ArrayList<>();

    public GeometryObject() {




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

    }
    public void remove(int index){
        array.remove(index-1);



    }

    public ArrayList<Element> getArray() {
        return array;
    }
}




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



分析

本题主要思想其实与上一题大差不差,主要新引入了一个关于抽象父类。

首先常用的Scanner引用创建一个输入的类以便创建输入对象等基础操作自然必不可少,那从面向对象的思想来看,我们先定义一个点的类的对像并存储点的x坐标和y坐标,我们可以使用方法set()和get()来存储和获取点的坐标。然后我们需要考虑如何处理我们所输入的字符串并从中提取出我们需要的各个点的x,y坐标,由于同时存在不同的选项代表不同的需求,这也需要纳入我们的考虑范围之内,我们可以使用正则表达式,通过判断输入的字符串是否符合我们所需要的格式就可以比较轻松的的得知输入的字符串是否符合我们的要求,从而进行不同的判断输出。

将对象类给设计好后再设计一个父类让子类继承其中的方法,将点中的x和y以及颜色给封装好,同时设计好构造方法这样子类就可以不用设计过于复杂的方法,可以方便地获取信息以进行题目中的判定。

三.踩坑心得

1.在使用继承这一特性来设计类时,需要搞清楚各个子类的共性来设计父类中的属性以及通过具体子类的方法来在父类中设计一个大体的方法。

2.要时刻牢记面向对象的核心思想以及它的三个特性继承,封装,多态。要清楚执行操作的对象和执行操作这两者有本质的不同,深刻理解两者的差异可以帮助我们在构建类的框架上能够少走弯路,错路。

四.改进建议

1.在建立输入对象时可以将输入类的对象放在我们其他的一些关键类中。

2.对于类的理解我有了一些更深层次的理解,执行的对象,对象执行的动作,比如题目如果要求有一些输入错误测试,这就可以专门写一个类,将所有的与之相关的类和方法来放入其中,这样在main函数中我们就只需要引入一个类了,代码的逻辑也会更加的清晰。

3.父类的设计可以加入更多的属性和方法来使子类的复用性和改进变得更加的方便和高效。

五.总结

1.首先必须时刻谨记关于面向对象的概念,即面向对象 (Object Oriented,OO) 的思想对软件开发相当重要,它的概念和应用甚至已超越了程序设计和软件开发,扩展到如数据库系统、交互式界面、应用结构、应用平台、分布式系统、网络管理结构、CAD 技术、人工智能等领域。面向对象是一种 对现实世界理解和抽象的方法,是计算机编程技术发展到一定阶段后的产物。

面向过程 (Procedure Oriented) 是一种 以过程为中心 的编程思想。这些都是以什么正在发生为主要目标进行编程,不同于面向对象的是谁在受影响。与面向对象明显的不同就是 封装、继承、类。
2.对于对象的属性和方法必须有清晰的理解执行者和执行者使用的方法之间可谓天差地别。

3。在运用封装,继承和多态时父类的编写是最关键的,这样会大大影响我们子类的改进,需要谨慎严谨和全面.

————————

Four to five summaries of PTA topic collection

I. Preface

Content: difficulty of knowledge points

1. The fourth operation

(1) Knowledge points

7-1. Read input and output, assignment statement and assignment expression, regular expression, loop structure and character reading from the console

7-2. Read input and output from the console, assignment statement and assignment expression, selection structure, complex mathematical calculation, regular expression, loop structure, character reading

7-3. Read input and output, assignment statement and assignment expression, selection structure, loop structure and character reading from the console

(2) Question quantity

Question 7-2 is cumbersome in the classification of categories, and the other two questions are relatively simple

(3) Difficulty

There are many calculation parts in question 7-2. It is necessary to use more complex mathematical calculation methods to avoid major problems. Questions 7-1 and 7-2 are not too difficult to understand. They need a certain basis of regular expressions

(4) Specific topics

7-1. Background introduction:

Jiaolong manned submersible is the first operational deep-sea manned submersible designed by China and developed by China. The designed maximum diving depth is 7000 meters. It is also the operational manned submersible with the strongest diving ability in the world “Jiaolong” < strong > can be used in the vast sea area accounting for 99.8% of the world’s ocean area, which is of great significance to the development and utilization of deep-sea resources in China.

After the United States, France, Russia and Japan, China is the fifth country in the world to master the technology of deep manned submergence. Among the global manned submersibles, < strong > “Jiaolong” belongs to the first echelon < / strong >. At present, there are about 90 manned submersibles in use all over the world, of which only 12 are more than 1000 meters deep, and the number of deeper submersibles is less. At present, the countries with manned submersibles more than 6000 meters deep include China, the United States, Japan, France and Russia. In addition to China, the maximum working depth of the operational manned submersible of the other four countries is 6527 meters of that of Japan. Therefore, the Jiaolong manned submersible successfully reached the < strong > 7020 meters < / strong > seabed in the Mariana Trench in the Western Pacific, creating a new world record of < strong > operational manned submersible < / strong >.

From 2009 to 2012, Jiaolong successively achieved successful sea trials of 1000 meter class, 3000 meter class, 5000 meter class and 7000 meter class< Strong > diving to 7000 meters < / strong >, < strong > shows the maturity of Jiaolong manned submersible integration technology < / strong >, < strong > marks that China’s deep-sea submersible has become one of the frontier and commanding heights of marine scientific investigation < / strong >.

At 11:47 on June 27, 2012, China’s “Jiaolong” refreshed its “China depth” – diving 7062 meters. The “Jiaolong” has set a new record of “665 meters” for 15 consecutive months; June 19, 6965 meters; June 22, 6963 meters; June 24, 7020 meters; June 27, 7062 meters< Strong > diving to 7000 meters marks that China has the ability to reach more than 99% of the global ocean depths for manned operations, marks the maturity of the “Jiaolong” manned submersible integration technology, marks that China’s deep-sea submersible has become one of the frontier and commanding heights of marine scientific investigation, and marks that China’s submarine manned scientific research and resource exploration capacity has reached the international leading level < / strong >.

Jiaolong is an important milestone in the development of manned deep diving in China. It is not only a deep-sea equipment, but also represents a spirit, a spirit of fearing difficulties and dangers and catching up with the world. It is the horn for the Chinese nation to march into the deep sea.

Learn about the remarkable achievements of Jiaolong manned submersible, and be proud that China’s submarine manned scientific research and resource exploration capabilities have reached the international leading level. Our partners share the same breath and destiny with our motherland. We must learn scientific and cultural knowledge, improve personal ability, enhance innovation awareness, strive for excellence, and establish the ambition of science and technology to serve the country!

Please write a program to realize the following functions: read in the multi line string of the exploration data of Jiaolong manned submersible, find out the numeric characters from the given information, and output the sum of the numbers in each line.

< strong > prompt < / strong > if the input is February 2012, the output of this line is 2014. Several consecutive numeric characters are added as a whole in decimal form.

7-2. The user enters a set of options and data for quadrilateral related calculations.
The coordinates of the following quadrilateral vertices are required to be input in sequence. The two vertices input continuously are adjacent vertices, and the first and last input vertices are adjacent.
Options include:
1: Enter the coordinates of four points to judge whether they are quadrilateral and parallelogram. The judgment result outputs true / false, and the results are separated by an English space character.
2: Enter the coordinates of four points to judge whether they are diamond, rectangle and square. The judgment result outputs true / false, and the results are separated by an English space character. If the coordinates of four points cannot form a quadrilateral, output “not a quadrilateral”
3: Enter the coordinates of four points, judge whether it is a concave quadrilateral (false) or a convex quadrilateral (true), and output the perimeter and area of the quadrilateral. The results are separated by an English space character. If the coordinates of four points cannot form a quadrilateral, output “not a quadrilateral”
4: Input six point coordinates. The first two points form a straight line, and the last four points form a quadrilateral or triangle. Output the number of intersections between the straight line and the quadrilateral (or triangle). If there are two intersections, output the area of quadrilateral (or triangle) divided into two parts by a straight line from small to large (no line break). If the line coincides with one of the lines of a quadrilateral or triangle, output “the line is coincide with one of the lines”. If the last four points do not conform to the input of quadrilateral or triangle, output “not a quadrilateral or triangle”.
The last four points form a triangle: suppose that the two endpoints on one side of the triangle are x and Y respectively, there is a point Z in the middle of the edge line, and the other vertex s:
1) Qualified input: vertices are repeated or Z and XY are adjacent, such as x x y s, x z y s, x y x s, s x y y y. At this time, the redundant points are removed and one X and one y are reserved.
2) Unqualified input: Z is not adjacent to XY, such as Z x y s, x z s y, x s Z y
5: Input the coordinates of five points and output whether the first one is inside the quadrilateral (limited to convex quadrilateral, regardless of concave quadrilateral) or triangle (see option 4 for judgment method) (if quadrilateral, output in the quadrilateral / out of the quadrilateral; if triangle, output in the triangle / out of the triangle). If the point is on an edge of the polygon, output “on the triangle or on the quadrilateral”. If the last four points do not conform to quadrilateral or triangle, output “not a quadrilateral or triangle”.

7-3. Write a banking business class bankbusiness, which has the following properties and methods:
(1) Public and static attributes: bank name, and the initial value is “Bank of China”.
(2) Private attributes: account name, password and account balance.
(3) The welcome action (static and public method) of the bank to the user shows “Bank of China welcomes you!”, Bank of China automatically uses the value of bankname.
(4) The bank’s welcome next action (static and public method) to remind users to leave displays “please take away your certificates and items, and welcome to visit next time!”
(5) The construction method with parameters completes the account opening operation. The account name, password and password information are required, and the account balance is 0.
(6) The user’s deposit operation (public method, which requires password and transaction amount information). When the password is wrong, you can’t deposit and prompt “your password is wrong!”; After the password is correct and the user completes the deposit operation, you should prompt the user’s account balance, for example, “your balance is 1000.0 yuan.”.
(7) Withdrawal operation of the user (public method, requiring password and transaction amount information). When the password is wrong, you can’t withdraw money and prompt “your password is wrong!”; When the password is correct but the balance is insufficient, you will be prompted with “your balance is insufficient!”; When the password is correct and the balance is sufficient, the transaction amount will be deducted and the user’s account balance will be prompted, such as “please take away the banknote, your balance still has 500.0 yuan.”.

Write a test class main. In the main method, perform the following operations successively:
(1) Call the welcome () method of the bankbusiness class.
(2) Receive the user name and password information entered by the keyboard as parameters, and call the construction method with parameters of bankbusiness class to create an object account of bankbusiness class.
(3) Call the deposit method of account, enter the correct password and deposit several yuan. The password and deposit amount are entered from the keyboard.
(4) Call the withdrawal method of account, enter the wrong password and try to withdraw several yuan. The password and withdrawal amount are entered from the keyboard.
(5) Call the withdrawal method of account, enter the correct password and try to withdraw several yuan (the withdrawal amount is greater than the balance). The password and withdrawal amount are entered from the keyboard.
(6) Call the withdrawal method of account, enter the correct password and try to withdraw several yuan (the withdrawal amount is less than the balance). The password and withdrawal amount are entered from the keyboard.
(7) Call the welcomenext() method of bankbusiness class.

Input format:

Enter the name and password required for opening an account
Enter the correct password and deposit amount
Input wrong password and withdrawal amount
Enter the correct password and the withdrawal amount greater than the balance
Enter the correct password and the withdrawal amount less than the balance

Output format:

Welcome to Bank of China (bank name)!
How much is your balance.
Your password is wrong!
Your balance is insufficient!
Please take the money. How much yuan do you have left.
Please keep your certificates and articles. Welcome to visit next time!

2. The fifth operation

(1) Knowledge points

7-1. Read input and output from the console, assignment statement and assignment expression, selection structure, acquisition of string and substring, regular expression, circular structure, character reading

7-2. Read input and output from the console, assignment statement and assignment expression, select structure, simple mathematical calculation, acquisition of string and substring, regular expression and circular structure

(2) Question quantity

Due to the depth and complexity of choice judgment and the complexity of calculation, the consumption of code and logical thinking is very high

(3) Difficulty

Questions 7-1 and 7-2 are quite difficult and the structure is very complex.

(4) Specific topics

7-1 the user inputs a set of options and data to perform calculations related to pentagons.
The coordinates of the following pentagonal vertices are required to be input in sequence. The two vertices input continuously are adjacent vertices, and the first and last input vertices are adjacent.
Options include:
1: Enter the coordinates of five points to judge whether it is a Pentagon, and the judgment result outputs true / false.
2: Input five point coordinates to judge whether it is a concave Pentagon (false) or a convex Pentagon (true). If it is a convex Pentagon, then output the perimeter and area of the Pentagon, and the results are separated by an English space character. If the five point coordinates cannot form a Pentagon, output “not a Pentagon”
3: Input seven point coordinates. The first two points form a straight line, and the last five points form a convex Pentagon, convex quadrilateral or convex triangle. Output the number of intersections between the straight line and the Pentagon, quadrilateral or triangle. If there are two intersections, output the area divided into two parts by a straight line from small to large (no line break). If the line coincides with one of the lines of the polygon, output “the line is coincide with one of the lines”. If the last five points do not conform to the pentagonal input, if the first two points coincide, output “points coincide”.

In the above three options, “not a polygon” is output if the input points cannot form a polygon. The input coordinates of the five points may be redundant. Suppose that the two endpoints on one edge of the polygon are x and Y respectively, there is a point Z in the middle of the edge line, and the other vertex s:
1) Qualified input: vertices are repeated or Z and XY are adjacent, such as x x y s, x z y s, x y x s, s x y y y. At this time, the redundant points are removed and one X and one y are reserved.
2) Unqualified input: Z is not adjacent to XY, such as Z x y s, x z s y, x s Z y

7-2 the user inputs a set of options and data to perform calculations related to pentagons.
The coordinates of the following pentagonal vertices are required to be input in sequence. The two vertices input continuously are adjacent vertices, and the first and last input vertices are adjacent.
Options include:
4: Enter the coordinates of ten points. The first and last five points form a convex polygon (triangle, quadrilateral and Pentagon) respectively, and judge whether there is an inclusion relationship between them (a polygon has one or more edges that coincide with another polygon, and other parts are included in another polygon, which is also included).
There are six relationships between the two: 1. Separation (no coincident points at all) 2. Connection (only one point or one edge coincides) 3. Complete coincidence 4. Inclusion (the former polygon is inside the latter polygon) 5. Interleaving 6. Inclusion (the latter polygon is inside the former polygon).
The output formats of various relationships are as follows:
1、no overlapping area between the previous triangle/quadrilateral/ pentagon and the following triangle/quadrilateral/ pentagon
2、the previous triangle/quadrilateral/ pentagon is connected to the following triangle/quadrilateral/ pentagon
3、the previous triangle/quadrilateral/ pentagon coincides with the following triangle/quadrilateral/ pentagon
4、the previous triangle/quadrilateral/ pentagon is inside the following triangle/quadrilateral/ pentagon
5、the previous triangle/quadrilateral/ pentagon is interlaced with the following triangle/quadrilateral/ pentagon
6、the previous triangle/quadrilateral/ pentagon contains the following triangle/quadrilateral/ pentagon

5: Input the coordinates of ten points. The first and last five points form a convex polygon (triangle, quadrilateral and Pentagon) respectively, and output the area of the common area of the two polygons. Note: only consider the case that each polygon is divided into at most two parts by another polygon, and do not consider the case that one polygon divides the other into more than two areas.
6: Input the coordinates of six points and output whether the first one is inside the polygon formed by the last five points (limited to convex polygon, regardless of concave polygon) (output in the Pentagon / outof the Pentagon, output in the quadrilateral / outof the quadrilateral, and output in the triangle / outof the triangle). Input errors have redundant points to be eliminated. See option 5 for the judgment method of redundant points. If the point is on an edge of the polygon, output “on the triangle / on the quadrilateral / on the Pentagon”.
The coordinates of the five points input in options 4, 5 and 6 above may be redundant. Suppose that the two endpoints on one edge of the polygon are x and Y respectively, there is a point Z in the middle of the edge line, and the other vertex s:
1) Qualified input: vertices are repeated or Z and XY are adjacent, such as x x y s, x z y s, x y x s, s x y y y. At this time, the redundant points are removed and one X and one y are reserved.
2) Unqualified input: Z is not adjacent to XY, such as Z x y s, x z s y, x s Z y

3. Interim

(1) Knowledge points

7-1. Read input and output from the console, assignment statement and expression, select structure, create class, reference of class and method, complex calculation and selection judgment.

7-2. Read input and output from the console, assignment statements and expressions, select structures, create classes, reference classes and methods, select judgments, and perform more complex calculations.

7-3. Read input and output from the console, assignment statements and assignment expressions, select structures, simple mathematical calculations, circular structures, class creation, and references to classes and methods.

(2) Question quantity

The three questions 7-1, 2 and 3 are similar in class creation, but require the inheritance and polymorphism of the parent class on the basis.

(3) Difficulty

The difficulty of 7-1, 7-2 and 7-3 is becoming more and more complicated for me.

(4) Specific topics

7-1 design a class to represent the point on the plane rectangular coordinate system. The private attributes are abscissa X and ordinate y respectively. The data types are real numbers. In addition to the construction method and the getter and setter methods of the attribute, define a method for displaying information display (), which is used to output the coordinate information of the coordinate point. The format is as follows: the value retains two decimal places.

(x,y)

7-2 based on the topic of “point and line (class design)”, the class design of the topic is reconstructed to realize the technical requirements of inheritance and polymorphism.

  • Further abstract the point class and line class in the topic, define a common parent class element (abstract class) of the two classes, declare the display () method in this method (abstract method), and take the point class and line class as the subclasses of this class.
  • Then define a subclass of element class plane, which has only one private attribute color. In addition to the getter and setter methods of construction method and attribute, the display () method is used to output the color of the surface. The output format is as follows: the plane’s color is: color
  • In the main method, define two point objects, a line object and a plane object, input the coordinates and color values of the two point objects from the keyboard in turn (the color of the line object and the plane object are the same), then define a reference of the element class, and use this reference to call the display () method of the above four objects respectively, so as to realize the polymorphism. The example code is as follows

7-3 on the basis of “point and line (inheritance and polymorphism)”, reconstruct the class design of the subject, add a container class to save point, line and surface objects, and add, delete and traverse the container accordingly.

  • On the basis of the original class design, add a geometryobject container class whose attribute is an object of ArrayList < element > (if you don’t know generics, you can not use < element >)
  • The add () method and remove (int index) method of this class are added. Their functions are to add objects to the container and delete the index – 1 (index > = 0 in ArrayList) object respectively
  • In the main method, the user circularly inputs the operation to be performed (choice ∈ [0,4]), which has the following meanings:
    1: Add a point object to the container
    2: Add a line object to the container
    3: Add plane to container
    4: Delete the index – 1 data in the container. If the index data is illegal, ignore this operation
    0: end of input
  • 1: Add a point object to the container
  • 2: Add a line object to the container
  • 3: Add plane to container
  • 4: Delete the index – 1 data in the container. If the index data is illegal, ignore this operation
  • 0: end of input

II Design and analysis

1. Topic set IV 7-2

Design and analysis of the topic

Source code design

OK, go to the source code first

import java.util.Scanner;
import java.util.ArrayList;
import java.text.DecimalFormat;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		String str = in.nextLine();
		Input input = new Input();
		ArrayList<String> a = new ArrayList();
		input.formatIsLegal(str, a);
		ArrayList<Double> b = new ArrayList();
		ArrayList<Point> c = new ArrayList();
		if(a.size()!=0)
		{
			Change change = new Change();
			change.StringToInt(a, b);
			change.listPoints(b, c);
			String s = str.substring(0,1);
			Quadrilateral q = new Quadrilateral();
			switch(s)
			{
			 /*	case "1":
			 		if(!input.numIsLegal(c, 4))
				 	{
				 		System.out.println("wrong number of points");
				 	}
			 		else
			 		{
			 			Point[] p = new Point[4];
			 			for(int i=0;i<4;i++)
			 			{
			 				p[i]=c.get(i);
			 			}
			 			if(q.isCoincident(p,4))
			 			{
			 				System.out.println("points coincide");
			 			}
			 			else
			 			{
			 				System.out.println(q.isQuadrilateral(p)+" "+q.isParallelogram(p));
			 			}
			 		}
			 		break;  */
			 	case "2":
			 		if(!input.numIsLegal(c, 4))
				 	{
				 		System.out.println("wrong number of points");
				 	}
			 		else
			 		{
			 			Point[] p = new Point[4];
			 			for(int i=0;i<4;i++)
			 			{
			 				p[i]=c.get(i);
			 			}
			 			if(q.isCoincident(p,4))
			 			{
			 				System.out.println("not a quadrilateral");
			 			}
			 			else
			 			{
			 				if(!q.isQuadrilateral(p))
			 				{
			 					System.out.println("not a quadrilateral");
			 				}
			 				else
			 				{
			 					System.out.println(q.isDiamond(p)+" "+q.isRectangle(p)+" "+q.isSquare(p));
			 				}
			 			}
			 		}
			 		break;
			 	case "3":
			 		if(!input.numIsLegal(c, 4))
				 	{
				 		System.out.println("wrong number of points");
				 	}
			 		else
			 		{
			 			Point[] p = new Point[4];
			 			for(int i=0;i<4;i++)
			 			{
			 				p[i]=c.get(i);
			 			}
			 			if(q.isCoincident(p,4))
			 			{
			 				System.out.println("not a quadrilateral");
			 			}
			 			else
			 			{
			 				if(!q.isQuadrilateral(p))
			 				{
			 					System.out.println("not a quadrilateral");
			 				}
			 				else
			 				{
			 					System.out.println(q.isConvex(p)+" "+q.Perimeter(p)+" "+q.Area(p));
			 				}
			 			}
			 		}
			 		break;
			/* 	case "4":
			 		if(!input.numIsLegal(c, 6))
				 	{
				 		System.out.println("wrong number of points");
				 	}
			 		else
			 		{
			 			Point[] p = new Point[4];
			 			Point[] l = new Point[2];
			 			for(int i=0;i<4;i++)
			 			{
			 				p[i]=c.get(i+2);
			 			}
			 			for(int i=0;i<2;i++)
			 			{
			 				l[i]=c.get(i);
			 			}
			 			if(q.isCoincident(p,2))
			 			{
			 				System.out.println("points coincide");
			 			}
			 			else
			 			{
			 				if(!q.isQuadrilateral(p)&&q.isTriangle(p)==-1)
			 				{
			 					System.out.println("not a quadrilateral or triangle");
			 				}
			 				else
			 				{
			 					
			 				}
			 			}
			 			
			 		}   */
			 	case "5":if(!input.numIsLegal(c, 5))
			 	{
			 		System.out.println("wrong number of points");
			 	}
		 		else
		 		{
		 			Point[] p = new Point[4];
		 			Point l = new Point(c.get(0).getx(),c.get(0).gety());
		 			for(int i=0;i<4;i++)
		 			{
		 				p[i]=c.get(i+1);
		 			}
		 			if(!q.isQuadrilateral(p)&&q.isTriangle(p)==-1)
	 				{
	 					System.out.println("not a quadrilateral or triangle");
	 				}
	 				else if(q.isQuadrilateral(p))
	 				{
	 					if(q.raymethod(l, p, 4)==0)
	 					{
	 						System.out.println("outof the quadrilateral");
	 					}
	 					else if(q.raymethod(l, p, 4)==1)
	 					{
	 						System.out.println("in the quadrilateral");
	 					}
	 					else
	 					{
	 						System.out.println("on the quadrilateral");
	 					}
	 				}
	 				else
	 				{
	 					Point[] t = new Point[3];
	 					if(q.isTriangle(p)==0)
	 					{
	 						t[0] = new Point(p[1].getx(),p[1].gety());
	 						t[1] = new Point(p[2].getx(),p[2].gety());
	 						t[2] = new Point(p[3].getx(),p[3].gety());
	 						if(q.raymethod(l, t, 3)==0)
		 					{
		 						System.out.println("outof the triangle");
		 					}
		 					else if(q.raymethod(l, t, 3)==1)
		 					{
		 						System.out.println("in the triangle");
		 					}
		 					else
		 					{
		 						System.out.println("on the triangle");
		 					}
	 					}
	 					else if(q.isTriangle(p)==1)
	 					{
	 						t[0] = new Point(p[0].getx(),p[0].gety());
	 						t[1] = new Point(p[2].getx(),p[2].gety());
	 						t[2] = new Point(p[3].getx(),p[3].gety());
	 						if(q.raymethod(l, t, 3)==0)
		 					{
		 						System.out.println("outof the triangle");
		 					}
		 					else if(q.raymethod(l, t, 3)==1)
		 					{
		 						System.out.println("in the triangle");
		 					}
		 					else
		 					{
		 						System.out.println("on the triangle");
		 					}
	 					}
	 					else if(q.isTriangle(p)==2)
	 					{
	 						t[0] = new Point(p[0].getx(),p[0].gety());
	 						t[1] = new Point(p[1].getx(),p[1].gety());
	 						t[2] = new Point(p[3].getx(),p[3].gety());
	 						if(q.raymethod(l, t, 3)==0)
		 					{
		 						System.out.println("outof the triangle");
		 					}
		 					else if(q.raymethod(l, t, 3)==1)
		 					{
		 						System.out.println("in the triangle");
		 					}
		 					else
		 					{
		 						System.out.println("on the triangle");
		 					}
	 					}
	 					else 
	 					{
	 						t[0] = new Point(p[0].getx(),p[0].gety());
	 						t[1] = new Point(p[1].getx(),p[1].gety());
	 						t[2] = new Point(p[2].getx(),p[2].gety());
	 						if(q.raymethod(l, t, 3)==0)
		 					{
		 						System.out.println("outof the triangle");
		 					}
		 					else if(q.raymethod(l, t, 3)==1)
		 					{
		 						System.out.println("in the triangle");
		 					}
		 					else
		 					{
		 						System.out.println("on the triangle");
		 					}
	 					}
	 					
	 				}
		 			
		  		}
			}
		}
	}

}
class Input
{
	public boolean choiceIsLegal(String str)
	{
		if(str.matches("[1-5]:.+"))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	public boolean pointIsLegal(String str)
	{
		if(str.matches("[+-]?([1-9]\\d*|0)(\\.\\d+)?,[+-]?([1-9]\\d*|0)(\\.\\d+)?"))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	public void formatIsLegal(String str,ArrayList<String> a)
	{
		if(choiceIsLegal(str))
		{
			String str1 = str.substring(2);
			String[] s1 = str1.split(" ");
			boolean flag = true;
			for(int i=0;i<s1.length;i++)
			{
				if(!pointIsLegal(s1[i]))
				{
					System.out.println("Wrong Format");
					flag = false;
					break;
				}
			}
			if(flag)
			{
				for(int i=0;i<s1.length;i++)
				{
					String[] s2 = s1[i].split(",");
					a.add(s2[0]);
					a.add(s2[1]);
				}
			}
		}
		else
		{	
			System.out.println("Wrong Format");
		}
	}
	public boolean numIsLegal(ArrayList<Point> c,int num)
	{
		if(c.size()==num)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}
class Change
{
	public void StringToInt(ArrayList<String> a,ArrayList<Double> b)
	{
		for(int i=0;i<a.size();i++)
		{
			b.add(Double.parseDouble(a.get(i)));
		}
	}
	public void listPoints(ArrayList<Double> b,ArrayList<Point> c)
	{
		for(int i=0;i<b.size();i+=2)
		{
			Point p = new Point(b.get(i),b.get(i+1));
			c.add(p);
		}
	}
}
class Output
{
	
}
class Point
{
	private double x,y;
	Point(double x,double y)
	{
		this.x = x;
		this.y = y;
	}
	public void setx(double x)
	{
		this.x = x;
	}
	public double getx()
	{
		return x;
	}
	public void sety(double y)
	{
		this.y = y;
	}
	public double gety()
	{
		return y;
	}
}
class Line
{
	Point p1;
	Point p2;
	Line(Point p1,Point p2)
	{
		this.p1 = p1;
		this.p2 = p2;
	}
	public static double distance(Point p1,Point p2)
	{
		double x = Math.pow(p1.getx()-p2.getx(),2);
		double y = Math.pow(p1.gety()-p2.gety(),2);
		return Math.sqrt(x+y);
	}
}
class Quadrilateral
{
	public boolean isCoincident(Point[] p,int num)
	{
		for(int i=0;i<num;i++)
		{
			for(int j=i+1;j<num;j++)
			{
				if(p[i].getx()==p[j].getx()&&p[i].gety()==p[j].gety())
				{
					return true;
				}
			}
		}
		return false;
	}
	public boolean isQuadrilateral(Point[] p)
	{
		if((p[0].getx()-p[1].getx())*(p[1].gety()-p[2].gety())==(p[1].getx()-p[2].getx())*(p[0].gety()-p[1].gety()))
		{
			return false;
		}
		else if((p[1].getx()-p[2].getx())*(p[2].gety()-p[3].gety())==(p[2].getx()-p[3].getx())*(p[1].gety()-p[2].gety()))
		{
			return false;
		}
		else if((p[2].getx()-p[3].getx())*(p[3].gety()-p[0].gety())==(p[3].getx()-p[0].getx())*(p[2].gety()-p[3].gety()))
		{
			return false;
		}
		else if((p[3].getx()-p[0].getx())*(p[0].gety()-p[1].gety())==(p[0].getx()-p[1].getx())*(p[3].gety()-p[0].gety()))
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	public boolean isParallelogram(Point[] p)
	{
		if(isQuadrilateral(p))
		{
			if(p[0].getx()+p[2].getx()==p[1].getx()+p[3].getx()&&p[0].gety()+p[2].gety()==p[1].gety()+p[3].gety())
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	
	public boolean isDiamond(Point[] p)
	{
		if(isParallelogram(p))
		{
			if(Line.distance(p[0],p[1])==Line.distance(p[1],p[2]))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	public boolean isRectangle(Point[] p)
	{
		if(isParallelogram(p))
		{
			if(Line.distance(p[0],p[2])==Line.distance(p[1],p[3]))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	public boolean isSquare(Point[] p)
	{
		if(isParallelogram(p))
		{
			if(Line.distance(p[0],p[1])==Line.distance(p[1],p[2])&&Line.distance(p[0],p[2])==Line.distance(p[1],p[3]))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	public boolean isConvex(Point[] p)
	{
		double t1 = (p[0].getx()-p[1].getx())*(p[1].gety()-p[2].gety())-(p[1].getx()-p[2].getx())*(p[0].gety()-p[1].gety());
		double t2 = (p[1].getx()-p[2].getx())*(p[2].gety()-p[3].gety())-(p[2].getx()-p[3].getx())*(p[1].gety()-p[2].gety());
		double t3 = (p[2].getx()-p[3].getx())*(p[3].gety()-p[0].gety())-(p[3].getx()-p[0].getx())*(p[2].gety()-p[3].gety());
		double t4 = (p[3].getx()-p[0].getx())*(p[0].gety()-p[1].gety())-(p[0].getx()-p[1].getx())*(p[3].gety()-p[0].gety());
		if(t1*t2*t3*t4>0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	public String Perimeter(Point[] p)
	{
		double c = Line.distance(p[0],p[1])+Line.distance(p[1],p[2])+Line.distance(p[2],p[3])+Line.distance(p[3],p[0]);
		String t = new DecimalFormat("#.0##").format(c);
		return t;
	}
	public String Area(Point[] p)
	{
		double a1 = Line.distance(p[0],p[1]);
		double b1 = Line.distance(p[3],p[0]);
		double a2 = Line.distance(p[1],p[2]);
		double b2 = Line.distance(p[2],p[3]);
		double c1 = Line.distance(p[1],p[3]);
		double p1 = (a1+b1+c1)/2;
		double p2 = (a2+b2+c1)/2;
		double s1 = Math.sqrt(p1*(p1-a1)*(p1-b1)*(p1-c1));
		double s2 = Math.sqrt(p2*(p2-a2)*(p2-b2)*(p2-c1));
		double a3 = Line.distance(p[0],p[1]);
		double b3 = Line.distance(p[1],p[2]);
		double a4 = Line.distance(p[0],p[3]);
		double b4 = Line.distance(p[3],p[2]);
		double c2 = Line.distance(p[2],p[0]);
		double p3 = (a3+b3+c2)/2;
		double p4 = (a4+b4+c2)/2;
		double s3 = Math.sqrt(p3*(p3-a3)*(p3-b3)*(p3-c2));
		double s4 = Math.sqrt(p4*(p4-a4)*(p4-b4)*(p4-c2));
		double s;
		if(s1+s2<=s3+s4)
		{
			s = s1+s2;
		}
		else
		{
			s = s3+s4;
		}
		return new DecimalFormat("#.0##").format(s);
	}
	public int isTriangle(Point[] p)
	{
		for(int i=0;i<4;i++)
		{
			Point m = p[i];
			Point n = p[(i+1)%4];
			Point s = p[(i+2)%4];
			Point t = p[(i+3)%4];
			if((m.getx()-n.getx())*(m.gety()-t.gety())==(m.getx()-t.getx())*(m.gety()-n.gety())&&(s.getx()-n.getx())*(s.gety()-t.gety())!=(s.getx()-t.getx())*(s.gety()-n.gety()))
			{
				return i;
			}
		}
		return -1;
	}
	public int raymethod(Point l,Point[] p,int num)
	{
		int s=0;
		for(int i=0;i<num;i++)
		{
			Point m = p[i];
			Point n = p[(i+1)%num];
				if(m.gety()==n.gety()||l.gety()>Math.max(m.gety(),n.gety())||l.gety()<Math.min(m.gety(), n.gety()))
				{
					if(l.gety()==m.gety()&&l.getx()<Math.max(m.getx(), n.getx())&&l.getx()>Math.min(m.getx(), n.getx()))
					{
						return -1;
					}
					continue;
				}
				
				double x = (l.gety()-m.gety())*(n.getx()-m.getx())/(n.gety()-m.gety())+m.getx();
				if(x>l.getx())
				{
					s++;
				}
				if(x==l.getx())
				{
					return -1;
				}
			}
		if(s%2==0)
		{
			return 0;
		}
		else 
		{
			return 1;
		}
		
	
	}
}

analysis

First of all, the common scanner reference creates an input class, so that basic operations such as creating input objects are naturally essential. Let’s first plan the input object we create, which is not as good as in our main. At the same time, all our inputs are written together in an output class. Whether the input is correct or not is judged in the legal method in the output class. Further, in the legal method, we should convert our string into an integer array, At that time, we can use various methods on dealing with specific calculation and other problems written later in the legal method.

Then use regular expressions in legal to judge whether the input is legal or not with if structure. Different types of errors have different output statements. If it is correct, we only need to calculate and judge according to the type of string obtained. Encapsulate the X and both in the coordinates and write the method at the same time to calculate the slope distance of the line and other data we need in the subject to judge whether it is a triangle, quadrilateral, etc.

2. Topic set V 7-1

Design and analysis of the topic

Source code design

OK, go to the source code first

import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Pattern;

class Main
{
    public static void main(String[] args)
    {
        ArrayList ps = new ArrayList();
        int a=0;
        int b = 4;
        for ( b=4;b<40;b++){
            if (b==36){
                break;
            }
        }
        Scanner input = new Scanner(System.in);
        String str = input.nextLine();
        Getnumber number = new Getnumber();
        Select sel = new Select();
        int select;
        double[] num = new double[100];
        num = number.get_number(str);//获取数字,储存在数组里
        select = number.dealnum(num,str);
        for (a=0;a<40;a++){
            if (a==36){
                break;
            }
        }

        switch(select)
        {
            case 1://选择1
                sel.select1(num,select);
                break;
            case 2:
                sel.select2(num, select);
                break;
            case 3:
                sel.select3(num,select);
                break;
        }

        input.close();
    }

}



class Getnumber
{

    public Getnumber()
    {

    }

    //判断输入是否正确
    public boolean ifright(String str)
    {
        for (int a=0;a<40;a++){
            if (a==36){
                break;
            }
        }
        boolean flag;
        //flag = false;
//		String pattern = "^[1-5]:(-)?(\\+)?\\d+(.)?(\\d+)?,(-)?(\\+)?\\d+(.)?(\\d+)?( (-)?(\\+)?\\d+(.)?(\\d+)?,(-)?(\\+)?\\d+(.)?(\\d+)?)?( (-)?(\\+)?\\d+(.)?(\\d+)?,(-)?(\\+)?\\d+(.)?(\\d+)?)?( (-)?(\\+)?\\d+(.)?(\\d+)?,(-)?(\\+)?\\d+(.)?(\\d+)?)?( (-)?(\\+)?\\d+(.)?(\\d+)?,(-)?(\\+)?\\d+(.)?(\\d+)?)?( (-)?(\\+)?\\d+(.)?(\\d+)?,(-)?(\\+)?\\d+(.)?(\\d+)?( )?)?";//正则表达式,判断格式
        String pattern = "^[1-5]:((-)?(\\+)?\\d+(.)?(\\d+)?,(-)?(\\+)?\\d+(.)?(\\d+)?( )?){1,}";//正则表达式,判断格式
        flag = Pattern.matches(pattern,str);
        if(flag){
            for (int a=0;a<40;a++){
                if (a==36){
                    break;
                }
            }
            return true;}
        return false;

    }

    //获取数字
    public double[] get_number(String s)
    {
        int i,k,n,m,count,f;
        f = 1;
        m = 1;
        double num,j;
        double[] number = new double[100];
        for(i = 2;i < s.length();i+=(count+1))
        {

            for (int a=0;a<40;a++){
                if (a==36){
                    break;
                }
            }
            num = 0.0;
            j = 0.1;
            k = 0;
            n = 1;
            f = 1;
            count = 0;
            for(n = i;n<s.length()&&s.charAt(n)!=','&&s.charAt(n)!=' ';n++)
            {
                for (int b=0;b<40;b++){
                    if (b==36){
                        break;
                    }
                }

                count++;
                if(s.charAt(n)=='-')
                {
                    for (int a=0;a<40;a++){
                        if (a==36){
                            break;
                        }
                    }
                    f = 0;
                }
                if(s.charAt(n)!='.'&& k==0&&s.charAt(n)>='0'&&s.charAt(n)<='9')
                {
                    num = s.charAt(n)-48  + num *10;//小数点之前获取整数
                }
                if(s.charAt(n)=='.')
                {
                    for (int a=0;a<40;a++){
                        if (a==36){
                            break;
                        }
                    }
                    k = 1;//读取到小数点
                }
                if(k == 1&&s.charAt(n)>='0'&&s.charAt(n)<='9')
                {
                    num = num + (s.charAt(n)-48) * j;//获取小数点之后
                    j = j * 0.1;
                }
            }
            if(f==0)
            {
                for (int a=0;a<40;a++){
                    if (a==36){
                        break;
                    }
                }
                number[m] = -num;
            }
            else number[m] = num;
            m++;

        }
        number[0] = m-1;//第一个数字储存数字个数
        return number;
    }

    //判断输入数字个数是否正确,数字正确返回“true”,不正确“false”
    public boolean ifRnum(double m,int n)
    {
        int x,y;
        y = 0;
        x = (int)m;
        if(n==1||n==2){
            for (int a=0;a<40;a++){
                if (a==36){
                    break;
                }
            }
            y = 10;}
        if(n == 3)
            y = 14;
        if(n == 4||n==5)
            y = 20;
        if(n==6)
            y = 12;
        if(x==y)
            return true;
        return false;
    }

    //是否有点重合
    public boolean isnotsame1(Point a,Point b,Point c,Point d)
    {
        boolean f1,f2,f3,f4,f5,f6;
        f1 = a.pointsame(a, b);
        f2 = a.pointsame(a, c);
        f3 = a.pointsame(a, d);
        f4 = a.pointsame(b, c);
        f5 = a.pointsame(d, b);
        f6 = a.pointsame(c, d);
        if(f1&&f2&&f3&&f4&&f5&&f6){
            int m = 0;
            for ( m=0;m<40;m++){
                if (m==36){
                    break;
                }
            }
            return false;}
        return true;

    }

    //处理数字出现各种错误,如果没错返回选择
    public int dealnum(double[] num,String str)
    {
        Getnumber ber = new Getnumber();
        boolean f1,f2,f3;
        int select;
        select =(int)(str.charAt(0)-48);
        f1 = ber.ifright(str);
        f2 = ber.ifRnum(num[0],select);
        if(!f1)
        {
            for (int a=0;a<40;a++){
                if (a==36){
                    break;
                }
            }
            System.out.println("Wrong Format");
            System.exit(0);
        }
        if(!f2)
        {
            for (int a=0;a<40;a++){
                if (a==36){
                    break;
                }
            }
            System.out.println("wrong number of points");
            System.exit(0);
        }
        return select;

    }

    //判断应该出现多少个数字
    public int getrightnum(int n)
    {
        int a = 4;
        int j = 4;
        if (a==4) {
            a=40;
        }
            if (n == 1 || n == 2){
                for (int h=0;h<40;h++){
                    if (h==36){
                        break;
                    }
                }
                return 10;}
            if (n == 3){
                if (j==4) {
                    j=40;
                }
                return 14;}
            if (n == 4 || n == 5)
                return 20;
            if (n == 6)
                return 12;

        return 0;

    }

    //输出格式处理
    public void output(double m)
    {
        //出现2.99999999转成2
        //****************
        int n1,n2;
        n1 = (int)m;
        n2 = (int)m+1;
        if(Math.abs(m-n1)<1e-5||Math.abs(m-n2)<1e-5) {
            System.out.printf("%.1f", m);
            for (int h=0;h<40;h++){
                if (h==36){
                    break;
                }
            }
        }
        else
            System.out.printf("%.3f",m);
    }


}



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

    double x;
    double y;

    public Point()
    {

    }

    //构造点
    public Point(double  a,double b)
    {
        this.x = a;
        this.y = b;
    }

    //判断点是否重合,重合返回“false”,不重合返回“true”
    public boolean pointsame(Point a,Point b)
    {
        for (int h=0;h<40;h++){
            if (h==36){
                break;
            }
        }
        if(a.x==b.x&&a.y==b.y)
            return false;
        return true;
    }

    //获取了两个点中x坐标更大的点的坐标
    public double getxmax(Point a,Point b)
    {
        int l = 4;
        int y;
        if (l == 4) {
            y=6;

        }
        if(a.x>b.x)
            return a.x;
        else return b.x;
    }

    //获取了两个点中y坐标更大的点的坐标
    public double  getymax(Point a,Point b)
    {
        int l = 4;
        int y;
        if (l == 4) {
            y=6;

        }
        if(a.y>b.y)
            return a.y;
        else return b.y;
    }

    //获取了两个点中x坐标更小的点的坐标
    public double getxmin(Point a,Point b)
    {
        int l = 4;
        int y;
        if (l == 4) {
            y=6;

        }
        if(a.x>b.x)
            return b.x;
        else return a.x;
    }

    //获取了两个点中y坐标更小的点的坐标
    public double getymin(Point a,Point b)
    {
        if(a.y>b.y){
            int l = 4;
            int y;
            if (l == 4) {
                y=6;

            }
            return b.y;}
        else return a.y;
    }

    //将点放在点的数组中去
    public Point[] sumpoint(double[] sum,int n)
    {
        Point[] allpoint = new Point[20];
        int i,j,m;
        j = 0;
        Getnumber num = new Getnumber();
        m = num.getrightnum(n);
        for(i = 1;i < m;i+=2)
        {
            Point a = new Point(sum[i],sum[i+1]);
            allpoint[j] = a;
            j++;
        }
        return allpoint;
    }
}

//有关线的类
class Line
{
    int f;//斜率是否存在
    double A;//斜率
    double B;//常数项
    Point a3;//表示两点向量方向的点
    Point a1,a2;//线上两个点
    double x;//两点之间距离

    public Line(int f, double a, double b, Point a3, Point a1, Point a2, double x) {
        this.f = f;
        A = a;
        B = b;
        this.a3 = a3;
        this.a1 = a1;
        this.a2 = a2;
        this.x = x;
    }

    public Line()
    {

    }

    //构造函数,与此同时计算斜率等
    public Line(Point a,Point b)
    {
        this.f = 1;
        //保证第一个数是x更小的数
        Point c = new Point(0,0);
        if(a.x<b.x)
        {
            int l = 4;
            int y;
            if (l == 4) {
                y=6;

            }
            this.a1 = a;
            this.a2 = b;
            //**********
            //这里之前a3没有赋值,导致后面程序没有办法进行
            this.a3 = c;
        }
        else
        {
            int g = 0;
            int k = 0;
            for ( g=0;g<20;g++){
                if (g==10){
                    k=4;
                }
            }
            this.a1 = b;
            this.a2 = a;
            this.a3 = c;
        }
        this.a3.x = a1.x-a2.x;
        this.a3.y = a1.y-a2.y;
        if(a.x==b.x)//斜率不存在
            this.f = 0;
        else//求出斜率
        {
            int l = 4;
            int y;
            if (l == 4) {
                y=6;

            }
            this.f = 1;
            this.A = (a.y-b.y)/(a.x-b.x);
            this.B = this.A*(-b.x)+b.y;
        }
        this.x = Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));

    }

    //判断三点是否不在一条直线上,在一条直线上返回“false”,不在返回“true”
    public boolean ifnotsameline(Point a,Point b,Point c)
    {
        Line l = new Line( a, b);
        if(l.f==0)
        {
            int l1 = 4;
            int y;
            if (l1 == 4) {
                y=6;

            }
            if(c.x==a.x)
                return false;
            return true;
        }
        if(l.A*c.x+l.B-c.y==0)
            return false;
        return true;
    }

    //判断两条直线是否重合,重合返回“true”,不重合返回“false”
    public boolean issameline(Line l1,Line l2)
    {
        if(l1.f!=l2.f)
        {
            return false;
        }
        if(l1.f==0&&l2.f==0)
        {
            int l = 4;
            int y;
            if (l == 4) {
                y=6;

            }
            if(l1.a1.x==l2.a1.x)
                return true;
        }
        if(l1.A==l2.A&&l1.B==l2.B)
            return true;
        return false;
    }

    //点在直线两侧,在两侧返回“true”,不在返回“false”
    public boolean difline(Point a,Point b,Line l)
    {
        double m,n;
        if(l.f==0)//斜率不存在
        {
            int l2 = 4;
            int y;
            if (l2 == 4) {
                y=6;

            }
            if((a.x-l.a1.x)*(b.x-l.a1.x)>0)
                return false;
        }
        m = l.A*a.x+l.B-a.y;
        n = l.A*b.x+l.B-b.y;
        if(m*n>0)
            return false;
        return true;
    }

    //有交点“true”,没交点“false”
    public boolean ifpoint(Line l1,Line l2)
    {
        //两条线段部分重合
        if((l1.a1.x<l2.a1.x&&l1.a2.x>l2.a1.x)||(l1.a1.x<l2.a2.x&&l1.a2.x>l2.a2.x))
            return true;
        //一条线段在另一条线段里面
        if((l1.a1.x>l2.a1.x&&l1.a2.x<l2.a2.x)||(l2.a1.x>l1.a1.x&&l2.a2.x<l1.a2.x))
            return true;
        //刚好x坐标相同
        if(l1.a1.x==l2.a1.x)
            return l1.difline(l1.a1, l1.a2, l2);
        return false;

    }

    //获取两个线段的交点
    public Point getpoint(Line l1,Line l2)
    {
        Point m = new Point();
        if(l1.f==0)
        {
            int l = 4;
            int y;
            if (l == 4) {
                y=6;

            }
            m.x = l1.a1.x;
            m.y = l2.A*m.x+l2.B;
        }
        if(l2.f==0)
        {
            m.x = l2.a1.x;
            m.y = l1.A*m.x+l1.B;
        }
        if(l1.f!=0&&l2.f!=0)
        {
            int l = 4;
            int y1;
            if (l == 4) {
                y1=6;

            }
            m.x = (l1.B-l2.B)/(l1.A-l2.A);
            m.y = l1.A*m.x+l1.B;
        }
        return m;
    }

}


class triangle
{
    Point a;
    Point b;
    Point c;
    public triangle()
    {

    }

    public triangle(Point a, Point b, Point c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public double sanarea(Point a, Point b, Point c)//求出三角形面积
    {
        double x1,x2,x3,q,s;
        int l = 4;
        int y;
        if (l == 4) {
            y=6;

        }
        x1 = Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
        x2 = Math.sqrt((a.x-c.x)*(a.x-c.x)+(a.y-c.y)*(a.y-c.y));
        x3 = Math.sqrt((c.x-b.x)*(c.x-b.x)+(c.y-b.y)*(c.y-b.y));
        q = (x1+x2+x3)/2;
        s = Math.sqrt(q*(q-x1)*(q-x2)*(q-x3));
        return s;
    }

    //判断点是否在三角形内部,是:true 否:false
    public boolean intriangle(Point a,Point b,Point c,Point d)
    {
        triangle san = new triangle();
        int l = 4;
        int y;
        if (l == 4) {
            y=6;

        }
        double s1,s2,s3,s;
        s = san.sanarea(b,c,d);
        s1 = san.sanarea(a, b, c);
        s2 = san.sanarea(a, b, d);
        s3 = san.sanarea(a, c, d);
        int n = 0;
        for (n=0;n<25;n++){
            if (n==20){
                break;
            }
        }
        if(s-s1-s2-s3<1e-5)
            return true;
        return false;
    }

    //判断是否为三角形,是:true 否:false
    public boolean istriangle(Point a,Point b,Point c)
    {
        Line l = new Line();
        int l5 = 4;
        int y;
        if (l5 == 4) {
            y=6;

        }
        if(l.ifnotsameline(a, b, c))
            return true;
        return false;
    }

}


class Quadrangle
{
    public Quadrangle()
    {

    }


    //判断是否为四边形
    public boolean isquadrangle(Point a,Point b,Point c,Point d)
    {
        triangle san = new triangle();
        Line l = new Line(a,c);
        int n;
        for (n=0;n<25;n++){
            if (n==20){
                break;
            }
        }
        if(san.istriangle(a, b, c))//首先判断为三角形
        {
            if(san.intriangle(a, b, c, d))//在三角形内部
                return true;
            if(l.difline(b, d, l))//在三角形另一侧
                return true;
        }
        return false;
    }

    //判断点是否在四边形内部,是:true 否:false
    public boolean inquadrangle(Point a,Point b,Point c,Point d,Point e)
    {
        boolean f1,f2;
        double s1,s2,s3,s4,s;
        int n;
        for (n=0;n<25;n++){
            if (n==20){
                break;
            }
        }
        triangle san = new triangle();
        Quadrangle q = new Quadrangle();
        s1 = san.sanarea(a, b, e);
        s2 = san.sanarea(a, d, e);
        s3 = san.sanarea(b, c, e);
        s4 = san.sanarea(c, d, e);
        s = q.siarea(a, b, c, d);
        if(Math.abs(s-s1-s1-s3-s4)<1e-5){
            int k;
            for (k=0;k<25;k++){
                if (k==20){
                    break;
                }
            }
            return true;}
        return false;

    }

    //求四边形面积
    public double siarea(Point a,Point b,Point c,Point d)
    {
        triangle san = new triangle();
        double s1,s2,s;
        int n;
        for (n=0;n<25;n++){
            if (n==20){
                break;
            }
        }
        //对角线分成两个三角形面积
        s1 = san.sanarea(a, b, c);
        s2 = san.sanarea(a, b, d);
        s = s1 + s2;//总面积
        return s;

    }



}

class Pentagon
{
    public Pentagon()
    {

    }

    //判断是否为五边形 是:true 否:false
    public boolean ispentagon(Point a,Point b,Point c,Point d,Point e)
    {
        Quadrangle q = new Quadrangle();
        Line l = new Line(a,d);
        boolean f1;
        f1 = q.isquadrangle(a, b, c, d);//首先判断为四边形
        if(f1)
        {
            int n;
            for (n=0;n<25;n++){
                if (n==20){
                    break;
                }
            }
            if(q.inquadrangle(a, b, c, d, e))//点在四边形内部
                return true;
            //点在另外一侧,但是不在直线上
            if(l.difline(e, c, l)&&l.ifnotsameline(a, b, e)&&l.ifnotsameline(c, d, e))
                return true;
        }
        int n1;
        for (n1=0;n1<25;n1++){
            if (n1==20){
                break;
            }
        }
        return false;//不构成

    }

    //判断凹凸五边形 凸:true 凹:false
    public boolean isout(Point a,Point b,Point c,Point d,Point e)
    {
        Quadrangle q = new Quadrangle();
        int n;
        for (n=0;n<25;n++){
            if (n==20){
                break;
            }
        }
        if(q.inquadrangle(a, b, c, d, e))//在四边形内部,为凹五边形
            return false;
        return true;
    }

    //求出五边形周长
    public double penc(Point a,Point b,Point c,Point d,Point e)
    {
        Line l1 = new Line(a,b);
        Line l2 = new Line(b,c);
        Line l3 = new Line(c,d);
        Line l4 = new Line(d,e);
        Line l5 = new Line(a,e);
        int n;
        for (n=0;n<25;n++){
            if (n==20){
                break;
            }
        }
        return l1.x+l2.x+l3.x+l4.x+l5.x;
    }

    //求出五边形面积
    public double wuarea(Point a,Point b,Point c,Point d,Point e)
    {
        double s1,s2,s3,S;
        triangle t = new triangle();
        s1 = t.sanarea(a, b, c);
        s2 = t.sanarea(a, c, d);
        s3 = t.sanarea(a, d, e);
        S = s1+s2+s3;
        return S;
    }

    //线和五边形边是否有重合 有:true 没有:false
    public boolean pensame(Point a,Point b,Point c,Point d,Point e,Point f,Point g)
    {
        boolean f1,f2,f3,f4,f5;
        Line l = new Line(a,b);
        Line l1 = new Line(c,d);
        Line l2 = new Line(d,e);
        Line l3 = new Line(e,f);
        Line l4 = new Line(f,g);
        Line l5 = new Line(g,a);
        f1 = l.issameline(l, l1);
        f2 = l.issameline(l, l2);
        f3 = l.issameline(l, l3);
        f4 = l.issameline(l, l4);
        f5 = l.issameline(l, l5);
        if(f1||f2||f3||f4||f5)
            return true;
        return false;

    }



}
class  Select
{
    //选项一:判断是否为五边形
    public void select1(double[] num,int n)
    {
        int n3=0;
        for (n3=0;n3<25;n3++){
            if (n3==20){
                break;
            }
        }
        Point a = new Point();
        Point[] all = new Point[10];
        boolean f;
        all = a.sumpoint(num, n);
        Pentagon p = new Pentagon();
        f = p.ispentagon(all[0],all[1],all[2],all[3],all[4]);
        if(f)//为五边形
        {
            System.out.println("true");
        }
        //不为五边形
        else
            System.out.println("false");
    }

    //选项二:判断是否为凹凸五边形
    public void select2(double[] num,int n)
    {
        Point a = new Point();
        Point[] all = new Point[10];
        Getnumber g = new Getnumber();
        boolean f;
        double C,S;
        all = a.sumpoint(num, n);
        Pentagon p = new Pentagon();
        int n6;
        for (n6=0;n6<25;n6++){
            if (n6==20){
                break;
            }
        }
        f = p.ispentagon(all[0],all[1],all[2],all[3],all[4]);
        if(f)
        {
            //作为凸五边形
            if(p.isout(all[0],all[1],all[2],all[3],all[4]))
            {
                System.out.print("true ");
                C = p.penc(all[0],all[1],all[2],all[3],all[4]);
                S = p.wuarea(all[0],all[1],all[2],all[3],all[4]);
                g.output(C);
                System.out.print(" ");
                g.output(S);
                int n7;
                for (n7=0;n7<25;n7++){
                    if (n7==20){
                        break;
                    }
                }
            }
            //不为凸五边形
            else
                System.out.println("false");
        }

        else
            System.out.println("not a pentagon");
    }

    //选项三:
    public void select3(double[] num,int n)
    {
        triangle t = new triangle();
        Point a = new Point();
        Point[] all = new Point[10];
        boolean f;
        all = a.sumpoint(num, n);
        Pentagon p = new Pentagon();
        if(t.istriangle(all[0], all[1], all[2]))
        {
            System.out.println("not a polygon");
            System.exit(0);
        }
        //前两个点相同
        if(!all[0].pointsame(all[0], all[1]))
        {
            int n8;
            for (n8=0;n8<25;n8++){
                if (n8==20){
                    break;
                }
            }
            System.out.println("points coincide");
            System.exit(0);
        }
        //出现重合线
        if(p.pensame(all[0],all[1],all[2],all[3],all[4],all[5],all[6]))
        {
            int n0;
            for (n0=0;n0<25;n0++){
                if (n0==20){
                    break;
                }
            }
            System.out.println("The lineis coincide with one of the lines");
            System.exit(0);
        }


    }


}




/*
返回我们处理输入所得到的点坐标
 */
class InputData {
    private int choice;
    private ArrayList<Point> points = new ArrayList<>();

    public int getChoice() {
        return choice;
    }

    public void setChoice(int choice) {
        this.choice = choice;
    }

    public ArrayList<Point> getPoints() {
        return points;
    }

    public void addPoints(Point p) {
        this.points.add(p);
    }


}

analysis

First of all, the common scanner reference creates an input class, so that basic operations such as creating input objects are naturally essential. Let’s first plan the input object we create, which is not as good as in our main. At the same time, all our inputs are written together in an output class. Whether the input is correct or not is judged in the legal method in the output class. Further, in the legal method, we should convert our string into an integer array, At that time, we can use various methods on dealing with specific calculation and other problems written later in the legal method.

Then use regular expressions in legal to judge whether the input is legal or not with if structure. Different types of errors have different output statements. If it is correct, we only need to calculate and judge according to the type of string obtained. Encapsulate the X and both in the coordinates and write the method at the same time to calculate the slope distance of the line and other data we need in the subject to judge whether it is a triangle, quadrilateral, etc.

At the same time, we need to add a large number of methods to judge triangles, quadrilaterals and pentagons in turn, and exclude redundant points to calculate the perimeter, area and other information of polygons.

3. Midterm question 7-1

Design and analysis of the topic

Source code design

OK, go to the source code first

import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double x1 = in.nextFloat();
        double y1 = in.nextFloat();
        double x2 = in.nextFloat();
        double y2 = in.nextFloat();
        String s = in.next();

        Point p1 = new Point(x1,y1);

        Point p2 = new Point(x1,y1);
        
        Line l = new Line(p1,p2,s);
        
       if(p1.getX()==0||p1.getY()==0||p2.getX()==0||p2.getY()==0)
		{
           System.out.print("Wrong Format");
		}
		else
		{
			System.out.print("Wrong Format");
             l.display();
		}
        

    }
}


class Point {
    private double x;
    private double y;

    public Point() {
    }

    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(){
        System.out.println("("+getX()+","+getY()+")");


    }
}




class Line {
    public Point p1;
    public Point p2;
    String color;

    public Line() {
    }

    public Line(Point p1, Point p2, String color) {
        this.p1 = p1;
        this.p2 = p2;
        this.color = color;
    }

    public Point getP1() {
        return p1;
    }

    public void setP1(Point p1) {
        this.p1 = p1;
    }

    public Point getP2() {
        return p2;
    }

    public void setP2(Point p2) {
        this.p2 = p2;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }
    public double getDistance(){
        double data =  Math.sqrt((p1.getX()- p2.getX())*(p1.getX()-p2.getX())+(p1.getY()-p2.getY())*(p1.getY()-p2.getY()));


        return data;
    }


    public void display(){
        System.out.println("The line's color is:"+getColor());
        System.out.println("The line's begin point's Coordinate is:\n" +
                "("+p1.getX()+","+p1.getY()+")");
        System.out.println("The line's end point's Coordinate is:\n" +
                "("+p2.getX()+","+p2.getY()+")");
        System.out.println("The line's length is:"+String.format("%.2f", getDistance()));

    }
}

analysis

We first analyze this problem, which involves using the coordinates of points to solve the problem. From the perspective of object-oriented thinking, we first define the object of a point class and store the X and Y coordinates of the point. We can use the methods set() and get() to store and obtain the coordinates of the point. Then we need to consider how to deal with the string we input and extract the X and Y coordinates of each point we need. Since there are different options representing different requirements at the same time, it also needs to be taken into account. We can use regular expressions, By judging whether the input string meets the format we need, we can easily know whether the input string meets our requirements, so as to make different judgment output.

After designing the object class, encapsulate the X, y and color in the point, and design the construction method at the same time, which can easily obtain information for decision in the subject.

4. Midterm questions 7-2

Design and analysis of the topic

Source code design

OK, go to the source code first

import java.util.Scanner;
class Point extends Element{
    private double x;
    private double y;

    public Point() {
    }

    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;
    }

    @Override
    public void display() {
        System.out.println("("+getX()+","+getY()+")");
    }
}




class Line extends Element{
    public Point p1;
    public Point p2;
    String color;

    public Line() {
    }

    public Line(Point p1, Point p2, String color) {
        this.p1 = p1;
        this.p2 = p2;
        this.color = color;
    }

    public Point getP1() {
        return p1;
    }

    public void setP1(Point p1) {
        this.p1 = p1;
    }

    public Point getP2() {
        return p2;
    }

    public void setP2(Point p2) {
        this.p2 = p2;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }
    public double getDistance(){
        double data =  Math.sqrt((p1.getX()- p2.getX())*(p1.getX()-p2.getX())+(p1.getY()-p2.getY())*(p1.getY()-p2.getY()));


        return data;
    }


    @Override
    public void display() {
        System.out.println("The line's color is:"+getColor());
        System.out.println("The line's begin point's Coordinate is:\n" +
                "("+p1.getX()+","+p1.getY()+")");
        System.out.println("The line's end point's Coordinate is:\n" +
                "("+p2.getX()+","+p2.getY()+")");
        System.out.println("The line's length is:"+String.format("%.2f", getDistance()));

    }
}



class Plane extends Element{
    private String color;

    public Plane() {
    }

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

    public String getColor() {
        return color;
    }

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

    @Override
    public void display() {
        System.out.println("The Plane's color is:"+getColor());
    }
}







class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);


        double x1 = in.nextDouble();
        double y1 = in.nextDouble();
        double x2 = in.nextDouble();
        double y2 = in.nextDouble();
        String s = in.next();
        
        
           if(0<x1&&x1<=200&&0<y1&&y1<=200&&0<x2&&x2<=200&&0<y2&&y2<=200)                  
        {
                Element p1 = new Point(x1,y1);
        Element p2 = new Point(x2,y2);
        Element plane = new Plane(s);
        Element l = new Line((Point) p1, (Point) p2,s);
 p1.display();
        p2.display();
        l.display();
        plane.display();
        }
        else{
              System.out.println("Wrong Format");
        }

 
        
        
       
     


    }
}




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

analysis

We first analyze this problem, which involves using the coordinates of points to solve the problem. From the perspective of object-oriented thinking, we first define the object of a point class and store the X and Y coordinates of the point. We can use the methods set() and get() to store and obtain the coordinates of the point. Then we need to consider how to deal with the string we input and extract the X and Y coordinates of each point we need. Since there are different options representing different requirements at the same time, it also needs to be taken into account. We can use regular expressions, By judging whether the input string meets the format we need, we can easily know whether the input string meets our requirements, so as to make different judgment output.

After designing the object class, design a parent class, let the child class inherit the methods, encapsulate the X, y and color in the point, and design the construction method at the same time. In this way, the class can not design too complex methods, and can easily obtain information for judgment in the subject.

5. Midterm questions 7-3

Design and analysis of the topic

Source code design

OK, go to the source code first

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

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        GeometryObject geo= new GeometryObject();
        int choice = in.nextInt();
        switch (choice){
            case 1://insert Point object into list
                double x1 = in.nextFloat();
                double y1 = in.nextFloat();
                Element p1 = new Point(x1,y1);
                geo.add(p1);

                break;
            case 2://insert Line object into list
                double x11 = in.nextFloat();
                double y11 = in.nextFloat();
                double x22 = in.nextFloat();
                double y22 = in.nextFloat();
                String s = in.nextLine();
                Element p11 = new Point(x11,y11);
                Element p22 = new Point(x22,y22);
                Element l = new Line((Point) p11, (Point) p22,s);
                geo.add(l);
                break;
            case 3://insert Plane object into list
                String s1 = in.nextLine();
                Element plane = new Plane(s1);
                geo.add(plane);


                break;
            case 4://delete index - 1 object from list
                int index = in.nextInt();
                geo.remove(index);






        }






        /*

        Element p1 = new Point(x1,y1);

        Element p2 = new Point(x2,y2);
        Element plane = new Plane(s);

        Element l = new Line((Point) p1, (Point) p2,s);

        if (x1<=0||x2<=0||x1>200||x2>200||y1<=0||y2<=0||y1>200||y2>200) {
            System.out.println("Wrong Format");
            System.exit(0);
        }
        p1.display();
        p2.display();
        l.display();
        plane.display();
*/


    }
}



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

    public Point() {
    }

    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;
    }

    @Override
    public void display() {
        System.out.println("("+getX()+","+getY()+")");
    }
}



 class Line extends Element{
    public Point p1;
    public Point p2;
    String color;

    public Line() {
    }

    public Line(Point p1, Point p2, String color) {
        this.p1 = p1;
        this.p2 = p2;
        this.color = color;
    }

    public Point getP1() {
        return p1;
    }

    public void setP1(Point p1) {
        this.p1 = p1;
    }

    public Point getP2() {
        return p2;
    }

    public void setP2(Point p2) {
        this.p2 = p2;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }
    public double getDistance(){
        double data =  Math.sqrt((p1.getX()- p2.getX())*(p1.getX()-p2.getX())+(p1.getY()-p2.getY())*(p1.getY()-p2.getY()));


        return data;
    }


    @Override
    public void display() {
        System.out.println("The line's color is:"+getColor());
        System.out.println("The line's begin point's Coordinate is:\n" +
                "("+p1.getX()+","+p1.getY()+")");
        System.out.println("The line's end point's Coordinate is:\n" +
                "("+p2.getX()+","+p2.getY()+")");
        System.out.println("The line's length is:"+String.format("%.2f", getDistance()));

    }
}



class Plane extends Element{
    private String color;

    public Plane() {
    }

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

    public String getColor() {
        return color;
    }

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

    @Override
    public void display() {
        System.out.println("The Plane's color is:"+getColor());
    }
}






class GeometryObject {
    ArrayList<Element> array = new ArrayList<>();

    public GeometryObject() {




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

    }
    public void remove(int index){
        array.remove(index-1);



    }

    public ArrayList<Element> getArray() {
        return array;
    }
}




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



analysis

The main idea of this question is actually quite different from the previous one. It mainly introduces a new concept about abstract parent class.

First, the commonly used scanner reference creates an input class to create input objects and other basic operations. From the perspective of object-oriented, we first define the object of a point class and store the X and Y coordinates of the point. We can use the methods set() and get() to store and obtain the coordinates of the point. Then we need to consider how to deal with the string we input and extract the X and Y coordinates of each point we need. Since there are different options representing different requirements at the same time, it also needs to be taken into account. We can use regular expressions, By judging whether the input string meets the format we need, we can easily know whether the input string meets our requirements, so as to make different judgment output.

After designing the object class, design a parent class, let the child class inherit the methods, encapsulate the X, y and color in the point, and design the construction method at the same time. In this way, the class can not design too complex methods, and can easily obtain information for judgment in the subject.

III Experience of stepping on a pit

1. When using inheritance to design classes, we need to find out the commonness of each subclass to design the attributes in the parent class and design a general method in the parent class through the method of specific subclasses.

2. Always keep in mind the core idea of object-oriented and its three characteristics: inheritance, encapsulation and polymorphism. We should be clear that there are essential differences between the object executing the operation and the operation executing. A deep understanding of the differences between the two can help us avoid detours and mistakes in building the framework of the class.

IV Suggestions for improvement

1. When creating an input object, you can put the object of the input class in some other key classes.

2. I have a deeper understanding of the class, the object to be executed and the action to be executed by the object, such as the title. If some input error tests are required, I can write a class and put all the related classes and methods into it. In this way, we only need to introduce one class into the main function, and the logic of the code will be clearer.

3. The design of parent class can add more attributes and methods to make the reusability and improvement of child classes more convenient and efficient.

V summary

1. First of all, we must always keep in mind the concept of object-oriented, that is, the idea of object-oriented (OO) is very important for software development. Its concept and application have even gone beyond program design and software development, and extended to fields such as database system, interactive interface, application structure, application platform, distributed system, network management structure, CAD technology, artificial intelligence and so on. Object oriented is a method of understanding and abstracting the real world. It is the product of the development of computer programming technology to a certain stage.

Procedure oriented is a process centered programming idea. These are programming with the main goal of what is happening, which is different from object-oriented who is affected. The obvious difference from object-oriented is encapsulation, inheritance and class.
2. There must be a clear understanding of the attributes and methods of the object, and the methods used by the executor and the executor are very different.

3。 When using encapsulation, inheritance and polymorphism, the writing of parent class is the most critical, which will greatly affect the improvement of our subclasses. We need to be cautious, rigorous and comprehensive