首页 > 编程语言 >JAVA的PTA题目集4、5和期中考试的总结

JAVA的PTA题目集4、5和期中考试的总结

时间:2022-10-29 22:14:26浏览次数:72  
标签:dian JAVA 期中考试 xian System lab lbc sanjiao PTA

一、前言:

(1)题量,难度

         1、题目集4(四边形):一共有三道题,第一题和第三题较为简单,第二题关于凸四边形的计算难度加大。

    2、题目集5(五边形):一共有两道题,都是关于对凸五边形的计算,第一题难度较大,第二题难度更大。

    3、期中: 一共有三道题,第一题是考察的是类的构造调用和点线的简答处理,较为简单,第二题考察到类的继承与多态,难度适中,第三题涉及容器类的问题,难度较大。

(2)知识点

    pta作业涉及到正则表达式的运用,类的设计及其方法的调用。

    期中考涉及到继承与多态和容器类的问题,关于点线的简单处理。

    类的构造方法、方法的调用、参数传递、对象的构造与使用 。

二、题目集4:

 7-1(1)题目:

 

7-2 点线形系列4-凸四边形的计算 分数 70 作者 蔡轲 单位 南昌航空大学

用户输入一组选项和数据,进行与四边形有关的计算。
以下四边形顶点的坐标要求按顺序依次输入,连续输入的两个顶点是相邻顶点,第一个和最后一个输入的顶点相邻。
选项包括:
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-1(2)设计与分析:

  

 

 

 

复制代码

import java.util.Scanner;

class dian{
double x;
double y;
}

class xian{
double d1,d2,dcd,dec,ded;
double A;
double B;
double C;
public void liangdian(dian a,dian b,xian l)
{//计算两点之间的距离
l.d1=Math.sqrt(Math.pow(a.x-b.x,2)+Math.pow(a.y-b.y,2));
}
public void juli(dian a,dian b,dian c,xian l){
//点到直线的距离
l.A=b.y-c.y;
l.B=c.x-b.x;
l.C=b.x*c.y-c.x*b.y;
l.d2=Math.abs((l.A*a.x+l.B*a.y+C)/Math.sqrt(Math.pow(l.A,2)+Math.pow(l.B,2)));
}
public void liangjiaodian(dian a,dian b,dian c,dian d,dian e,xian lab,xian lcd){
//两直线的交点
juli(c,a,b,lab);
juli(a,c,d,lcd);
// e.y= (lab.A*lcd.C-lcd.A*lab.C)/(lab.B*lcd.A-lab.A*lcd.B);
// e.x=(-1)*(lab.B/lab.A)*e.y-lab.C/lab.A;
e.x=(lab.B*lcd.C-lcd.B*lab.C)/(lab.A*lcd.B-lcd.A*lab.B);
e.y=(lcd.A*lab.C-lab.A*lcd.C)/(lcd.B*lab.A-lcd.A*lab.B);
e.y=Math.round(e.y*1000000000)/(double)1000000000;
e.x=Math.round(e.x*1000000000)/(double)1000000000;
}
public boolean xiangjiao(dian e,dian c,dian d,xian lcd){
//判断直线与线段是否相交
lcd.dcd=Math.sqrt(Math.pow(c.x-d.x,2)+Math.pow(c.y-d.y,2));
lcd.dec=Math.sqrt(Math.pow(e.x-c.x,2)+Math.pow(e.y-c.y,2));
lcd.ded=Math.sqrt(Math.pow(e.x-d.x,2)+Math.pow(e.y-d.y,2));
if(Math.abs(lcd.ded+lcd.dec-lcd.dcd)<0.000001)
return true;
else
return false;
}
}

class triangle{
double l1,s1,flag=0,cos1,cos2,cos3;
public boolean shifou(xian lac,xian lbc,xian lab){
//判断是否是三角形
if((lac.d1+lbc.d1)>lab.d1&&(lab.d1+lbc.d1)>lac.d1&&(lac.d1+lab.d1)>lbc.d1)
return true;
else
return false;
}
public boolean dengyao(xian lac,xian lbc,xian lab){
//判断是否是等腰三角形
if(lac.d1==lab.d1||lab.d1==lbc.d1||lbc.d1==lac.d1)
return true;
else
return false;
}
public boolean dengbian(xian lac,xian lbc,xian lab){
//判断是否是等边三角形
if(lab.d1==lac.d1&&lac.d1==lbc.d1&&lab.d1==lbc.d1)
return true;
else
return false;
}
public void zhouchang(xian lac,xian lbc,xian lab,triangle sanjiao){
//计算周长
sanjiao.l1=lac.d1+lbc.d1+lab.d1;
}
public void mianji(xian lbc,triangle sanjiao){
//计算面积
sanjiao.s1=0.5*lbc.d2*lbc.d1;
}
public boolean dunjiao(xian lab,xian lac,xian lbc,triangle sanjiao){
//判断是否是钝角三角形
sanjiao.cos1=(lac.d1*lac.d1+lab.d1*lab.d1-lbc.d1*lbc.d1)/(2*lac.d1*lab.d1);
sanjiao.cos2=(lbc.d1*lbc.d1+lab.d1*lab.d1-lac.d1*lac.d1)/(2*lbc.d1*lab.d1);
sanjiao.cos3=(lbc.d1*lbc.d1+lac.d1*lac.d1-lab.d1*lab.d1)/(2*lbc.d1*lac.d1);
if(sanjiao.cos1<0.0001||sanjiao.cos2<0.0001||sanjiao.cos3<0.0001)
return true;
else

return false;
}
public boolean zhijiao(xian lab,xian lac,xian lbc,triangle sanjiao){
//判断是否是直角三角形
sanjiao.cos1=(lac.d1*lac.d1+lab.d1*lab.d1-lbc.d1*lbc.d1)/(2*lac.d1*lab.d1);
sanjiao.cos2=(lbc.d1*lbc.d1+lab.d1*lab.d1-lab.d1*lab.d1)/(2*lbc.d1*lab.d1);
sanjiao.cos3=(lbc.d1*lbc.d1+lac.d1*lac.d1-lab.d1*lab.d1)/(2*lbc.d1*lac.d1);
if(sanjiao.cos1==0||sanjiao.cos2==0||sanjiao.cos3==0)
return true;
else
return false;
}
public boolean ruijiao(xian lab,xian lac,xian lbc,triangle sanjiao){
//判断是否是锐角三角形
sanjiao.cos1=(lac.d1*lac.d1+lab.d1*lab.d1-lbc.d1*lbc.d1)/(2*lac.d1*lab.d1);
sanjiao.cos2=(lbc.d1*lbc.d1+lab.d1*lab.d1-lab.d1*lab.d1)/(2*lbc.d1*lab.d1);
sanjiao.cos3=(lbc.d1*lbc.d1+lac.d1*lac.d1-lab.d1*lab.d1)/(2*lbc.d1*lac.d1);
if(sanjiao.cos1>0&&sanjiao.cos2>0&&sanjiao.cos3>0)
return true;
else
return false;
}
public boolean chonghe(xian l,xian lab,xian lac,xian lbc){
//判断直线是否与三角形的一条边重合
if((l.A==lab.A&&l.B==lab.B&&l.C==lab.C)||(l.A==lac.A&&l.B==lac.B&&l.C==lac.C)||(l.A==lbc.A&&l.B==lbc.B&&l.C==lbc.C))
return true;
else
return false;
}
public void whichsanjiao(triangle DEF,triangle CEF,triangle CDE,triangle CDF,dian c,dian d,dian e,dian f,xian lde,xian ldf,xian lef,xian lce,xian lcf,xian lcd){
//判断是哪三个点组成的三角形
if(shifou(lde,ldf,lef)&&(ldf.xiangjiao(c,d,f,ldf)||(e.x==c.x&&e.y==c.y)))
DEF.flag=1;
else if(shifou(lce,lcf,lef)&&(lce.xiangjiao(d,c,e,lce)||(d.x==f.x&&d.y==f.y)))
CEF.flag=1;
else if(shifou(lcd,lce,lde)&&(lce.xiangjiao(f,c,e,lce)||(f.x==d.x&&f.y==d.y)))
CDE.flag=1;
else if(shifou(lcd,lcf,ldf)&&(ldf.xiangjiao(e,d,f,ldf)||(e.x==c.x&&e.y==c.y)))
CDF.flag=1;
}
}

class quadrangle{
double c1,s4;
public boolean shifousi(xian lac,dian a,dian b,dian c,dian d){
//判断是否是四边形
lac.juli(b,a,c,lac);
double y0=0,y00=0,x0=0;
if(lac.B==0)
{
x0=((-1)*lac.C)/lac.A;
if((d.x<x0&&b.x>x0)||(d.x>x0&&b.x<x0))
{
return true;
}
else
return false;
}
else{
y0=(-1)*(lac.C/lac.B+lac.A*d.x/lac.B);
y00=(-1)*(lac.C/lac.B+lac.A*b.x/lac.B);
if((d.y<y0&&b.y>y00)||(d.y>y0&&b.y<y00))
{
return true;
}
else
return false;
}
}
public boolean pingxingsb(xian lac,xian lbc,xian lab,dian a,dian b,dian c,dian d,xian lcd,xian lad,quadrangle sibian){
//判断是否是平行四边形
lab.juli(c,a,b,lab);
lbc.juli(a,b,c,lbc);
lcd.juli(a,c,d,lcd);
lad.juli(b,a,d,lad);
if(lab.A*lcd.B==lab.B*lcd.A&&lbc.A*lad.B==lbc.B*lad.A)
{
return true;
}
else
return false;
}
public boolean lingxing(xian lac,xian lbc,xian lab,dian a,dian b,dian c,dian d,xian lcd,xian lad,quadrangle sibian){
//判断是否是菱形,邻边相等的平行四边形
if(pingxingsb(lac,lbc,lab,a,b,c,d,lcd,lad,sibian))
{
lab.liangdian(a,b,lab);
lbc.liangdian(b,c,lbc);
if(lab.d1==lbc.d1)
return true;
else
return false;
}
else
return false;
}
public boolean juxing(xian lac,xian lbc,xian lab,xian lbd,dian a,dian b,dian c,dian d,xian lcd,xian lad,quadrangle sibian){
//判断是否是矩形,有一个角为90度(用勾股定理算)的平行四边形
if(pingxingsb(lac,lbc,lab,a,b,c,d,lcd,lad,sibian))
{
lab.liangdian(a,b,lab);
lad.liangdian(a,d,lad);
lbd.liangdian(b,d,lbd);
if(Math.abs(lab.d1*lab.d1+lad.d1*lad.d1-lbd.d1*lbd.d1)<0.000001)
return true;
else
return false;
}
else
return false;
}
public boolean zhengfangxing(xian lac,xian lbc,xian lab,xian lbd,dian a,dian b,dian c,dian d,xian lcd,xian lad,quadrangle sibian){
//判断是否是正方形,邻边相等的矩形
if(juxing(lac,lbc,lab,lbd,a,b,c,d,lcd,lad,sibian))
{
lab.liangdian(a,b,lab);
lad.liangdian(a,d,lad);
if(lab.d1==lad.d1)
return true;
else
return false;
}
else
return false;
}
public boolean sidchonghe(dian a,dian b,dian c,dian d){
//判断四边形四点中是否有点重合
if((a.x==b.x&&a.y==b.y)||(a.x==c.x&&a.y==c.y)||(a.x==d.x&&a.y==d.y)||(b.x==c.x&&b.y==c.y)||(b.x==d.x&&b.y==d.y)||(c.x==d.x&&c.y==d.y))
return true;
else
return false;
}
public boolean tusibian(dian a,dian b,dian c,dian d,dian e,xian lac,xian lbd){
//判断是否是凸四边形,对角线的交点是否在两对角线的线段上
lac.liangjiaodian(a,c,b,d,e,lac,lbd);
if((lac.xiangjiao(e,a,c,lac))&&(lbd.xiangjiao(e,b,d,lbd)))
return true;
else
return false;
}
public boolean ousibian(dian a,dian b,dian c,dian d,dian e,xian lac,xian lbd){
//判断是否是凹四边形,对角线的交点是否在仅在其中一条的两对角线的线段上
lac.liangjiaodian(a,c,b,d,e,lac,lbd);
if( ( lac.xiangjiao(e,a,c,lac)&&!lbd.xiangjiao(e,b,d,lbd) )||( !lac.xiangjiao(e,a,c,lac) &&lbd.xiangjiao(e,b,d,lbd) ) )
return true;
else
return false;
}
public boolean tusibian1(dian a,dian b,dian c,dian d,dian e,xian lac,xian lbd,xian lab,xian lbc,xian lad,xian lcd,triangle sanjiao){
//判断是否是凸四边形,对角线的交点是否在两对角线的线段上
lab.liangdian(a,b,lab);
lbc.liangdian(b,c,lbc);
lac.liangdian(a,c,lac);
lad.liangdian(a,d,lad);
lbd.liangdian(b,d,lbd);
lcd.liangdian(c,d,lcd);
lac.liangjiaodian(a,c,b,d,e,lac,lbd);
if(!sanjiao.shifou(lab,lbc,lac)||!sanjiao.shifou(lab,lad,lbd)||!sanjiao.shifou(lbc,lbd,lcd)||!sanjiao.shifou(lcd,lac,lad))
return false;
else
{
if((lac.xiangjiao(e,a,c,lac))&&(lbd.xiangjiao(e,b,d,lbd)))
return true;
else
return false;
}
}
public boolean ousibian1(dian a,dian b,dian c,dian d,dian e,xian lac,xian lbd,xian lab,xian lbc,xian lad,xian lcd,triangle sanjiao){
//判断是否是凹四边形,对角线的交点是否在仅在其中一条的两对角线的线段上
lab.liangdian(a,b,lab);
lbc.liangdian(b,c,lbc);
lac.liangdian(a,c,lac);
lad.liangdian(a,d,lad);
lbd.liangdian(b,d,lbd);
lcd.liangdian(c,d,lcd);
lac.liangjiaodian(a,c,b,d,e,lac,lbd);

if(!sanjiao.shifou(lab,lbc,lac)||!sanjiao.shifou(lab,lad,lbd)||!sanjiao.shifou(lbc,lbd,lcd)||!sanjiao.shifou(lcd,lac,lad))
return false;
else{
if( ( lac.xiangjiao(e,a,c,lac)&&!lbd.xiangjiao(e,b,d,lbd) )||( !lac.xiangjiao(e,a,c,lac) &&lbd.xiangjiao(e,b,d,lbd) ) )
return true;
else
return false;
}
}
public void sibianzc(dian a,dian b,dian c,dian d,xian lab,xian lbc,xian lcd,xian lad,quadrangle sibian){
//计算四边形的周长
lab.liangdian(a,b,lab);
lbc.liangdian(b,c,lbc);
lcd.liangdian(c,d,lcd);
lad.liangdian(a,d,lad);
sibian.c1=lab.d1+lbc.d1+lcd.d1+lad.d1;
sibian.c1=Math.round(sibian.c1*1000)/(double)1000;
}
public void sibianmj(dian a,dian b,dian c,dian d,dian e,xian lac,xian lbd,triangle sanjiao,quadrangle sibian){
//计算四边形的面积
double flag1=0;
double flag2=0;
if(tusibian(a,b,c,d,e,lac,lbd))
{
lbd.juli(a,b,d,lbd);
lbd.liangdian(b,d,lbd);
sanjiao.mianji(lbd,sanjiao);
sibian.s4=sanjiao.s1;
lbd.juli(c,b,d,lbd);
sanjiao.mianji(lbd,sanjiao);
sibian.s4=sibian.s4+sanjiao.s1;
sibian.s4=Math.round(sibian.s4*1000)/(double)1000;
}
else{
if(lac.xiangjiao(e,a,c,lac))
flag1=1;
if(lbd.xiangjiao(e,b,d,lbd))
flag2=1;
if(flag1==1)
{//BD做切线
lbd.juli(a,b,d,lbd);
lbd.liangdian(b,d,lbd);
sanjiao.mianji(lbd,sanjiao);
sibian.s4=sanjiao.s1;
lbd.juli(c,b,d,lbd);
sanjiao.mianji(lbd,sanjiao);
sibian.s4=sibian.s4+sanjiao.s1;
sibian.s4=Math.round(sibian.s4*1000)/(double)1000;
}
else{//AC做切线
lac.juli(b,a,c,lac);
lac.liangdian(a,c,lac);
sanjiao.mianji(lac,sanjiao);
sibian.s4=sanjiao.s1;
lac.juli(d,a,c,lac);
sanjiao.mianji(lac,sanjiao);
sibian.s4=sibian.s4+sanjiao.s1;
sibian.s4=Math.round(sibian.s4*1000)/(double)1000;
}
}
}
}

public class Main{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
String input=in.nextLine();
if(input.charAt(1)!=':')
{
System.out.print("Wrong Format");
System.exit(0);
}
int count=0;
for(int u=0;u<input.length();u++)
{
if(input.charAt(u)==':')
count++;
}
if(count!=1)
{
System.out.print("Wrong Format");
System.exit(0);
}
if(input.charAt(0)=='1'||input.charAt(0)=='2'||input.charAt(0)=='3')//输入情况1
{
String[] coord0=input.split(":| ");
for(int i=1;i<coord0.length;i++)
{
if(!coord0[i].matches("^[+-]?(0|(0\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?),[+-]?(0|(0\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?)$"))
{ System.out.print("Wrong Format");
System.exit(0);
}
}
if(coord0.length!=5)
{
System.out.print("wrong number of points");
System.exit(0);
}
String[] coord1=coord0[1].split(",");
String[] coord2=coord0[2].split(",");
String[] coord3=coord0[3].split(",");
String[] coord4=coord0[4].split(",");
double x1,x2,x3,x4,y1,y2,y3,y4;
x1=Double.parseDouble(coord1[0]);
y1=Double.parseDouble(coord1[1]);
x2=Double.parseDouble(coord2[0]);
y2=Double.parseDouble(coord2[1]);
x3=Double.parseDouble(coord3[0]);
y3=Double.parseDouble(coord3[1]);
x4=Double.parseDouble(coord4[0]);
y4=Double.parseDouble(coord4[1]);
dian a=new dian();
dian b=new dian();
dian c=new dian();
dian d=new dian();
a.x=x1;a.y=y1;
b.x=x2;b.y=y2;
c.x=x3;c.y=y3;
d.x=x4;d.y=y4;

if(input.charAt(0)=='1'){
if((x1==x2&&y1==y2)||(x1==x3&&y1==y3)||(x1==x4&&y1==y4)||(x2==x3&&y2==y3)||(x2==x4&&y2==y4)||(x3==x4&&y3==y4))
{
System.out.print("points coincide");
System.exit(0);
}
xian lac=new xian();
xian lbc=new xian();
xian lab=new xian();
quadrangle sibian=new quadrangle();
triangle sanjiao=new triangle();
lac.liangdian(a,c,lac);
lbc.liangdian(b,c,lbc);
lab.liangdian(a,b,lab);
if(sibian.shifousi(lac,a,b,c,d))
System.out.print("true ");
else{
System.out.print("false false");
System.exit(0);
}
xian lcd=new xian();
xian lad=new xian();
if(sibian.pingxingsb(lac,lbc,lab,a,b,c,d,lcd,lad,sibian))
System.out.print("true");
else
System.out.print("false");
}//if 1
if(input.charAt(0)=='2')
{
xian lac=new xian();
xian lbc=new xian();
xian lab=new xian();
xian lcd=new xian();
xian lad=new xian();
xian lbd=new xian();
quadrangle sibian=new quadrangle();
if(!sibian.shifousi(lac,a,b,c,d))
{
System.out.print("not a quadrilateral");
System.exit(0);
}
if(sibian.lingxing(lac,lbc,lab,a,b,c,d,lcd,lad,sibian))
System.out.print("true ");
else
System.out.print("false ");
if(sibian.juxing(lac,lbc,lab,lbd,a,b,c,d,lcd,lad,sibian))
System.out.print("true ");
else
System.out.print("false ");
if(sibian.zhengfangxing(lac,lbc,lab,lbd,a,b,c,d,lcd,lad,sibian))
System.out.println("true");
else
System.out.println("false");
}
if(input.charAt(0)=='3')
{
xian lac=new xian();
xian lbc=new xian();
xian lab=new xian();
xian lcd=new xian();
xian lad=new xian();
xian lbd=new xian();
dian e=new dian();
triangle sanjiao=new triangle();
quadrangle sibian=new quadrangle();
if(!sibian.shifousi(lac,a,b,c,d))
{
System.out.println("not a quadrilateral");
System.exit(0);
}
if(sibian.tusibian(a,b,c,d,e,lac,lbd))
System.out.print("true ");
else
System.out.print("false ");
sibian.sibianzc(a,b,c,d,lab,lbc,lcd,lad,sibian);
System.out.print(sibian.c1+" ");
sibian.sibianmj(a,b,c,d,e,lac,lbd,sanjiao,sibian);
System.out.print(sibian.s4);
}
}//if 1,2,3
else if(input.charAt(0)=='4')//输入情况4
{
String[] coord0=input.split(":| ");
for(int i=1;i<coord0.length;i++)
{
if(!coord0[i].matches("^[+-]?(0|(0\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?),[+-]?(0|(0\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?)$"))
{ System.out.print("Wrong Format");
System.exit(0);
}
}
if(coord0.length!=7)
{
System.out.print("wrong number of points");
System.exit(0);
}
String[] coord1=coord0[1].split(",");
String[] coord2=coord0[2].split(",");
String[] coord3=coord0[3].split(",");
String[] coord4=coord0[4].split(",");
String[] coord5=coord0[5].split(",");
String[] coord6=coord0[6].split(",");
double x1,x2,x3,x4,x5,x6,y1,y2,y3,y4,y5,y6;
x1=Double.parseDouble(coord1[0]);
y1=Double.parseDouble(coord1[1]);
x2=Double.parseDouble(coord2[0]);
y2=Double.parseDouble(coord2[1]);
x3=Double.parseDouble(coord3[0]);
y3=Double.parseDouble(coord3[1]);
x4=Double.parseDouble(coord4[0]);
y4=Double.parseDouble(coord4[1]);
x5=Double.parseDouble(coord5[0]);
y5=Double.parseDouble(coord5[1]);
x6=Double.parseDouble(coord6[0]);
y6=Double.parseDouble(coord6[1]);
dian a=new dian();
dian b=new dian();
dian c=new dian();
dian d=new dian();
dian e=new dian();
dian f=new dian();
dian g=new dian();
dian h=new dian();
dian q=new dian();
dian p1=new dian();
dian p2=new dian();
dian p3=new dian();
dian p4=new dian();
a.x=x1;a.y=y1;
b.x=x2;b.y=y2;
c.x=x3;c.y=y3;
d.x=x4;d.y=y4;
e.x=x5;e.y=y5;
f.x=x6;f.y=y6;
xian lce=new xian();
xian lde=new xian();
xian ldf=new xian();
xian lef=new xian();
xian lcf=new xian();
xian lcd=new xian();
xian lac=new xian();
xian lbd=new xian();
xian lab=new xian();
xian lbe=new xian();
xian lbc=new xian();
xian lp1p2=new xian();
xian lp1p3=new xian();
xian lp1p4=new xian();
xian lp2p3=new xian();
xian lp3p4=new xian();
xian lcp3=new xian();
xian ldp3=new xian();
xian lcp2=new xian();
xian lfp2=new xian();
quadrangle sibian=new quadrangle();
triangle DEF=new triangle();
triangle CEF=new triangle();
triangle CDE=new triangle();
triangle CDF=new triangle();
triangle sanjiao=new triangle();

if(sibian.tusibian1(c,d,e,f,g,lce,ldf,lcd,lcf,lde,lef,sanjiao)||sibian.ousibian1(c,d,e,f,g,lce,ldf,lcd,lcf,lde,lef,sanjiao))
{
e.x=x5;e.y=y5;
lab.juli(c,a,b,lab);
lcd.juli(a,c,d,lcd);
lcf.juli(a,c,f,lcf);
lde.juli(a,d,e,lde);
lef.juli(a,e,f,lef);

if((lab.A*lcd.B==lab.B*lcd.A&&lab.A*lcd.C==lab.C*lcd.A&&lab.B*lcd.C==lab.C*lcd.B)||(lab.A*lcf.B==lab.B*lcf.A&&lab.A*lcf.C==lab.C*lcf.A&&lab.B*lcf.C==lab.C*lcf.B)||(lab.A*lde.B==lab.B*lde.A&&lab.A*lde.C==lab.C*lde.A&&lab.B*lde.C==lab.C*lde.B)||(lab.A*lef.B==lab.B*lef.A&&lab.A*lef.C==lab.C*lef.A&&lab.B*lef.C==lab.C*lef.B)){
System.out.println("The line is coincide with one of the lines");
System.exit(0);
}
double s1=0,s2=0,s0=0,xx1=0,yy1=0,xx2=0,yy2=0,xx3=0,yy3=0,xx4=0,yy4=0;
int flag111=0,flag22=0,flag33=0,flag44=0,count11=0;
lcd.liangjiaodian(a,b,c,d,g,lab,lcd);
if(lcd.xiangjiao(g,c,d,lcd)){
count11++;xx1=g.x;yy1=g.y;flag111=1;
}
e.x=x5;e.y=y5;
lde.juli(a,d,e,lde);
lde.liangjiaodian(a,b,d,e,g,lab,lde);
if(lde.xiangjiao(g,d,e,lde)){
count11++;xx2=g.x;yy2=g.y;flag22=1;
}
f.x=x6;f.y=y6;
lef.juli(a,e,f,lef);
lef.liangjiaodian(a,b,e,f,g,lab,lef);
if(lef.xiangjiao(g,e,f,lef)){
count11++;xx3=g.x;yy3=g.y;flag33=1;
}
lcf.juli(a,c,f,lcf);
lcf.liangjiaodian(a,b,c,f,g,lab,lcf);
if(lcf.xiangjiao(g,c,f,lcf)){
count11++;xx4=g.x;yy4=g.y;flag44=1;
}

if(count11>2)
count11=2;
System.out.print(count11+" ");
if(count11<2){
System.exit(0);}
else{
sibian.sibianmj(c,d,e,f,h,lce,lef,sanjiao,sibian);
s0=sibian.s4;
if(flag111==1&&flag22==1)
{
p1.x=xx1;p1.y=yy1;
p2.x=xx2;p2.y=yy2;
lp1p2.liangdian(p1,p2,lp1p2);
lp1p2.juli(d,p1,p2,lp1p2);
sanjiao.mianji(lp1p2,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
else if(flag111==1&&flag44==1)
{
p1.x=xx1;p1.y=yy1;
p4.x=xx4;p4.y=yy4;
lp1p2.liangdian(p1,p2,lp1p2);
lp1p2.juli(c,p1,p2,lp1p2);
sanjiao.mianji(lp1p2,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
else if(flag22==1&&flag33==1)
{
p3.x=xx3;p3.y=yy3;
p2.x=xx2;p2.y=yy2;
lp2p3.liangdian(p2,p3,lp2p3);
lp2p3.juli(e,p2,p3,lp2p3);
sanjiao.mianji(lp2p3,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
else if(flag33==1&&flag44==1)
{
p3.x=xx3;p3.y=yy3;
p4.x=xx4;p4.y=yy4;
lp3p4.liangdian(p3,p4,lp3p4);
lp3p4.juli(f,p3,p4,lp3p4);
sanjiao.mianji(lp3p4,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
else if(flag111==1&&flag33==1)
{
p1.x=xx1;p1.y=yy1;
p3.x=xx3;p3.y=yy3;
lcp3.liangdian(c,p3,lcp3);
lcp3.juli(f,c,p3,lcp3);
sanjiao.mianji(lcp3,sanjiao);
s1=sanjiao.s1;
lcp3.juli(p1,c,p3,lcp3);
sanjiao.mianji(lcp3,sanjiao);
s1=s1+sanjiao.s1;

ldp3.liangdian(d,p3,ldp3);
ldp3.juli(e,d,p3,ldp3);
sanjiao.mianji(ldp3,sanjiao);
s2=sanjiao.s1;
ldp3.juli(p1,d,p3,ldp3);
sanjiao.mianji(ldp3,sanjiao);
s2=s2+sanjiao.s1;

if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
else if(flag22==1&&flag44==1)
{
p2.x=xx2;p2.y=yy2;
p4.x=xx4;p4.y=yy4;
lcp2.liangdian(c,p2,lcp2);
lcp2.juli(d,c,p2,lcp2);
sanjiao.mianji(lcp2,sanjiao);
s1=sanjiao.s1;
lcp2.juli(p4,c,p2,lcp2);
sanjiao.mianji(lcp2,sanjiao);
s1=s1+sanjiao.s1;

lfp2.liangdian(f,p2,lfp2);
lfp2.juli(e,f,p2,lfp2);
sanjiao.mianji(lfp2,sanjiao);
s2=sanjiao.s1;
lfp2.juli(p4,f,p2,lfp2);
sanjiao.mianji(lfp2,sanjiao);
s2=s2+sanjiao.s1;

if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
}
}
else{
sanjiao.whichsanjiao(DEF,CEF,CDE,CDF,c,d,e,f,lde,ldf,lef,lce,lcf,lcd);
if(DEF.flag==1)
{
double s1=0,s2=0,s0=0,xx1=0,yy1=0,xx2=0,yy2=0,xx3=0,yy3=0;
int flag111=0,flag22=0,flag33=0,count11=0;
lcd.liangjiaodian(a,b,c,d,g,lab,lcd);
if(lcd.xiangjiao(g,c,d,lcd))
count11++;xx1=g.x;yy1=g.y;flag111=1;
lde.liangjiaodian(a,b,d,e,g,lab,lde);
if(lde.xiangjiao(g,d,e,lde))
count11++;xx2=g.x;yy2=g.y;flag22=1;
lce.liangjiaodian(a,b,c,e,g,lab,lcf);
if(lcf.xiangjiao(g,e,f,lcf))
count11++;xx3=g.x;yy3=g.y;flag33=1;
if(count11>2)
count11=2;
System.out.print(count+" ");
if(count11<2)
System.exit(0);
lde.liangdian(d,e,lde);
lde.juli(c,d,e,lde);
sanjiao.mianji(lde,sanjiao);
s0=sanjiao.s1;

if(flag111==1&&flag22==1)
{
p1.x=xx1;p1.y=yy1;
p2.x=xx2;p2.y=yy2;
lp1p2.liangdian(p1,p2,lp1p2);
lp1p2.juli(d,p1,p2,lp1p2);
sanjiao.mianji(lp1p2,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
else if(flag22==1&&flag33==1)
{
p2.x=xx2;p2.y=yy2;
p3.x=xx3;p3.y=yy3;
lp2p3.liangdian(p2,p3,lp2p3);
lp2p3.juli(e,p2,p3,lp2p3);
sanjiao.mianji(lp2p3,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
else if(flag111==1&&flag33==1)
{
p1.x=xx1;p1.y=yy1;
p3.x=xx3;p3.y=yy3;
lp1p3.liangdian(p1,p3,lp1p3);
lp1p3.juli(c,p1,p3,lp1p3);
sanjiao.mianji(lp1p3,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
}//
else if(CEF.flag==1){
double s1=0,s2=0,s0=0,xx1=0,yy1=0,xx2=0,yy2=0,xx3=0,yy3=0;
int flag111=0,flag22=0,flag33=0,count11=0;
lbd.liangjiaodian(a,b,b,d,g,lab,lbd);
if(lbd.xiangjiao(g,b,d,lbd))
count11++;xx1=g.x;yy1=g.y;flag111=1;
lbe.liangjiaodian(a,b,b,e,g,lab,lbe);
if(lbe.xiangjiao(g,b,e,lbe))
count11++;xx2=g.x;yy2=g.y;flag22=1;
lde.liangjiaodian(a,b,d,e,g,lab,lde);
if(lde.xiangjiao(g,d,e,lde))
count11++;xx3=g.x;yy3=g.y;flag33=1;
if(count11>2)
count11=2;
System.out.print(count11+" ");
if(count11<2)
System.exit(0);
lde.liangdian(d,e,lde);
lde.juli(b,d,e,lde);
sanjiao.mianji(lde,sanjiao);
s0=sanjiao.s1;

if(flag111==1&&flag22==1)
{

p1.x=xx1;p1.y=yy1;
p2.x=xx2;p2.y=yy2;
lp1p2.liangdian(p1,p2,lp1p2);
lp1p2.juli(b,p1,p2,lp1p2);
sanjiao.mianji(lp1p2,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
else if(flag22==1&&flag33==1)
{
p2.x=xx2;p2.y=yy2;
p3.x=xx3;p3.y=yy3;
lp2p3.liangdian(p2,p3,lp2p3);
lp2p3.juli(e,p2,p3,lp2p3);
sanjiao.mianji(lp2p3,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
else if(flag111==1&&flag33==1)
{
p1.x=xx1;p1.y=yy1;
p3.x=xx3;p3.y=yy3;
lp1p3.liangdian(p1,p3,lp1p3);
lp1p3.juli(d,p1,p3,lp1p3);
sanjiao.mianji(lp1p3,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
}
else if(CDE.flag==1){
double s1=0,s2=0,s0=0,xx1=0,yy1=0,xx2=0,yy2=0,xx3=0,yy3=0;
int flag111=0,flag22=0,flag33=0,count11=0;
lbc.liangjiaodian(a,b,b,c,g,lab,lbc);
if(lbc.xiangjiao(g,b,c,lbc))
count11++;xx1=g.x;yy1=g.y;flag111=1;
lbd.liangjiaodian(a,b,b,d,g,lab,lbd);
if(lbd.xiangjiao(g,b,d,lbd))
count11++;xx2=g.x;yy2=g.y;flag22=1;
lcd.liangjiaodian(a,b,c,d,g,lab,lcd);
if(lde.xiangjiao(g,c,d,lcd))
count11++;xx3=g.x;yy3=g.y;flag33=1;
if(count11>2)
count11=2;
System.out.print(count+" ");
if(count11<2)
System.exit(0);
lcd.liangdian(c,d,lcd);
lcd.juli(b,c,d,lcd);
sanjiao.mianji(lcd,sanjiao);
s0=sanjiao.s1;

if(flag111==1&&flag22==1)
{
p1.x=xx1;p1.y=yy1;
p2.x=xx2;p2.y=yy2;
lp1p2.liangdian(p1,p2,lp1p2);
lp1p2.juli(b,p1,p2,lp1p2);
sanjiao.mianji(lp1p2,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
else if(flag22==1&&flag33==1)
{
p2.x=xx2;p2.y=yy2;
p3.x=xx3;p3.y=yy3;
lp2p3.liangdian(p2,p3,lp2p3);
lp2p3.juli(d,p2,p3,lp2p3);
sanjiao.mianji(lp2p3,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
else if(flag111==1&&flag33==1)
{
p1.x=xx1;p1.y=yy1;
p3.x=xx3;p3.y=yy3;
lp1p3.liangdian(p1,p3,lp1p3);
lp1p3.juli(c,p1,p3,lp1p3);
sanjiao.mianji(lp1p3,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
}
else if(CDF.flag==1){
double s1=0,s2=0,s0=0,xx1=0,yy1=0,xx2=0,yy2=0,xx3=0,yy3=0;
int flag111=0,flag22=0,flag33=0,count11=0;
lbc.liangjiaodian(a,b,b,c,g,lab,lbc);
if(lbc.xiangjiao(g,b,c,lbc))
count11++;xx1=g.x;yy1=g.y;flag111=1;
lbe.liangjiaodian(a,b,b,e,g,lab,lbe);
if(lbe.xiangjiao(g,b,e,lbe))
count11++;xx2=g.x;yy2=g.y;flag22=1;
lce.liangjiaodian(a,b,c,e,g,lab,lce);
if(lce.xiangjiao(g,c,e,lce))
count11++;xx3=g.x;yy3=g.y;flag33=1;
if(count11>2)
count11=2;
System.out.print(count+" ");
if(count11<2)
System.exit(0);
lce.liangdian(c,e,lce);
lce.juli(b,c,e,lce);
sanjiao.mianji(lce,sanjiao);
s0=sanjiao.s1;

if(flag111==1&&flag22==1)
{
p1.x=xx1;p1.y=yy1;
p2.x=xx2;p2.y=yy2;
lp1p2.liangdian(p1,p2,lp1p2);
lp1p2.juli(b,p1,p2,lp1p2);
sanjiao.mianji(lp1p2,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
else if(flag22==1&&flag33==1)
{
p2.x=xx2;p2.y=yy2;
p3.x=xx3;p3.y=yy3;
lp2p3.liangdian(p2,p3,lp2p3);
lp2p3.juli(e,p2,p3,lp2p3);
sanjiao.mianji(lp2p3,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
else if(flag111==1&&flag33==1)
{
p1.x=xx1;p1.y=yy1;
p3.x=xx3;p3.y=yy3;
lp1p3.liangdian(p1,p3,lp1p3);
lp1p3.juli(c,p1,p3,lp1p3);
sanjiao.mianji(lp1p3,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
if(s1<s2)
System.out.println(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.println(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}
}
else{
System.out.println("not a quadrilateral or triangle");
}
}

}
else if(input.charAt(0)=='5')//输入情况5
{
String[] coord0=input.split(":| ");
for(int i=1;i<coord0.length;i++)
{
if(!coord0[i].matches("^[+-]?(0|(0\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?),[+-]?(0|(0\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?)$"))
{ System.out.print("Wrong Format");
System.exit(0);
}
}
if(coord0.length!=6)
{
System.out.print("wrong number of points");
System.exit(0);
}
String[] coord1=coord0[1].split(",");
String[] coord2=coord0[2].split(",");
String[] coord3=coord0[3].split(",");
String[] coord4=coord0[4].split(",");
String[] coord5=coord0[5].split(",");
double x1,x2,x3,x4,x5,y1,y2,y3,y4,y5;
x1=Double.parseDouble(coord1[0]);
y1=Double.parseDouble(coord1[1]);
x2=Double.parseDouble(coord2[0]);
y2=Double.parseDouble(coord2[1]);
x3=Double.parseDouble(coord3[0]);
y3=Double.parseDouble(coord3[1]);
x4=Double.parseDouble(coord4[0]);
y4=Double.parseDouble(coord4[1]);
x5=Double.parseDouble(coord5[0]);
y5=Double.parseDouble(coord5[1]);
dian a=new dian();
dian b=new dian();
dian c=new dian();
dian d=new dian();
dian e=new dian();
dian g=new dian();
a.x=x1;a.y=y1;
b.x=x2;b.y=y2;
c.x=x3;c.y=y3;
d.x=x4;d.y=y4;
e.x=x5;e.y=y5;
xian lbd=new xian();
xian lcd=new xian();
xian lce=new xian();
xian lde=new xian();
xian lbe=new xian();
xian lbc=new xian();
xian lac=new xian();
xian led=new xian();

triangle sanjiao=new triangle();
triangle CDE=new triangle();
triangle BDE=new triangle();
triangle BCD=new triangle();
triangle BCE=new triangle();
triangle DEF=new triangle();
triangle CEF=new triangle();
triangle CDF=new triangle();
quadrangle sibian=new quadrangle();
if(sibian.tusibian1(b,c,d,e,g,lbc,lbd,lcd,lbe,lce,lde,sanjiao)||sibian.ousibian1(b,c,d,e,g,lbc,lbd,lcd,lbe,lce,lde,sanjiao))
{
//判断点是否在四边形的某条边上
if(lbc.xiangjiao(a,b,c,lbc)||lcd.xiangjiao(a,c,d,lcd)||lde.xiangjiao(a,d,e,lde)||lbe.xiangjiao(a,b,e,lbe))
{
System.out.println("on the quadrilateral");
System.exit(0);
}
double s1=0,s2=0,s3=0,s4=0;
//面积法,先求出四边形的面积,在求出将四边形拆分为四个三角形的面积相加,与四边形面积相减的绝对值<0.0000001
//则在四边形里面,否则在外面
sibian.sibianmj(a,b,c,d,e,lac,lbd,sanjiao,sibian);
lbc.liangdian(b,c,lbc);
lbc.juli(a,b,c,lbc);
sanjiao.mianji(lbc,sanjiao);
s1=sanjiao.s1;

lbe.liangdian(b,e,lbe);
lbe.juli(a,b,e,lbe);
sanjiao.mianji(lbe,sanjiao);
s2=sanjiao.s1;

led.liangdian(e,d,led);
led.juli(a,e,d,led);
sanjiao.mianji(led,sanjiao);
s3=sanjiao.s1;

lcd.liangdian(c,d,lcd);
lcd.juli(a,c,d,lcd);
sanjiao.mianji(lcd,sanjiao);
s4=sanjiao.s1;

if(Math.abs(sibian.s4-s1-s2-s3-s4)<0.000001)
System.out.println("in the quadrilateral");
else
System.out.println("outof the quadrilateral");
}
else{
sanjiao.whichsanjiao(CDE,BDE,BCD,BCE,b,c,d,e,lcd,lce,lde,lbd,lbe,lbc);
double s1=0,s2=0,s3=0,s0=0;
if(CDE.flag==1)
{
if(lcd.xiangjiao(a,c,d,lcd)||lce.xiangjiao(a,c,e,lce)||lde.xiangjiao(a,d,e,lde))
{
System.out.println("on the triangle");
System.exit(0);
}
//其余四个点为三角形时,同样面积法如四边形
//CDE
lde.liangdian(d,e,lde);
lde.juli(c,d,e,lde);
sanjiao.mianji(lde,sanjiao);
sanjiao.s1=s0;
//ACE
lce.liangdian(c,e,lce);
lce.juli(a,c,e,lce);
sanjiao.mianji(lce,sanjiao);
sanjiao.s1=s1;
//ADE
lde.liangdian(d,e,lde);
lde.juli(a,d,e,lde);
sanjiao.mianji(lde,sanjiao);
sanjiao.s1=s2;
//ACD
lcd.liangdian(c,d,lcd);
lcd.juli(a,c,d,lcd);
sanjiao.mianji(lcd,sanjiao);
sanjiao.s1=s3;

if(Math.abs(s0-s1-s2-s3)<0.000001)
System.out.println("in the triangle");
else
System.out.println("outof the triangle");

}
else if(BDE.flag==1){
//同样面积法如四边形
if(lbd.xiangjiao(a,b,d,lbd)||lbe.xiangjiao(a,b,e,lbe)||lde.xiangjiao(a,d,e,lde))
{
System.out.println("on the triangle");
System.exit(0);
}
//BDE
lde.liangdian(d,e,lde);
lde.juli(b,d,e,lde);
sanjiao.mianji(lde,sanjiao);
sanjiao.s1=s0;
//ABE
lbe.liangdian(b,e,lbe);
lbe.juli(a,b,e,lbe);
sanjiao.mianji(lbe,sanjiao);
sanjiao.s1=s1;
//ADE
lde.liangdian(d,e,lde);
lde.juli(a,d,e,lde);
sanjiao.mianji(lde,sanjiao);
sanjiao.s1=s2;
//ABD
lbd.liangdian(b,d,lbd);
lbd.juli(a,b,d,lbd);
sanjiao.mianji(lbd,sanjiao);
sanjiao.s1=s3;

if(Math.abs(s0-s1-s2-s3)<0.000001)
System.out.println("in the triangle");
else
System.out.println("outof the triangle");

}
else if(BCD.flag==1){
//同样面积法如四边形
if(lbc.xiangjiao(a,b,c,lbc)||lbd.xiangjiao(a,b,d,lbd)||lcd.xiangjiao(a,c,d,lcd))
{
System.out.println("on the triangle");
System.exit(0);
}
//BCD
lcd.liangdian(c,d,lcd);
lcd.juli(b,c,d,lcd);
sanjiao.mianji(lcd,sanjiao);
sanjiao.s1=s0;
//ABD
lbd.liangdian(b,d,lbd);
lbd.juli(a,b,d,lbd);
sanjiao.mianji(lbd,sanjiao);
sanjiao.s1=s1;
//ACD
lcd.liangdian(c,d,lcd);
lcd.juli(a,c,d,lcd);
sanjiao.mianji(lcd,sanjiao);
sanjiao.s1=s2;
//ABC
lbc.liangdian(b,c,lbc);
lbc.juli(a,b,c,lbc);
sanjiao.mianji(lbc,sanjiao);
sanjiao.s1=s3;

if(Math.abs(s0-s1-s2-s3)<0.000001)
System.out.println("in the triangle");
else
System.out.println("outof the triangle");

}
else if(BCE.flag==1){
if(lbc.xiangjiao(a,b,c,lbc)||lbe.xiangjiao(a,b,e,lbe)||lce.xiangjiao(a,c,e,lce))
{
System.out.println("on the triangle");
System.exit(0);
}
//同样面积法如四边形
//BCE
lce.liangdian(c,e,lce);
lce.juli(b,c,e,lce);
sanjiao.mianji(lce,sanjiao);
sanjiao.s1=s0;
//ABE
lbe.liangdian(b,e,lbe);
lbe.juli(a,b,e,lbe);
sanjiao.mianji(lbe,sanjiao);
sanjiao.s1=s1;
//ACE
lce.liangdian(c,e,lce);
lce.juli(a,c,e,lce);
sanjiao.mianji(lce,sanjiao);
sanjiao.s1=s2;
//ABC
lbc.liangdian(b,c,lbc);
lbc.juli(a,b,c,lbc);
sanjiao.mianji(lbc,sanjiao);
sanjiao.s1=s3;

if(Math.abs(s0-s1-s2-s3)<0.000001)
System.out.println("in the triangle");
else
System.out.println("outof the triangle");

}
else{
System.out.println("not a quadrilateral or triangle");
}
}
}
else{
System.out.print("Wrong Format");
System.exit(0);
}
}
}

复制代码

 分析如下:

     平均复杂度较高,平均深度复杂度较高,最大复杂度较高,平均方法复杂度较高。可能是只用了一个类,一个方法很多if,else堆在一起复杂度就很高。需要减少判断语句的使用。

7-1(3)踩坑心得:

遇到的问题:

  由于题目有多个操作符,要进行多个选择,要是每个操作都在main里面写,代码太多,会导致后面操作、修改、寻找困难,可以在里面设置一个switch然后每一个操作符对应一个方法,这样会在后面修改的时候方便许多,还有题目有些问题希望可以改正

样例7 
2:0,0 -10,80 0,160 -10,80
输出not a quadrilateral

这里点(-10,80)重合,根据题意

选项1、2、3中,若四边形四个点中有重合点,输出"points coincide"。

判断格式要注意,如果判断的方法不好,后面正常输入的时候才发现,会时修改起来较为复杂

操作3中,要判断是凹四边形还是凸四边形要根据对角线来判断如果对角线有焦点则说明的凸四边形,如果无焦点则是凹四边形。如果通过求出一个对角线,判断是否其他俩个点在直线的左右俩边,需要判断俩次更加复杂

判断输入的四个点是四边形还是三角形的时候要判断是否有点重合,或者点在俩个点的连线上,计算俩点减斜率的时候要考虑分母为零的情况,分母为零的时候要特殊考虑

心得及总结

  题目比较晦涩难懂,但如果看懂了题目意思,其实题目不难,但由于我写题时运用的if,else比较多,不仅增加了代码的复杂度,还很容易遗漏条件导致犯一些不易察觉到的逻辑错误。

  对于四边形题目,运用了一些三角形的知识,将四边形切分为两个三角形,从而减少一些思考方面的问题。

7-1(4)改进建议:

    答题考虑写题简单的同时尽量考虑一些复杂度问题。建议使用继承 和接口,减少判断语句循环语句的使用,减少冗余度。

三、题目集5:

7-1 点线形系列5-凸五边形的计算-1 分数 50 作者 蔡轲 单位 南昌航空大学

用户输入一组选项和数据,进行与五边形有关的计算。
以下五边形顶点的坐标要求按顺序依次输入,连续输入的两个顶点是相邻顶点,第一个和最后一个输入的顶点相邻。
选项包括:
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-1(2)设计与分析:

  

 

 

 

复制代码

import java.util.Scanner;

class dian{
double x;
double y;
}

class xian{
double d1,d2,dcd,dec,ded;
double A;
double B;
double C;
public void liangdian(dian a,dian b,xian l)
{//计算两点之间的距离
l.d1=Math.sqrt(Math.pow(a.x-b.x,2)+Math.pow(a.y-b.y,2));
}
public void juli(dian a,dian b,dian c,xian l){
//点到直线的距离,求出ax+by+c=0中的a、b、c
l.A=b.y-c.y;
l.B=c.x-b.x;
l.C=b.x*c.y-c.x*b.y;
l.d2=Math.abs((l.A*a.x+l.B*a.y+C)/Math.sqrt(Math.pow(l.A,2)+Math.pow(l.B,2)));
}
public void liangjiaodian(dian a,dian b,dian c,dian d,dian e,xian lab,xian lcd){
//两直线的交点
juli(c,a,b,lab);
juli(a,c,d,lcd);
// e.y= (lab.A*lcd.C-lcd.A*lab.C)/(lab.B*lcd.A-lab.A*lcd.B);
// e.x=(-1)*(lab.B/lab.A)*e.y-lab.C/lab.A;
e.x=(lab.B*lcd.C-lcd.B*lab.C)/(lab.A*lcd.B-lcd.A*lab.B);
e.y=(lcd.A*lab.C-lab.A*lcd.C)/(lcd.B*lab.A-lcd.A*lab.B);
e.y=Math.round(e.y*1000000000)/(double)1000000000;
e.x=Math.round(e.x*1000000000)/(double)1000000000;
}
public boolean xiangjiao(dian a,dian b,dian c,dian d,dian e,xian lab,xian lcd){
//判断直线与线段是否相交,判断交点e是否在lcd上
lab.liangjiaodian(a,b,c,d,e,lab,lcd);
lcd.dcd=Math.sqrt(Math.pow(c.x-d.x,2)+Math.pow(c.y-d.y,2));
lcd.dec=Math.sqrt(Math.pow(e.x-c.x,2)+Math.pow(e.y-c.y,2));
lcd.ded=Math.sqrt(Math.pow(e.x-d.x,2)+Math.pow(e.y-d.y,2));
if(Math.abs(lcd.ded+lcd.dec-lcd.dcd)<0.000001)
return true;
else
return false;
}
public boolean dianonxian(dian c,dian d,dian e,xian lcd){
//判断点是否在线上
lcd.dcd=Math.sqrt(Math.pow(c.x-d.x,2)+Math.pow(c.y-d.y,2));
lcd.dec=Math.sqrt(Math.pow(e.x-c.x,2)+Math.pow(e.y-c.y,2));
lcd.ded=Math.sqrt(Math.pow(e.x-d.x,2)+Math.pow(e.y-d.y,2));
if(Math.abs(lcd.ded+lcd.dec-lcd.dcd)<0.000001)
return true;
else
return false;
}
}

class triangle{
double l1,s1,flag=0,cos1,cos2,cos3;
public boolean shifou(dian a,dian b,dian c,xian lac,xian lbc,xian lab){
//判断是否是三角形
lac.liangdian(a,c,lac);
lbc.liangdian(b,c,lbc);
lab.liangdian(a,b,lab);
if((lac.d1+lbc.d1)>lab.d1&&(lab.d1+lbc.d1)>lac.d1&&(lac.d1+lab.d1)>lbc.d1)
return true;
else
return false;
}

public boolean dengbian(dian a,dian b,dian c,xian lac,xian lbc,xian lab){
//判断是否是等边三角形
lac.liangdian(a,c,lac);
lbc.liangdian(b,c,lbc);
lab.liangdian(a,b,lab);
if(lab.d1==lac.d1&&lac.d1==lbc.d1&&lab.d1==lbc.d1)
return true;
else
return false;
}
public void zhouchang(dian a,dian b,dian c,xian lac,xian lbc,xian lab,triangle sanjiao){
//计算周长
lac.liangdian(a,c,lac);
lbc.liangdian(b,c,lbc);
lab.liangdian(a,b,lab);
sanjiao.l1=lac.d1+lbc.d1+lab.d1;
}
public void mianji(dian a,dian b,dian c,xian lbc,triangle sanjiao){
//计算面积
lbc.liangdian(b,c,lbc);
lbc.juli(a,b,c,lbc);
sanjiao.s1=0.5*lbc.d2*lbc.d1;
}
public boolean dunjiao(dian a,dian b,dian c,xian lab,xian lac,xian lbc,triangle sanjiao){
//判断是否是钝角三角形
lac.liangdian(a,c,lac);
lbc.liangdian(b,c,lbc);
lab.liangdian(a,b,lab);
sanjiao.cos1=(lac.d1*lac.d1+lab.d1*lab.d1-lbc.d1*lbc.d1)/(2*lac.d1*lab.d1);
sanjiao.cos2=(lbc.d1*lbc.d1+lab.d1*lab.d1-lac.d1*lac.d1)/(2*lbc.d1*lab.d1);
sanjiao.cos3=(lbc.d1*lbc.d1+lac.d1*lac.d1-lab.d1*lab.d1)/(2*lbc.d1*lac.d1);
if(sanjiao.cos1<0.0001||sanjiao.cos2<0.0001||sanjiao.cos3<0.0001)
return true;
else

return false;
}
public boolean zhijiao(dian a,dian b,dian c,xian lab,xian lac,xian lbc,triangle sanjiao){
//判断是否是直角三角形
lac.liangdian(a,c,lac);
lbc.liangdian(b,c,lbc);
lab.liangdian(a,b,lab);
sanjiao.cos1=(lac.d1*lac.d1+lab.d1*lab.d1-lbc.d1*lbc.d1)/(2*lac.d1*lab.d1);
sanjiao.cos2=(lbc.d1*lbc.d1+lab.d1*lab.d1-lab.d1*lab.d1)/(2*lbc.d1*lab.d1);
sanjiao.cos3=(lbc.d1*lbc.d1+lac.d1*lac.d1-lab.d1*lab.d1)/(2*lbc.d1*lac.d1);
if(sanjiao.cos1==0||sanjiao.cos2==0||sanjiao.cos3==0)
return true;
else
return false;
}
public boolean ruijiao(dian a,dian b,dian c,xian lab,xian lac,xian lbc,triangle sanjiao){
//判断是否是锐角三角形
lac.liangdian(a,c,lac);
lbc.liangdian(b,c,lbc);
lab.liangdian(a,b,lab);
sanjiao.cos1=(lac.d1*lac.d1+lab.d1*lab.d1-lbc.d1*lbc.d1)/(2*lac.d1*lab.d1);
sanjiao.cos2=(lbc.d1*lbc.d1+lab.d1*lab.d1-lab.d1*lab.d1)/(2*lbc.d1*lab.d1);
sanjiao.cos3=(lbc.d1*lbc.d1+lac.d1*lac.d1-lab.d1*lab.d1)/(2*lbc.d1*lac.d1);
if(sanjiao.cos1>0&&sanjiao.cos2>0&&sanjiao.cos3>0)
return true;
else
return false;
}
public boolean chonghe(dian a,dian b,dian c,dian d,dian e,xian l,xian lcd,xian lce,xian lde){
//判断直线是否与三角形的一条边重合//////////////////////////////////////////////////////////////
l.juli(c,a,b,l);
lcd.juli(a,c,d,lcd);
lce.juli(a,c,e,lce);
lde.juli(a,d,e,lde);
if((l.A==lcd.A&&l.B==lcd.B&&l.C==lcd.C)||(l.A==lce.A&&l.B==lce.B&&l.C==lce.C)||(l.A==lde.A&&l.B==lde.B&&l.C==lde.C))
return true;
else
return false;
}
public void whichsanjiao(triangle DEF,triangle CEF,triangle CDE,triangle CDF,dian c,dian d,dian e,dian f,xian lde,xian ldf,xian lef,xian lce,xian lcf,xian lcd){
//判断是哪三个点组成的三角形
if(shifou(d,e,f,lde,ldf,lef)&&(ldf.dianonxian(c,d,f,ldf)||(e.x==c.x&&e.y==c.y)))
DEF.flag=1;
else if(shifou(c,e,f,lce,lcf,lef)&&(lce.dianonxian(d,c,e,lce)||(d.x==f.x&&d.y==f.y)))
CEF.flag=1;
else if(shifou(c,d,e,lcd,lce,lde)&&(lce.dianonxian(f,c,e,lce)||(f.x==d.x&&f.y==d.y)))
CDE.flag=1;
else if(shifou(c,d,f,lcd,lcf,ldf)&&(ldf.dianonxian(e,d,f,ldf)||(e.x==c.x&&e.y==c.y)))
CDF.flag=1;
}
public boolean dianinsanjiao(dian a,dian b,dian c,dian d,xian lbc,xian lab,xian lac,triangle sanjiao)
{//判断点是否在三角形里边
double s1,s2,s3,s0;
mianji(a,b,c,lbc,sanjiao);
s0=sanjiao.s1;
mianji(d,a,b,lab,sanjiao);
s1=sanjiao.s1;
mianji(d,b,c,lbc,sanjiao);
s2=sanjiao.s1;
mianji(d,a,c,lac,sanjiao);
s3=sanjiao.s1;
if(Math.abs(s1+s2+s3-s0)<0.00000001)
return true;
else
return false;
}
}

class quadrangle{
double c1,s4;
public boolean pingxingsb(xian lac,xian lbc,xian lab,dian a,dian b,dian c,dian d,xian lcd,xian lad,quadrangle sibian){
//判断是否是平行四边形
lab.juli(c,a,b,lab);
lbc.juli(a,b,c,lbc);
lcd.juli(a,c,d,lcd);
lad.juli(b,a,d,lad);
if(lab.A*lcd.B==lab.B*lcd.A&&lbc.A*lad.B==lbc.B*lad.A)
{
return true;
}
else
return false;
}
public boolean lingxing(xian lac,xian lbc,xian lab,dian a,dian b,dian c,dian d,xian lcd,xian lad,quadrangle sibian){
//判断是否是菱形,邻边相等的平行四边形
if(pingxingsb(lac,lbc,lab,a,b,c,d,lcd,lad,sibian))
{
lab.liangdian(a,b,lab);
lbc.liangdian(b,c,lbc);
if(lab.d1==lbc.d1)
return true;
else
return false;
}
else
return false;
}
public boolean juxing(xian lac,xian lbc,xian lab,xian lbd,dian a,dian b,dian c,dian d,xian lcd,xian lad,quadrangle sibian){
//判断是否是矩形,有一个角为90度(用勾股定理算)的平行四边形
if(pingxingsb(lac,lbc,lab,a,b,c,d,lcd,lad,sibian))
{
lab.liangdian(a,b,lab);
lad.liangdian(a,d,lad);
lbd.liangdian(b,d,lbd);
if(Math.abs(lab.d1*lab.d1+lad.d1*lad.d1-lbd.d1*lbd.d1)<0.000001)
return true;
else
return false;
}
else
return false;
}
public boolean zhengfangxing(xian lac,xian lbc,xian lab,xian lbd,dian a,dian b,dian c,dian d,xian lcd,xian lad,quadrangle sibian){
//判断是否是正方形,邻边相等的矩形
if(juxing(lac,lbc,lab,lbd,a,b,c,d,lcd,lad,sibian))
{
lab.liangdian(a,b,lab);
lad.liangdian(a,d,lad);
if(lab.d1==lad.d1)
return true;
else
return false;
}
else
return false;
}
public boolean sidchonghe(dian a,dian b,dian c,dian d){
//判断四边形四点中是否有点重合
if((a.x==b.x&&a.y==b.y)||(a.x==c.x&&a.y==c.y)||(a.x==d.x&&a.y==d.y)||(b.x==c.x&&b.y==c.y)||(b.x==d.x&&b.y==d.y)||(c.x==d.x&&c.y==d.y))
return true;
else
return false;
}
public boolean tusibian(dian a,dian b,dian c,dian d,dian e,xian lac,xian lbd,xian lab,xian lbc,xian lad,xian lcd,triangle sanjiao){
//判断是否是凸四边形,对角线的交点是否在两对角线的线段上
if(!sanjiao.shifou(a,b,c,lab,lbc,lac)||!sanjiao.shifou(a,b,d,lab,lad,lbd)||!sanjiao.shifou(b,c,d,lbc,lbd,lcd)||!sanjiao.shifou(a,c,d,lcd,lac,lad))
return false;
else
{
if(lac.xiangjiao(a,c,b,d,e,lab,lcd)&&lbd.xiangjiao(a,c,b,d,e,lac,lbd))
return true;
else
return false;
}
}
public boolean ousibian(dian a,dian b,dian c,dian d,dian e,xian lac,xian lbd,xian lab,xian lbc,xian lad,xian lcd,triangle sanjiao){
//判断是否是凹四边形,对角线的交点是否在仅在其中一条的两对角线的线段上
if(!sanjiao.shifou(a,b,c,lab,lbc,lac)||!sanjiao.shifou(a,b,d,lab,lad,lbd)||!sanjiao.shifou(b,c,d,lbc,lbd,lcd)||!sanjiao.shifou(a,c,d,lcd,lac,lad))
return false;
else{
if( (lac.xiangjiao(a,c,b,d,e,lab,lcd)&&!lbd.xiangjiao(a,c,b,d,e,lac,lbd) )||( !lac.xiangjiao(a,c,b,d,e,lab,lcd) &&lbd.xiangjiao(a,c,b,d,e,lac,lbd) ) )
return true;
else
return false;
}
}
public void sibianzc(dian a,dian b,dian c,dian d,xian lab,xian lbc,xian lcd,xian lad,quadrangle sibian){
//计算四边形的周长
lab.liangdian(a,b,lab);
lbc.liangdian(b,c,lbc);
lcd.liangdian(c,d,lcd);
lad.liangdian(a,d,lad);
sibian.c1=lab.d1+lbc.d1+lcd.d1+lad.d1;
sibian.c1=Math.round(sibian.c1*1000)/(double)1000;
}
public void sibianmj(dian a,dian b,dian c,dian d,dian e,xian lab,xian lbc,xian lcd,xian lad,xian lac,xian lbd,triangle sanjiao,quadrangle sibian){
//计算四边形的面积
double flag1=0;
double flag2=0;
if(tusibian(a,b,c,d,e,lac,lbd,lab,lbc,lad,lcd,sanjiao))
{
sanjiao.mianji(a,b,d,lbd,sanjiao);
sibian.s4=sanjiao.s1;
sanjiao.mianji(c,b,d,lbd,sanjiao);
sibian.s4=sibian.s4+sanjiao.s1;
sibian.s4=Math.round(sibian.s4*1000)/(double)1000;
}
else{
if(lac.xiangjiao(a,c,b,d,e,lac,lbd))
flag1=1;
if(lbd.xiangjiao(b,d,a,c,e,lac,lbd))
flag2=1;
if(flag1==1)
{//BD做切线
sanjiao.mianji(a,b,d,lbd,sanjiao);
sibian.s4=sanjiao.s1;
sanjiao.mianji(c,b,d,lbd,sanjiao);
sibian.s4=sibian.s4+sanjiao.s1;
sibian.s4=Math.round(sibian.s4*1000)/(double)1000;
}
else{//AC做切线
sanjiao.mianji(d,a,c,lac,sanjiao);
sibian.s4=sanjiao.s1;
sanjiao.mianji(b,b,d,lac,sanjiao);
sibian.s4=sibian.s4+sanjiao.s1;
sibian.s4=Math.round(sibian.s4*1000)/(double)1000;
}
}
}
public boolean dianinsibian(dian a,dian b,dian c,dian d,dian e,dian q,xian lab,xian lbc,xian lcd,xian lad,xian lac,xian lbd,triangle sanjiao,quadrangle sibian){
//判断点是否在四边形里边
double s0,s1,s2,s3,s4;
sibianmj(a,b,c,d,q,lab,lbc,lcd,lad,lac,lbd,sanjiao,sibian);
s0=sibian.s4;
sanjiao.mianji(e,a,c,lac,sanjiao);
s1=sanjiao.s1;
sanjiao.mianji(e,c,d,lcd,sanjiao);
s2=sanjiao.s1;
sanjiao.mianji(e,b,d,lbd,sanjiao);
s3=sanjiao.s1;
sanjiao.mianji(e,a,b,lab,sanjiao);
s4=sanjiao.s1;
if(Math.abs(s1+s2+s3+s4-s0)<0.00000001)
return true;
else
return false;
}
}

class pantagon{
double c5,s5;
int biaoji1=0,biaoji2=0,biaoji3=0,biaoji4=0,biaoji5=0;
public boolean shifouwubian(dian a,dian b,dian c,dian d,dian e,dian q,xian lac,xian lbd,xian lab,xian lbc,xian lad,xian lcd,xian lde,xian lae,triangle sanjiao,quadrangle sibian,pantagon wubian)
{//判断是否是五边形
if(sibian.tusibian(a,b,c,d,q,lac,lbd,lab,lbc,lad,lcd,sanjiao)||sibian.ousibian(a,b,c,d,q,lac,lbd,lab,lbc,lad,lcd,sanjiao))
{//四边形ABCD
biaoji1=1;
if(lab.xiangjiao(d,e,a,b,q,lde,lab)||lcd.xiangjiao(a,e,c,b,q,lae,lcd)||lae.xiangjiao(a,e,b,c,q,lae,lbc)||lde.xiangjiao(d,e,b,c,q,lde,lbc))
return false;
else
return true;
}
else if(sibian.tusibian(b,c,d,e,q,lac,lbd,lab,lbc,lad,lcd,sanjiao)||sibian.ousibian(b,c,d,e,q,lac,lbd,lab,lbc,lad,lcd,sanjiao))
{//四边形BCDE
biaoji2=1;
if(lbc.xiangjiao(a,e,b,c,q,lae,lbc )||lde.xiangjiao(a,b,d,e,q,lab,lde)||lab.xiangjiao(a,b,c,d,q,lab,lcd)||lae.xiangjiao(a,e,c,d,q,lae,lcd))
return false;
else
return true;
}
else if(sibian.tusibian(a,c,d,e,q,lac,lbd,lab,lbc,lad,lcd,sanjiao)||sibian.ousibian(a,c,d,e,q,lac,lbd,lab,lbc,lad,lcd,sanjiao))
{//四边形ACDE
biaoji3=1;
if(lcd.xiangjiao(a,b,c,d,q,lab,lcd)||lae.xiangjiao(b,c,a,e,q,lbc,lae)||lab.xiangjiao(a,b,d,e,q,lab,lde)||lbc.xiangjiao(b,c,d,e,q,lbc,lde))
return false;
else
return true;
}
else if(sibian.tusibian(a,b,d,e,q,lac,lbd,lab,lbc,lad,lcd,sanjiao)||sibian.ousibian(a,b,d,e,q,lac,lbd,lab,lbc,lad,lcd,sanjiao))
{//四边形ABDE
biaoji4=1;
if(lde.xiangjiao(b,c,d,e,q,lbc,lde)||lab.xiangjiao(c,d,a,b,q,lab,lcd)||lbc.xiangjiao(b,c,a,e,q,lae,lbc)||lcd.xiangjiao(c,d,a,e,q,lae,lcd))
return false;
else
return true;
}
else if(sibian.tusibian(a,b,c,e,q,lac,lbd,lab,lbc,lad,lcd,sanjiao)||sibian.ousibian(a,b,c,e,q,lac,lbd,lab,lbc,lad,lcd,sanjiao))
{//四边形ABCE
biaoji5=1;
if(lbc.xiangjiao(d,e,b,c,q,lbc,lde)||lae.xiangjiao(c,d,a,e,q,lae,lcd)||lcd.xiangjiao(c,d,a,b,q,lcd,lab)||lde.xiangjiao(d,e,a,b,q,lde,lab))
return false;
else
return true;
}
else
return false;
}
public boolean tuwubian(dian a,dian b,dian c,dian d,dian e,dian q,xian lac,xian lbd,xian lab,xian lbc,xian lad,xian lcd,xian lde,xian lae,triangle sanjiao,quadrangle sibian,pantagon wubian)
{//判断是否是凸五边形
if(shifouwubian(a,b,c,d,e,q,lac,lbd,lab,lbc,lad,lcd,lde,lae,sanjiao,sibian,wubian))
{
if(wubian.biaoji1==1)
{//四边形ABCD
if(!sibian.dianinsibian(a,b,c,d,e,q,lab,lbc,lcd,lad,lac,lbd,sanjiao,sibian))
return true;
else
return false;
}
else if(wubian.biaoji2==1)
{//四边形BCDE
if(!sibian.dianinsibian(b,c,d,e,a,q,lab,lbc,lcd,lad,lac,lbd,sanjiao,sibian))
return true;
else
return false;
}
else if(wubian.biaoji3==1)
{//四边形ACDE
if(!sibian.dianinsibian(a,c,d,e,b,q,lab,lbc,lcd,lad,lac,lbd,sanjiao,sibian))
return true;
else
return false;
}
else if(wubian.biaoji4==1)
{//四边形ABDE
if(!sibian.dianinsibian(a,b,d,e,c,q,lab,lbc,lcd,lad,lac,lbd,sanjiao,sibian))
return true;
else
return false;
}
else if(wubian.biaoji5==1)
{//四边形ABCE
if(!sibian.dianinsibian(a,b,c,e,d,q,lab,lbc,lcd,lad,lac,lbd,sanjiao,sibian))
return true;
else
return false;
}
else
return false;
}
else
return false;
}
public void wubianmianji(dian a,dian b,dian c,dian d,dian e,xian lad,xian lbd,triangle sanjiao,pantagon wubian)
{//计算凸五边形的面积
double s1=0,s2=0,s3=0;
sanjiao.mianji(e,a,d,lad,sanjiao);
s1=sanjiao.s1;
sanjiao.mianji(a,b,d,lbd,sanjiao);
s2=sanjiao.s1;
sanjiao.mianji(c,b,d,lbd,sanjiao);
s3=sanjiao.s1;
wubian.s5=s1+s2+s3;
wubian.s5=Math.round(s5*1000)/(double)1000;
}
public void wubianzc(dian a,dian b,dian c,dian d,dian e,xian lab,xian lbc,xian lcd,xian lde,xian lae,pantagon wubian)
{//计算五边形的周长
lab.liangdian(a,b,lab);
lbc.liangdian(b,c,lbc);
lcd.liangdian(c,d,lcd);
lde.liangdian(d,e,lde);
lae.liangdian(a,e,lae);
wubian.c5=lab.d1+lbc.d1+lcd.d1+lde.d1+lae.d1;
wubian.c5=Math.round(c5*1000)/(double)1000;
}
public boolean wubchonghe(dian a,dian b,dian c,dian d,dian e,dian f,dian g,xian lab)
{//判断直线是否和五边形的其中一条边重合
lab.juli(c,a,b,lab);
if((lab.A*c.x+lab.B*c.y+lab.C)<0.00000001&&(lab.A*d.x+lab.B*d.y+lab.C)<0.00000001)
return true;
else if((lab.A*d.x+lab.B*d.y+lab.C)<0.00000001&&(lab.A*e.x+lab.B*e.y+lab.C)<0.00000001)
return true;
else if((lab.A*e.x+lab.B*e.y+lab.C)<0.00000001&&(lab.A*f.x+lab.B*f.y+lab.C)<0.00000001)
return true;
else if((lab.A*f.x+lab.B*f.y+lab.C)<0.00000001&&(lab.A*g.x+lab.B*g.y+lab.C)<0.00000001)
return true;
else if((lab.A*g.x+lab.B*g.y+lab.C)<0.00000001&&(lab.A*c.x+lab.B*c.y+lab.C)<0.00000001)
return true;
else{
return false;
}
}
}

public class Main{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
String input=in.nextLine();
if(input.charAt(1)!=':')
{
System.out.print("Wrong Format");
System.exit(0);
}
int count=0;
for(int u=0;u<input.length();u++)
{
if(input.charAt(u)==':')
count++;
}
if(count!=1)
{
System.out.print("Wrong Format");
System.exit(0);
}
dian a=new dian();
dian b=new dian();
dian c=new dian();
dian d=new dian();
dian e=new dian();
dian f=new dian();
dian g=new dian();
dian q=new dian();
dian p1=new dian();
dian p2=new dian();
xian lac=new xian();
xian lbd=new xian();
xian lab=new xian();
xian lbc=new xian();
xian lad=new xian();
xian lcd=new xian();
xian lde=new xian();
xian lae=new xian();
triangle sanjiao=new triangle();
quadrangle sibian=new quadrangle();
pantagon wubian=new pantagon();
if(input.charAt(0)=='1'||input.charAt(0)=='2')//输入情况1
{
String[] coord0=input.split(":| ");
for(int i=1;i<coord0.length;i++)
{
if(!coord0[i].matches("^[+-]?(0|(0\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?),[+-]?(0|(0\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?)$"))
{ System.out.print("Wrong Format");
System.exit(0);
}
}
if(coord0.length!=6)
{
System.out.print("wrong number of points");
System.exit(0);
}
String[] coord1=coord0[1].split(",");
String[] coord2=coord0[2].split(",");
String[] coord3=coord0[3].split(",");
String[] coord4=coord0[4].split(",");
String[] coord5=coord0[5].split(",");
double x1,x2,x3,x4,x5,y1,y2,y3,y4,y5;
x1=Double.parseDouble(coord1[0]);
y1=Double.parseDouble(coord1[1]);
x2=Double.parseDouble(coord2[0]);
y2=Double.parseDouble(coord2[1]);
x3=Double.parseDouble(coord3[0]);
y3=Double.parseDouble(coord3[1]);
x4=Double.parseDouble(coord4[0]);
y4=Double.parseDouble(coord4[1]);
x5=Double.parseDouble(coord5[0]);
y5=Double.parseDouble(coord5[1]);
a.x=x1;a.y=y1;
b.x=x2;b.y=y2;
c.x=x3;c.y=y3;
d.x=x4;d.y=y4;
e.x=x5;e.y=y5;
if(input.charAt(0)=='1')
{
if(wubian.shifouwubian(a,b,c,d,e,q,lac,lbd,lab,lbc,lad,lcd,lde,lae,sanjiao,sibian,wubian))
System.out.print("true");
else
System.out.print("false");
}
//if 1
if(input.charAt(0)=='2')
{
if(wubian.shifouwubian(a,b,c,d,e,q,lac,lbd,lab,lbc,lad,lcd,lde,lae,sanjiao,sibian,wubian))
{
if(wubian.tuwubian(a,b,c,d,e,q,lac,lbd,lab,lbc,lad,lcd,lde,lae,sanjiao,sibian,wubian))
{
wubian.wubianzc(a,b,c,d,e,lab,lbc,lcd,lde,lae,wubian);
wubian.wubianmianji(a,b,c,d,e,lad,lbd,sanjiao,wubian);
System.out.print("true "+wubian.c5+" "+wubian.s5);
}
else
{
System.out.print("false");
}
}
else{
System.out.print("not a pentagon");
}
}
}//if 1 2
else if(input.charAt(0)=='3')
{
String[] coord0=input.split(":| ");
for(int i=1;i<coord0.length;i++)
{
if(!coord0[i].matches("^[+-]?(0|(0\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?),[+-]?(0|(0\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?)$"))
{ System.out.print("Wrong Format");
System.exit(0);
}
}
if(coord0.length!=8)
{
System.out.print("wrong number of points");
System.exit(0);
}
String[] coord1=coord0[1].split(",");
String[] coord2=coord0[2].split(",");
String[] coord3=coord0[3].split(",");
String[] coord4=coord0[4].split(",");
String[] coord5=coord0[5].split(",");
String[] coord6=coord0[6].split(",");
String[] coord7=coord0[7].split(",");
double x1,x2,x3,x4,x5,x6,x7,y1,y2,y3,y4,y5,y6,y7;
x1=Double.parseDouble(coord1[0]);
y1=Double.parseDouble(coord1[1]);
x2=Double.parseDouble(coord2[0]);
y2=Double.parseDouble(coord2[1]);
x3=Double.parseDouble(coord3[0]);
y3=Double.parseDouble(coord3[1]);
x4=Double.parseDouble(coord4[0]);
y4=Double.parseDouble(coord4[1]);
x5=Double.parseDouble(coord5[0]);
y5=Double.parseDouble(coord5[1]);
x6=Double.parseDouble(coord6[0]);
y6=Double.parseDouble(coord6[1]);
x7=Double.parseDouble(coord7[0]);
y7=Double.parseDouble(coord7[1]);
a.x=x1;a.y=y1;
b.x=x2;b.y=y2;
c.x=x3;c.y=y3;
d.x=x4;d.y=y4;
e.x=x5;e.y=y5;
f.x=x6;f.y=y6;
g.x=x7;g.y=x7;
if(x1==x2&&y1==y2)
System.out.println("points coincide");
else
{
/* if(wubian.tuwubian(a,b,c,d,e,q,lac,lbd,lab,lbc,lad,lcd,sanjiao,sibian,wubian))
{//如果后面五个点可以构成凸五边形
int flag11=0,flag22=0,flag33=0,flag44=0,flag55=0,sum=0;
double xx1=0,yy1=0,xx2=0,yy2=0,xx3=0,yy3=0,xx4=0,yy4=0,xx5=0,yy5=0;
if(lab.xiangjiao(a,b,c,d,q,lab,lcd))
flag11=1; xx1=q.x; yy1=q.y; sum++;
if(lab.xiangjiao(a,b,d,e,q,lab,lcd))
flag22=1; xx2=q.x; yy2=q.y; sum++;
if(lab.xiangjiao(a,b,e,f,q,lab,lcd))
flag33=1; xx3=q.x; yy3=q.y; sum++;
if(lab.xiangjiao(a,b,f,g,q,lab,lcd))
flag44=1; xx4=q.x; yy4=q.y; sum++;
if(lab.xiangjiao(a,b,c,g,q,lab,lcd))
flag55=1; xx5=q.x; yy5=q.y; sum++;
if(sum>2)
sum=2;
System.out.print(sum+" ");
if(sum<2)
System.exit(0);
if(wubian.wubchonghe(a,b,c,d,e,f,g,lab))
{
System.out.println("The line is coincide with one of the lines");
System.exit(0);
}
double s1=0,s2=0,s0=0;
wubian.wubianmianji(c,d,e,f,g,lad,lbd,sanjiao,wubian);
s0=wubian.s5;
if(flag11==1&&flag22==1)
{
p1.x=xx1; p1.y=yy1;
p2.x=xx2; p2.y=yy2;
sanjiao.mianji(d,p1,p2,lbc,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
}
else if(flag22==1&&flag33==1)
{
p1.x=xx2; p1.y=yy2;
p2.x=xx3; p2.y=yy3;
sanjiao.mianji(e,p1,p2,lbc,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
}
else if(flag33==1&&flag44==1)
{
p1.x=xx3; p1.y=yy3;
p2.x=xx4; p2.y=yy4;
sanjiao.mianji(f,p1,p2,lbc,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
}
else if(flag44==1&&flag55==1)
{
p1.x=xx4; p1.y=yy4;
p2.x=xx5; p2.y=yy5;
sanjiao.mianji(g,p1,p2,lbc,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
}
else if(flag11==1&&flag55==1)
{
p1.x=xx1; p1.y=yy1;
p2.x=xx5; p2.y=yy5;
sanjiao.mianji(c,p1,p2,lbc,sanjiao);
s1=sanjiao.s1;
s2=s0-s1;
}
else if(flag11==1&&flag33==1)
{
p1.x=xx1; p1.y=yy1;
p2.x=xx3; p2.y=yy3;
sanjiao.mianji(p1,d,e,lbc,sanjiao);
s1=sanjiao.s1;
sanjiao.mianji(p1,p2,e,lbc,sanjiao);
s1=s1+sanjiao.s1;
s2=s0-s1;
}
else if(flag11==1&&flag44==1)
{
p1.x=xx1; p1.y=yy1;
p2.x=xx4; p2.y=yy4;
sanjiao.mianji(p1,p2,c,lbc,sanjiao);
s1=sanjiao.s1;
sanjiao.mianji(p2,c,g,lbc,sanjiao);
s1=s1+sanjiao.s1;
s2=s0-s1;
}
else if(flag22==1&&flag44==1)
{
p1.x=xx2; p1.y=yy2;
p2.x=xx4; p2.y=yy4;
sanjiao.mianji(p1,p2,e,lbc,sanjiao);
s1=sanjiao.s1;
sanjiao.mianji(p2,e,f,lbc,sanjiao);
s1=s1+sanjiao.s1;
s2=s0-s1;
}
else if(flag22==1&&flag55==1)
{
p1.x=xx2; p1.y=yy2;
p2.x=xx5; p2.y=yy5;
sanjiao.mianji(p1,c,d,lbc,sanjiao);
s1=sanjiao.s1;
sanjiao.mianji(p1,p2,c,lbc,sanjiao);
s1=s1+sanjiao.s1;
s2=s0-s1;
}
else if(flag33==1&&flag55==1)
{
p1.x=xx3; p1.y=yy3;
p2.x=xx5; p2.y=yy5;
sanjiao.mianji(p1,p2,f,lbc,sanjiao);
s1=sanjiao.s1;
sanjiao.mianji(p2,g,f,lbc,sanjiao);
s1=s1+sanjiao.s1;
s2=s0-s1;
}
if(s1<s2)
System.out.print(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
else
System.out.print(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
}//凸五边形*/
}
}//if 3
else{
System.out.print("Wrong Format");
System.exit(0);
}
}
}

复制代码

 分析如下:

     这是继承直线、三角形和四边形之后的升级版,输入五个点既要判断是否为五边形又要判断为什么形状。输入七个点时要考虑后五个点是否是五边形,凸五边形还是四边形还是三角形,需要考虑的情况很多,题目很复杂。

 7-1.(3)踩坑心得:

遇到的问题:

  由于代码的书写比较冗余,导致遇到问题很难找到错的地方,除了语法问题系统会报错得以解决,一些逻辑问题只能通过很多样例不停调试,大大增加了写代码的复杂度和时间。。

心得及总结:

   规范代码的书写,这样可以在后面寻找的时候方便许多,注意数组的范围,数组范围索引越界处理起来复杂,在运行之后才能发现,所以要注意数组的范围

7-1(4)改进建议

  在面对大代码量的题目,多次操作多做操作的题目可以用switch然后对应每一个操作定制一个函数,这样会在后期修改,选择函数会方便许多,像上次图像题目代码量太大,操作多,用if-else会有大量的代码去写,到最后,进行修改代码的时候非常麻烦,非常难找。

7-2(1) 题目:

7-2 点线形系列5-凸五边形的计算-2 分数 50 作者 蔡轲 单位 南昌航空大学

用户输入一组选项和数据,进行与五边形有关的计算。
以下五边形顶点的坐标要求按顺序依次输入,连续输入的两个顶点是相邻顶点,第一个和最后一个输入的顶点相邻。
选项包括:
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

7-2(2)设计与分析:

  

 

 

 

复制代码
public class Main
{
    public static void main(String[] args)
    {
        Scanner input=new Scanner(
System.in);
        String str,s2;
        str=input.nextLine();
        Judge.cheek(str);
        String[] s1, s3, num;
        ArrayList<Point> InPoints=new ArrayList<>();
        ArrayList<Point> InPoints2=new ArrayList<>();
        int t,k=0;
        char a=str.charAt(0);
        s1 = str.split(":");
        s2 = s1[1];
        s3 = s2.split(" ");
        Point point=new Point();
        Line line=new Line();
        Triangle triangle=new Triangle();
        Quadrilateral quadrilateral=new Quadrilateral();
        Pentagon pentagon=new Pentagon();
        Relation relation=new Relation();
        Relation relation2=new Relation();
        t=s3.length;
        for(String n:s3)
        {
            num = n.split(",");
            Point in=new Point(Double.parseDouble(num[0]),Double.parseDouble(num[1]));
            k++;
            if(t==10)
            {
                if(k<=5)
                {
                    if(!point.repeat(in,InPoints))
                        InPoints.add(in);
                }
                else
                {
                    if(!point.repeat(in,InPoints2))
                        InPoints2.add(in);
                }
            }
            else
            {
                if(k<=1)
                    InPoints.add(in);
                else
                {
                    if(!point.repeat(in,InPoints2))
                        InPoints2.add(in);
                }
            }
        }
        for(int i=0;i<InPoints.size()-2;i++)
        {
            if(point.collinear2(InPoints.get(i),InPoints.get(i+1),InPoints.get(i+2)))
            {
                InPoints.remove(i+1);
                i--;
            }
        }
        if(InPoints.size()>=3&&point.collinear2(InPoints.get(InPoints.size()-1),InPoints.get(0),InPoints.get(1)))
        {
            InPoints.remove(0);
        }
        if(InPoints.size()>=3&&point.collinear2(InPoints.get(InPoints.size()-2),InPoints.get(InPoints.size()-1),InPoints.get(0)))
        {
            InPoints.remove(InPoints.size()-1);
        }
        for(int i=0;i<InPoints2.size()-2;i++)
        {
            if(point.collinear2(InPoints2.get(i),InPoints2.get(i+1),InPoints2.get(i+2)))
            {
                InPoints2.remove(i+1);
                i--;
            }
        }
        if(InPoints2.size()>=3&&point.collinear2(InPoints2.get(InPoints2.size()-1),InPoints2.get(0),InPoints2.get(1)))
        {
            InPoints2.remove(0);
        }
        if(InPoints2.size()>=3&&point.collinear2(InPoints2.get(InPoints2.size()-2),InPoints2.get(InPoints2.size()-1),InPoints2.get(0)))
        {
            InPoints2.remove(InPoints2.size()-1);
        }
        switch (a)
        {
            case '4':
                relation.getCount(InPoints,InPoints2);
                relation2.getCount(InPoints2,InPoints);
                if(relation.out==InPoints.size()&&relation2.out==InPoints2.size())
                {
                    System.out.print("no overlapping area between the previous ");
                    if(InPoints.size()==3)
                        System.out.print("triangle and the following ");
                    else if(InPoints.size()==4)
                        System.out.print("quadrilateral and the following ");
                    else
                        System.out.print("pentagon and the following ");
                    if(InPoints2.size()==3)
                        System.out.print("triangle");
                    else if(InPoints2.size()==4)
                        System.out.print("quadrilateral");
                    else
                        System.out.print("pentagon");
                }
                else if(relation.on==InPoints.size()&&relation2.on==InPoints2.size())
                {
                    System.out.print("the previous ");
                    if(InPoints.size()==3)
                        System.out.print("triangle coincides with the following ");
复制代码    else if(InPoints.size()==4)
                        System.out.print("quadrilateral coincides with the following ");
                    else
                        System.out.print("pentagon coincides with the following ");
                    if(InPoints2.size()==3)
                        System.out.print("triangle");
                    else if(InPoints2.size()==4)
                        System.out.print("quadrilateral");
                    else
                        System.out.print("pentagon");
                }
                else if(relation.out==0)
                {
                    System.out.print("the previous ");
                    if(InPoints.size()==3)
                        System.out.print("triangle is inside the following ");
                    else if(InPoints.size()==4)
                        System.out.print("quadrilateral is inside the following ");
                    else
                        System.out.print("pentagon is inside the following ");
                    if(InPoints2.size()==3)
                        System.out.print("triangle");
                    else if(InPoints2.size()==4)
                        System.out.print("quadrilateral");
                    else
                        System.out.print("pentagon");
                }
                else if(relation2.out==0)
                {
                    System.out.print("the previous ");
                    if(InPoints.size()==3)
                        System.out.print("triangle contains the following ");
                    else if(InPoints.size()==4)
                        System.out.print("quadrilateral contains the following ");
                    else
                        System.out.print("pentagon contains the following ");
                    if(InPoints2.size()==3)
                        System.out.print("triangle");
                    else if(InPoints2.size()==4)
                        System.out.print("quadrilateral");
                    else
                        System.out.print("pentagon");
                }
                else if(relation.coincide(relation.OnPoints,InPoints2)&&relation.in==0&&relation2.in==0)
                {
                    System.out.print("the previous ");
                    if(InPoints.size()==3)
                        System.out.print("triangle is connected to the following ");
                    else if(InPoints.size()==4)
                        System.out.print("quadrilateral is connected to the following ");
                    else
                        System.out.print("pentagon is connected to the following ");
                    if(InPoints2.size()==3)
                        System.out.print("triangle");
                    else if(InPoints2.size()==4)
                        System.out.print("quadrilateral");
                    else
                        System.out.print("pentagon");
                }
                else
                {
                    System.out.print("the previous ");
                    if(InPoints.size()==3)
                        System.out.print("triangle is interlaced with the following ");
                    else if(InPoints.size()==4)
                        System.out.print("quadrilateral is interlaced with the following ");
                    else
                        System.out.print("pentagon is interlaced with the following ");
                    if(InPoints2.size()==3)
                        System.out.print("triangle");
                    else if(InPoints2.size()==4)
                        System.out.print("quadrilateral");
                    else
                        System.out.print("pentagon");
                }
                break;
            case '5':
                double s;
                relation.getCount(InPoints,InPoints2);
                relation2.getCount(InPoints2,InPoints);
                Cut cut=new Cut();
                ArrayList<Point> cutPoints=new ArrayList<>();
                cutPoints.addAll(relation.InPoints);
                cutPoints.addAll(relation.OnPoints);
                cutPoints.addAll(relation2.InPoints);
                cut.sort(cutPoints);
                s= cut.getArea(cutPoints);
                System.out.print(Judge.change(s));
                break;
            case '6':
                if(InPoints2.size()==3&&triangle.isOn(InPoints.get(0),InPoints2))
                    System.out.print("on the triangle");
 else if(InPoints2.size()==3&&triangle.InOrOut(InPoints.get(0),InPoints2.get(0),InPoints2.get(1),InPoints2.get(2)))
                    System.out.print("in the triangle");
                else if(InPoints2.size()==3&&!triangle.InOrOut(InPoints.get(0),InPoints2.get(0),InPoints2.get(1),InPoints2.get(2)))
                    System.out.print("outof the triangle");
                else if(InPoints2.size()==4&&quadrilateral.isOn(InPoints.get(0),InPoints2))
                    System.out.print("on the quadrilateral");
                else if(InPoints2.size()==4&&quadrilateral.InOrOut(InPoints.get(0),InPoints2.get(0),InPoints2.get(1),InPoints2.get(2),InPoints2.get(3)))
                    System.out.print("in the quadrilateral");
                else if(InPoints2.size()==4&&!quadrilateral.InOrOut(InPoints.get(0),InPoints2.get(0),InPoints2.get(1),InPoints2.get(2),InPoints2.get(3)))
                    System.out.print("outof the quadrilateral");
                else if(InPoints2.size()==5&&pentagon.isOn(InPoints.get(0),InPoints2))
                    System.out.print("on the pentagon");
                else if(InPoints2.size()==5&&pentagon.InOrOut(InPoints.get(0),InPoints2.get(0),InPoints2.get(1),InPoints2.get(2),InPoints2.get(3),InPoints2.get(4)))
                    System.out.print("in the pentagon");
                else
                    System.out.print("outof the pentagon");
                break;
        }
    }
}

分析如下:

  本题为点线型系列的进阶题,从面向对象和方法设计出发,进行五边形为主的图形化设计。

7-2(3)踩坑心得:

遇到的问题:

   这道题目是这几次作业中最复杂的一题 ,遇到的问题非常多,最主要的原因还是不会用类的继承和接口,导致代码又臭又长,还得不了满分,所以这里我只放了主函数的代码。

心得及总结:

  本题主函数采用switch case语句,每个语句对应题目中所给出的一个选项;在点类与线类的基础上,增加五边形(Pentagen)的输入格式正确判断函数。本题是点线形系列最后一个类型的第一部分,难度显著提升,主要还是考察类与对象含义的理解和运用.

7-2(4)改进建议:

在输出函数里面 不要把算术放里面,这样在后面寻找错误的时候麻烦,难找还要修改,不如直接就分开写,在一些算法,思路方面可以在代码边上写注释,后面回来看的时候会方便很多。

四、期中:

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

  • 设计一个类表示平面直角坐标系上的线Line,私有属性除了标识线段两端的点point1、point2外,还有一个字符串类型的color,用于表示该线段的颜色,同样,除构造方法以及属性的getter与setter方法外,定义一个用于计算该线段长度的方法getDistance(),还有一个用于显示信息的方法display(),用来输出线段的相关信息,输出格式如下:

      ```
          The line's color is:颜色值
          The line's begin point's Coordinate is:
          (x1,y1)
          The line's end point's Coordinate is:
          (x2,y2)
          The line's length is:长度值
      ```
    
     

    其中,所有数值均保留两位小数,建议可用String.format("%.2f", data)方法。

      设计类图如下图所示。
    
     

1641304523(1).jpg

** 题目要求:在主方法中定义一条线段对象,从键盘输入该线段的起点坐标与终点坐标以及颜色,然后调用该线段的display()方法进行输出。**

  • 以下情况为无效作业
    • 无法运行
    • 设计不符合所给类图要求
    • 未通过任何测试点测试
    • 判定为抄袭

7-1(2)设计与分析:

  

 

 

复制代码

import java.text.DecimalFormat;
import java.util.Scanner;
public class Main{
public static void main(String []args) {
Scanner input =new Scanner(System.in);

Point point1= new Point(input.nextDouble(),input.nextDouble());
Point point2= new Point(input.nextDouble(),input.nextDouble());
Line line = new Line(point1,point2,input.next());
if((point1.getX()<=0||point1.getX()>200)||(point1.getY()<=0)||(point1.getY()>200)) {
System.out.println("Wrong Format");
System.exit(0);
}
if((point2.getX()<=0||point2.getX()>200)||(point2.getY()<=0)||(point2.getY()>200)) {
System.out.println("Wrong Format");
System.exit(0);
}
line.display();
}
}

class Point{
private double x;
private double y;

public Point() {

}

public Point(double x, double y) {
super();
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() {
if((x<=0||x>200)||(y<=0)||(y>200)) {
System.out.println("Wrong Format");
System.exit(0);
}
}
}
class Line{
private Point point1;
private Point point2;
private String color;
public Line() {

}

public Line(Point point1, Point point2, String color ) {
super();
this.point1 = point1;
this.point2 = point2;
this.color = color;
}
public Point getPoint1() {
return point1;
}
public void setPoint1(Point point1) {
this.point1=point1;
}
public Point getPoint2() {
return point2;
}
public void setPoint2(Point point2) {
this.point2=point2;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color=color;
}
public double getDistance(Point point1,Point point2) {
double a;
a=Math.sqrt((point1.getX()-point2.getX())*(point1.getX()-point2.getX())+(point1.getY()-point2.getY())*(point1.getY()-point2.getY()));
return a;
}
public void display() {
System.out.println("The line's color is:"+getColor());
System.out.println("The line's begin point's Coordinate is:");
System.out.print("(");
System.out.printf("%.2f,%.2f",point1.getX(),point1.getY());
System.out.println(")");
System.out.println("The line's end point's Coordinate is:");
System.out.print("(");
System.out.printf("%.2f,%.2f",point2.getX(),point2.getY());
System.out.println(")");
System.out.print("The line's length is:");
System.out.printf("%.2f",getDistance(point1,point2));
}
}复制代码

 分析如下: 

    本题一共设计了两个类。一个是Point类,一个是Line类。

    Point类用来定义一个点,构造一个有参构造器,里面设置判断条件,如果成立则构造点,如果不成立则输出"Wrong Format"并结束进程。该类中还构造了一个display方法,方便后续输出点坐标。Line类用来定义一条线,构造有参构造器来接收Point类和String类数据,构造getDistance方法来计算线段长度,构造display方法输出结果。由于类图题中都给出了类图基本上确定的,所以没有很高的复杂度。复杂度都在绿环内。

 7-1.(3)踩坑心得:

遇到的问题:

最开始不知道为啥运行超时,后面发现关于点的getX函数进不去,经过不断调试后编译成功。

 

 

 

心得及总结:

     因为第一题是其他题目的基础有,第一题要多花写时间检查,如果第一题写出了后面回来修改还是非常麻烦的。

7-1(4)改进建议

题中给出了类图,基本框架是固定的,填满代码实现题目要求即可,没有改进建议。

7-2(1) 题目:

  7-2 点线面问题重构(继承与多态) 分数 40 作者 段喜龙 单位 南昌航空大学

在“点与线(类设计)”题目基础上,对题目的类设计进行重构,以实现继承与多态的技术性需求。

  • 对题目中的点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()方法,从而实现多态特性。示例代码如下:
          element = p1;//起点Point
          element.display();
          
          element = p2;//终点Point
          element.display();
          
          element = line;//线段
          element.display();
          
          element = plane;//面
          element.display();
    
      类结构如下图所示。

1641340607(1).jpg

其中,所有数值均保留两位小数,建议可用String.format("%.2f", data)方法。

  • 以下情况为无效作业
    • 无法运行
    • 设计不符合所给类图要求
    • 未通过任何测试点测试
    • 判定为抄袭

7-2(2)设计与分析:

  

复制代码

import java.text.DecimalFormat;
import java.util.Scanner;
public class Main{
public static void main(String []args) {
Scanner input =new Scanner(System.in);

Point point1= new Point(input.nextDouble(),input.nextDouble());
Point point2= new Point(input.nextDouble(),input.nextDouble());
Line line = new Line(point1,point2,input.next());
Plane plane=new Plane(line.getColor());
if((point1.getX()<=0||point1.getX()>200)||(point1.getY()<=0)||(point1.getY()>200)) {
System.out.println("Wrong Format");
System.exit(0);
}
if((point2.getX()<=0||point2.getX()>200)||(point2.getY()<=0)||(point2.getY()>200)) {
System.out.println("Wrong Format");
System.exit(0);
}
line.display();
plane.display();
}
}

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

public Point() {

}

public Point(double x, double y) {
super();
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() {
if((x<=0||x>200)||(y<=0)||(y>200)) {
System.out.println("Wrong Format");
System.exit(0);
}
}
}
class Line extends Element{
private Point point1;
private Point point2;
private String color;
public Line() {

}

public Line(Point point1, Point point2, String color ) {
super();
this.point1 = point1;
this.point2 = point2;
this.color = color;
}
public Point getPoint1() {
return point1;
}
public void setPoint1(Point point1) {
this.point1=point1;
}
public Point getPoint2() {
return point2;
}
public void setPoint2(Point point2) {
this.point2=point2;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color=color;
}
public static double getDistance(Point point1,Point point2) {
double a;
a=Math.sqrt((point1.getX()-point2.getX())*(point1.getX()-point2.getX())+(point1.getY()-point2.getY())*(point1.getY()-point2.getY()));
return a;
}
public void display() {
System.out.print("(");
System.out.printf("%.2f,%.2f",point1.getX(),point1.getY());
System.out.println(")");

System.out.print("(");
System.out.printf("%.2f,%.2f",point2.getX(),point2.getY());
System.out.println(")");
System.out.println("The line's color is:"+getColor());
System.out.println("The line's begin point's Coordinate is:");
System.out.print("(");
System.out.printf("%.2f,%.2f",point1.getX(),point1.getY());
System.out.println(")");
System.out.println("The line's end point's Coordinate is:");
System.out.print("(");
System.out.printf("%.2f,%.2f",point2.getX(),point2.getY());
System.out.println(")");
System.out.print("The line's length is:");
System.out.printf("%.2f\n",getDistance(point1,point2));
}
}
class Plane extends Element{
private String color;

public Plane(String color) {
super();
this.color = color;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color=color;
}
public void display() {
System.out.println("The Plane's color is:"+getColor());
}
}
class Element{
private double x;
private double y;
private Point point1;
private Point point2;
private String color;
public void display() {
System.out.print("(");
System.out.printf("%.2f,%.2f",point1.getX(),point1.getY());
System.out.println(")");

System.out.print("(");
System.out.printf("%.2f,%.2f",point2.getX(),point2.getY());
System.out.println(")");

System.out.println("The line's begin point's Coordinate is:");
System.out.print("(");
System.out.printf("%.2f,%.2f",point1.getX(),point1.getY());
System.out.println(")");
System.out.println("The line's end point's Coordinate is:");
System.out.print("(");
System.out.printf("%.2f,%.2f",point1.getX(),point1.getY());
System.out.println(")");
System.out.print("The line's length is:");
System.out.printf("%.2f",Line.getDistance(point1,point2));
}
}

分析如下:

    本题一共设计了四个类。在第一题的基础上,增加一个抽象类Element作为Point、Line、Plane的父类,其中只定义一个抽象方法display。在每个子类中重写display方法以实现不同的输出内容。

  一开始写的时候没看到题干中给出的实现多态特性的那段代码,虽然不影响最后结果的输出。 

 

7-2(3)踩坑心得:

遇到的问题:

  最开始没有运用继承来写码,而且由于第一题 的运行超时问题,最开始第二题只得了十六分,重新返工第一题后,第二题才开始能多的一些分。

心得及总结:

     定义新的面类,还有一个共同的父类,类是抽象的,还有抽象方法,在每一个子类中都要重新抽象类的抽象方法,然后同过父类来new子类,形成多态,父类就可以调用子类方法,使的主方法更加美观,看起来清晰易懂

7-2(4)改进建议:

 题目难度适中,没有改进建议。

7-3(1) 题目: 

7-3 点线面问题再重构(容器类) 分数 40 作者 段喜龙 单位 南昌航空大学

在“点与线(继承与多态)”题目基础上,对题目的类设计进行重构,增加容器类保存点、线、面对象,并对该容器进行相应增、删、遍历操作。

  • 在原有类设计的基础上,增加一个GeometryObject容器类,其属性为ArrayList<Element>类型的对象(若不了解泛型,可以不使用<Element>
  • 增加该类的add()方法及remove(int index)方法,其功能分别为向容器中增加对象及删除第index - 1(ArrayList中index>=0)个对象
  • 在主方法中,用户循环输入要进行的操作(choice∈[0,4]),其含义如下:
    • 1:向容器中增加Point对象
    • 2:向容器中增加Line对象
    • 3:向容器中增加Plane对象
    • 4:删除容器中第index - 1个数据,若index数据非法,则无视此操作
    • 0:输入结束
    示例代码如下:
       choice = input.nextInt();
        while(choice != 0) {
            switch(choice) {
            case 1://insert Point object into list 
              ...
                break;
            case 2://insert Line object into list
                ...
                break;
            case 3://insert Plane object into list
                ...
                break;
            case 4://delete index - 1 object from list
                int index = input.nextInt();
                ...
            }
            choice = input.nextInt();
        }
    
      输入结束后,按容器中的对象顺序分别调用每个对象的display()方法进行输出。
    类图如下所示:

classdiagram.jpg

  • 以下情况为无效作业
    • 无法运行
    • 设计不符合所给类图要求
    • 未通过任何测试点测试
    • 判定为抄袭

7-3(2)设计与分析:

  

复制代码

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Scanner;
public class Main{
public static void main(String []args) {
Scanner input =new Scanner(System.in);
int choice = input.nextInt();
ArrayList<Element> list = new ArrayList<Element>();
while(choice != 0) {
switch(choice) {
case 1://insert Point object into list
Point point1= new Point(input.nextDouble(),input.nextDouble());
list.add(point1);
break;
case 2://insert Line object into list
Point point3= new Point(input.nextDouble(),input.nextDouble());
Point point2= new Point(input.nextDouble(),input.nextDouble());
Line line = new Line(point3,point2,input.next());
list.add(line);
break;
case 3://insert Plane object into list
Plane plane=new Plane(input.next());
list.add(plane);
break;
case 4://delete index - 1 object from list
int index = input.nextInt();

list.remove(index-1);


}
choice = input.nextInt();
}
for (Element element : list) {
element.display();
}

}
}




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

public Point() {

}

public Point(double x, double y) {
super();
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() {
if((x<=0||x>200)||(y<=0)||(y>200)) {
System.out.println("Wrong Format");
System.exit(0);
}else {
System.out.print("(");
System.out.printf("%.2f,%.2f",x,y);
System.out.println(")");

}
}
}
class Line extends Element{
private Point point1;
private Point point2;
private String color;
public Line() {

}

public Line(Point point1, Point point2, String color ) {
super();
this.point1 = point1;
this.point2 = point2;
this.color = color;
}
public Point getPoint1() {
return point1;
}
public void setPoint1(Point point1) {
this.point1=point1;
}
public Point getPoint2() {
return point2;
}
public void setPoint2(Point point2) {
this.point2=point2;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color=color;
}
public static double getDistance(Point point1,Point point2) {
double a;
a=Math.sqrt((point1.getX()-point2.getX())*(point1.getX()-point2.getX())+(point1.getY()-point2.getY())*(point1.getY()-point2.getY()));
return a;
}
public void display() {
System.out.println("The line's color is:"+getColor());
System.out.println("The line's begin point's Coordinate is:");
System.out.print("(");
System.out.printf("%.2f,%.2f",point1.getX(),point1.getY());
System.out.println(")");
System.out.println("The line's end point's Coordinate is:");
System.out.print("(");
System.out.printf("%.2f,%.2f",point2.getX(),point2.getY());
System.out.println(")");
System.out.print("The line's length is:");
System.out.printf("%.2f\n",getDistance(point1,point2));
}
}
class Plane extends Element{
private String color;

public Plane(String color) {
super();
this.color = color;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color=color;
}
public void display() {
System.out.println("The Plane's color is:"+getColor());
}
}
class Element{
private double x;
private double y;
private Point point1;
private Point point2;
private String color;
public void display() {
System.out.print("(");
System.out.printf("%.2f,%.2f",point1.getX(),point1.getY());
System.out.println(")");

System.out.print("(");
System.out.printf("%.2f,%.2f",point2.getX(),point2.getY());
System.out.println(")");

System.out.println("The line's begin point's Coordinate is:");
System.out.print("(");
System.out.printf("%.2f,%.2f",point1.getX(),point1.getY());
System.out.println(")");
System.out.println("The line's end point's Coordinate is:");
System.out.print("(");
System.out.printf("%.2f,%.2f",point1.getX(),point1.getY());
System.out.println(")");
System.out.print("The line's length is:");
System.out.printf("%.2f",Line.getDistance(point1,point2));
}
}
class GeometryObject{
ArrayList<Element> list = new ArrayList<Element>();

public GeometryObject() {
super();
}
public void add(Element element) {
list.add(element);
}
public void remove(int index) {
if(index>0)
list.remove(index);
}
public ArrayList<Element> getList(){
return list;

}
}

复制代码

 分析如下:

    本题一共设计了五个类。在第二题的基础上,新增加一个容器类GeometryObject,创建一个泛型链表以储存element类型数据。类中创建add方法来添加成员,remove方法来删除指定位置的成员。

一个容器只能装入一种类型,但是可以同过多态的形式来装的同一类型的不同形式,通过装入父类,把不同类型装入,最后在输出的时候可以统一调用display方法,不同判断是什么类型,非常方便。

 7-3.(3)踩坑心得:

遇到的问题:

    在一开始没意识到容器类这个东西,导致虽然写了这个类,却没有用这个类去声明对象然后调用方法,导致和题目给出的类图不一样,然后快写完的时候才发现错误,所以又花了一些时间去重新写。

心得及总结:

  第二题的升级版,生成一个容器类,要求有容器的相关功能

将多态传入容器,在容器是进行容器操作,在删除操作的时候要注意容器的范围,如果输入不合法则会自动跳过改操作。

7-3(4)改进建议

难度加大,要熟练掌握多态和继承,没有改进建议。

五、总结:

      第四次和第五次PTA大作业题目明显复杂了很多,由于最开始我不会用继承及多态抽象类,导致代码也越来越复杂,不仅增加了代码的复杂度和长度,到第五次大作业时甚至出现代码超出代码长度都无法写完题目的程度。为了精简代码和进一步的学习,所以我更加熟悉了类是什么,方法是什么。之后的这段时间里我学习了异常处理、抛出异常以及多态抽象类和接口的基本使用后,代码的长度开始精简了一些,没有之前写代码时冗余度那么高了。

         通过期中考试,我更加了解了类的定义,抽象类的使用,还有容器类的原理,以及对继承和多态的使用掌握了更加深刻。在考试时由于对继承和多态的使用不够熟练,时间对我来说不太够用,没有得满分,我明白了在学习的过程中还有一些地方有待加强,要多做一些相关题目,加强理解。

 

标签:dian,JAVA,期中考试,xian,System,lab,lbc,sanjiao,PTA
From: https://www.cnblogs.com/wdbbl0101/p/16840004.html

相关文章

  • Javaweb基础复习------Cookie+Session案例的实现(登录注册案例)
    Cookie对象的创建--Cookiecookie=newCookie("key","value");发送Cookie:resp.addCookie();获取Cookie数据:req.getCookie("","");Cookie不能直接存储中文需要进行转......
  • LeetCode 题解 | 1. 两数之和 Javascript 版
    题目给定一个整数数组nums 和一个整数目标值target,请你在该数组中找出和为目标值target 的那 两个 整数,并返回它们的数组下标。你可以假设每种输入只会对应一个......
  • LeetCode 题解 | 3. 无重复字符的最长子串 Javascript
    /***@param{string}str*@returnsnumber*思路:1.start与range组合成一个窗口,窗口内的子串就是当前最长不重复的字符串*2.range每次循环递增*......
  • JAVA-JButton 窗口中添加按钮
    packagecom.itheima;importjavax.swing.*;publicclassJFrame03{publicstaticvoidmain(String[]args){JFramejf=newJFrame();jf.s......
  • JAVA___HashSet底层原理
    HashCode和equalsHashSet通过hashCode确定元素存储的位置,如果该位置没有元素就直接放入,有元素的话需要利用equals方法比较两个元素是否相同,如果不相同利用链表将两个元素......
  • JAVA-初始窗体
    创建一个最基本的窗体packagecom.itheima;importjavax.swing.*;publicclassJFrame01{publicstaticvoidmain(String[]args){//JFrame()构......
  • 题目集4、5以及期中考试的总结性Blog
    前言:这两次的pta题目也是多边形系列的,题目要求复杂,测试点多,难度高,虽然题目数量少了,但所需时间更多。知识点涉及的其实主要还是类的运用,只是为实现功能所需的各种算法难度较......
  • JAVA-GUI
    ......
  • PTA题目集阶段总结2及期中考试
    PTA题目集阶段总结2及期中考试 前沿概要 经过前一次的点线系列三角形熏陶后,第四次和第五次大作业就进入了四边形和五边形的相关计算。总体来说代码难度提升,期中考试的......
  • Java-汉诺塔问题
    //汉诺塔问题publicclassHannoi{ publicstaticvoidmain(String[]args){ Towertower=newTower(); tower.move(5,'A','B','C'); }}classTower{ //n......