⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jp1.java

📁 java开发的公交查询系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				System.out.println("排序了的W[]:");
				System.out.println("路线1\t路线2\t中转站\t经过站点数");
				for(i=0;i<length_W;i++)
				{
					System.out.println(W[i][0]+'\t'+W[i][1]+'\t'+W[i][2]+'\t'+W[i][3]);
				}
				System.out.println("只需转一趟车的最佳线路:");
				i=1;
				j=0;
				while (i<length_W)
				{
					if(Integer.parseInt(W[i-1][3])<Integer.parseInt(W[i][3]))
					{
						j=i-1;
						break;
					}
					i++;
				}
				int length;
				query="select line_name from lines where line_id ='"+W[0][0]+"'";
				length=execute(query);
				if(length!=0)
				{
					jta.setText("");
					jta.append("需转一趟车的最佳线路:\n");
				}
				for(i=0;i<=j;i++)
				{
					query="select line_name from lines where line_id ='"+W[i][0]+"'";
					length=execute(query);
					if(length!=0)
					{
						System.out.print("从起点站"+jt1.getText()+"乘坐"+array[0]+"到");						
						jta.append("从起点站"+jt1.getText()+"乘坐"+array[0]+"到");
						query="select stop_name from stops where stop_id ='"+W[i][2]+"'";
						length=execute(query);
						System.out.print(array[0]+"站转乘");
						jta.append(array[0]+"站转乘");
						query="select line_name from lines where line_id ='"+W[i][1]+"'";
						length=execute(query);
						System.out.print(array[0]+"到终点站"+jt2.getText());
						jta.append(array[0]+"到终点站"+jt2.getText());;
						System.out.print(".经过的站点数目为"+W[i][3]+"站.");
						jta.append(".经过的站点数目为"+W[i][3]+"站.");
						return;
					}
				}
				System.out.println();
				System.out.println("-----------------------");
				
				
				
				//----------------------R[][][]:经过站点O[][]的公交线路
				System.out.println("R[][][]:经过站点O[][]的公交线路");
				for(i=0;i<length_X;i++)
				{
					for(j=0;j<lengthofrow_O[i];j++)
					{
						query="select line_id from linesstops where stop_id ='"+O[i][j]+"'";
						lengthofrow_R[i][j]=execute(query);
						for(k=0;k<lengthofrow_R[i][j];k++)
						{
							R[i][j][k]=array[k];
						}
					}
				}
				for(i=0;i<length_X;i++)
				{
					for(j=0;j<lengthofrow_O[i];j++)
					{
						for(k=0;k<lengthofrow_R[i][j];k++)
						{
							System.out.print(R[i][j][k]+" ");
						}
						System.out.println();
					}
					System.out.println();
				}
				//------------------G[][][][]:公交路线R[][][]所包含的站点
  				System.out.println("G[][][][]:公交路线R[][][]所包含的站点");
				for(i=0;i<length_X;i++)
				{
					for(j=0;j<lengthofrow_O[i];j++)
					{
						for(k=0;k<lengthofrow_R[i][j];k++)
						{
							query="select stop_id from linesstops where line_id ='"+R[i][j][k]+"'";
							lengthofrow_G[i][j][k]=execute(query);
							for(a=0;a<lengthofrow_G[i][j][k];a++)
							{
								G[i][j][k][a]=array[a];
							}
						}
					}
				}
				for(i=0;i<length_X;i++)
				{
					for(j=0;j<lengthofrow_O[i];j++)
					{
						for(k=0;k<lengthofrow_R[i][j];k++)
						{
							for(a=0;a<lengthofrow_G[i][j][k];a++)
							{
								System.out.print(G[i][j][k][a]+" ");
							}
							System.out.println();
						}
						System.out.println();
					}
					System.out.println();
				}
				//--------------S[][]:G[][]=P[][]
				System.out.println("S[][]:G[][]=P[][]");
				for(i=0;i<length_X;i++)
				{
					for(j=0;j<lengthofrow_O[i];j++)
					{
						for(k=0;k<lengthofrow_R[i][j];k++)
						{
							for(l=0;l<lengthofrow_G[i][j][k];l++)
							{
								for(m=0;m<length_Y;m++)
								{
									for(n=0;n<lengthofrow_P[m];n++)
									{
										if(G[i][j][k][l].equals(P[m][n]))
										{
											for(a=0;a<length_S;a++)
											{
												if(S[a][0].equals(X[i])&&S[a][1].equals(R[i][j])&&S[a][2].equals(Y[m])&&S[a][3].equals(O[i][j])&&S[a][4].equals(P[m][n]))//不允许S中有重复记录
												{
													break;
												}
											}
											//没有重复,且两路路线不相同,中转站不是起点,也不是终点
											if(a==length_S && (!X[i].equals(R[i][j][k]))&& (!X[i].equals(Y[m]))&& (!R[i][j][k].equals(Y[m])) && (!(O[i][j]).equals(stop1)) && (!(O[i][j]).equals(stop2))&& (!(P[m][n]).equals(stop1)) && (!(P[m][n]).equals(stop2))&& (!(P[m][n]).equals(O[i][j])))
											{
												S[length_S][0]=X[i];
												S[length_S][1]=R[i][j][k];
												S[length_S][2]=Y[m];
												S[length_S][3]=O[i][j];
												S[length_S][4]=P[m][n];
												length_S++;
												break;
											}
										}
									}
								}
							}
						}
					}
				}
				System.out.println("Line1\tLine2\tLine3\tStop1\tStop2");
				for(i=0;i<length_S;i++)
				{
					System.out.println(S[i][0]+'\t'+S[i][1]+'\t'+S[i][2]+'\t'+S[i][3]+'\t'+S[i][4]);
				}
				//--------------S[][]:G[][]=P[][]
				System.out.println("已排序S[][]:G[][]=P[][]");
				for(i=0;i<length_S;i++)
				{
					int seqa,seqo1,seqo2,seqp1,seqp2,seqb,tempint,seqao,seqop,seqpb,seq;
					String seqas,seqos1,seqos2,seqps1,seqps2,seqbs,seqs;
					query="select seq from linesstops where line_id='"+S[i][0]+"' and stop_id='"+stop1+"'";
					tempint=execute(query);
					seqas=array[0];
					query="select seq from linesstops where line_id='"+S[i][2]+"' and stop_id='"+stop2+"'";
					tempint=execute(query);
					seqbs=array[0];
					query="select seq from linesstops where line_id='"+S[i][0]+"' and stop_id='"+S[i][3]+"'";
					tempint=execute(query);
					seqos1=array[0];
					query="select seq from linesstops where line_id='"+S[i][1]+"' and stop_id='"+S[i][3]+"'";
					tempint=execute(query);
					seqos2=array[0];
					query="select seq from linesstops where line_id='"+S[i][1]+"' and stop_id='"+S[i][4]+"'";
					tempint=execute(query);
					seqps1=array[0];
					query="select seq from linesstops where line_id='"+S[i][2]+"' and stop_id='"+S[i][4]+"'";
					tempint=execute(query);
					seqps2=array[0];
					seqa=Integer.parseInt(seqas);
					seqb=Integer.parseInt(seqbs);
					seqo1=Integer.parseInt(seqos1);
					seqo2=Integer.parseInt(seqos2);
					seqp1=Integer.parseInt(seqps1);
					seqp2=Integer.parseInt(seqps2);
					if(seqa>seqo1)
					{
						seqao=seqa-seqo1;
					}
					else
					{
						seqao=seqo1-seqa;
					}
					if(seqo2>seqp1)
					{
						seqop=seqo2-seqp1;
					}
					else
					{
						seqop=seqp1-seqo2;
					}
					if(seqp2>seqb)
					{
						seqpb=seqp2-seqb;
					}
					else
					{
						seqpb=seqb-seqp2;
					}
					seq=seqao+seqop+seqpb;
					seqs=Integer.toString(seq);
					S[i][5]=seqs;
				}
				//-----------排序
				String temparr1[][]=new String[1][6];
				for(int pass=1;pass<length_S;pass++)
				{
					for(i=0;i<length_S-pass;i++)
					{
						temp1=Integer.parseInt(S[i][5]);
						temp2=Integer.parseInt(S[i+1][5]);
						if(temp1>temp2)
						{
							for(j=0;j<6;j++)
							{
								temparr1[0][j]=S[i][j];
							}
							for(j=0;j<6;j++)
							{
								S[i][j]=S[i+1][j];
							}
							for(j=0;j<6;j++)
							{
								S[i+1][j]=temparr1[0][j];
							}
						}
					}
				}
				//-------------------
				System.out.println("Line1\tLine2\tLine3\tStop1\tStop2\tStopNum");
				for(i=0;i<length_S;i++)
				{
					System.out.println(S[i][0]+'\t'+S[i][1]+'\t'+S[i][2]+'\t'+S[i][3]+'\t'+S[i][4]+'\t'+S[i][5]);
				}
				System.out.println("需转两趟车的最佳线路:");
				i=1;
				j=0;
				while (i<length_S)
				{
					if(Integer.parseInt(S[i-1][5])<Integer.parseInt(S[i][5]))
					{
						j=i-1;
						break;
					}
					i++;
				}
				query="select line_name from lines where line_id ='"+S[0][0]+"'";
				length=execute(query);
				if(length!=0)
				{
					jta.setText("");
					jta.append("需转两趟车的最佳线路:\n");
				}
				for(i=0;i<=j;i++)
				{
					query="select line_name from lines where line_id ='"+S[i][0]+"'";
					length=execute(query);
					if(length!=0)
					{
						System.out.print("从起点站"+jt1.getText()+"乘坐"+array[0]+"到");
						jta.append("从起点站"+jt1.getText()+"乘坐"+array[0]+"到");
						query="select stop_name from stops where stop_id ='"+S[i][3]+"'";
						length=execute(query);
						System.out.print(array[0]+"站转乘");
						jta.append(array[0]+"站转乘");
						query="select line_name from lines where line_id ='"+S[i][1]+"'";
						length=execute(query);
						System.out.print(array[0]+",到");
						jta.append(array[0]+",到");
						query="select stop_name from stops where stop_id ='"+S[i][4]+"'";
						length=execute(query);
						System.out.print(array[0]+"站转乘");
						jta.append(array[0]+",到");
						query="select line_name from lines where line_id ='"+S[i][2]+"'";
						length=execute(query);
						System.out.print(array[0]+"到终点站"+jt2.getText());
						jta.append(array[0]+"到终点站"+jt2.getText());
						System.out.print(".经过的站点数目为"+S[i][5]+"站.");
						jta.append(".经过的站点数目为"+S[i][5]+"站.");
					}
					
				}
				System.out.println();
				System.out.println("-----------------------");
				if(length_W==0&length_Z==0&length_R==0)
				{
					System.out.println();
				jta.append("找不到合适的路线");
				}
			}
			
		}
	}
	public int execute(String query)
	{
		String dbDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
        String url = "jdbc:odbc:liu";
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        
        int i=0;
        try
        {
            Class.forName(dbDriver);
            conn = DriverManager.getConnection(url);
            stmt=conn.createStatement();
            rs=stmt.executeQuery(query);
            while (rs.next())
            {
            	String temp=rs.getString(1);
            	array[i]=temp;
            	i++;
            }
			rs.close();
			stmt.close();
			conn.close();
			
        } 
        catch (Exception ee)
        {
        	System.out.println("33 "+ee);
        }
        return i;
	}
	void bubble(int a[],String b[],int size)
	{
		int i,temp;
		String temps;
		for(int pass=1;pass<size;pass++)
		{
			for(i=0;i<size-pass;i++)
			if(a[i]>a[i+1])
			{
				temp=a[i];
				a[i]=a[i+1];
				a[i+1]=temp;
				temps=b[i];
				b[i]=b[i+1];
				b[i+1]=temps;
			}
		}
	}
//	public String data()
//	{
//		return "sdfd ffff"+"\n"+"\n"+"\n"+"\n"+"\n"+"\n"+"\n"+"南昌航空";
//	}	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -