秦皇岛公交信息查询系统单机测试平台.docx
- 文档编号:8206954
- 上传时间:2023-01-29
- 格式:DOCX
- 页数:35
- 大小:21.53KB
秦皇岛公交信息查询系统单机测试平台.docx
《秦皇岛公交信息查询系统单机测试平台.docx》由会员分享,可在线阅读,更多相关《秦皇岛公交信息查询系统单机测试平台.docx(35页珍藏版)》请在冰豆网上搜索。
秦皇岛公交信息查询系统单机测试平台
//BusSystem.java
//秦皇岛公交信息查询系统单机测试平台
//用于以窗口形式输入查询站点,输出乘车方案
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
importjavax.swing.border.TitledBorder;
publicclassBusSystemextendsJFrameimplementsActionListener
{
privateJTextFieldjtfBeginSta=newJTextField(10);
privateJTextFieldjtfEndSta=newJTextField(10);
privateJTextAreajtaResult;
privateJButtonjbtQuery=newJButton("查询");
publicBusSystem()
{
//jtfBeginSta.setHorizontalAlignment(JTextField.RIGHT);
//jtfEndSta.setHorizontalAlignment(JTextField.RIGHT);
JScrollPanescrollPane=newJScrollPane(jtaResult=newJTextArea());
jtaResult.setEditable(false);
JPanelp1=newJPanel();
p1.setLayout(newGridLayout(2,3));
p1.add(newLabel("起点车站"));
p1.add(jtfBeginSta);
p1.add(newLabel("终点车站"));
p1.add(jtfEndSta);
JPanelp3=newJPanel();
p3.setLayout(newBorderLayout(2,1));
p3.add(newLabel("查询结果"),BorderLayout.NORTH);
p3.add(scrollPane,BorderLayout.CENTER);
p1.setBorder(newTitledBorder(""));
JPanelp2=newJPanel();
p2.setLayout(newFlowLayout(FlowLayout.RIGHT));
p2.add(jbtQuery);
getContentPane().add(p1,BorderLayout.NORTH);
getContentPane().add(p2,BorderLayout.SOUTH);
getContentPane().add(p3,BorderLayout.CENTER);
jbtQuery.addActionListener(this);
}
publicstaticvoidmain(String[]args)
{
BusSystemframe=newBusSystem();
frame.setTitle("秦皇岛公交信息查询系统");
frame.setSize(300,500);
frame.setVisible(true);
}
publicvoidactionPerformed(ActionEvente)
{
if(e.getSource()==jbtQuery)
{
StringbeginSta=jtfBeginSta.getText();
StringendSta=jtfEndSta.getText();
StringresultQuery;
booleanisFinded;
Finding_waymyFind=newFinding_way();
myFind.createFindWay(beginSta,endSta);
isFinded=myFind.find_bestway();
if(isFinded)
{
resultQuery=myFind.output();
//System.out.println(myFind.output());
}
else
{
resultQuery="对不起,未找到可行方案!
\n";
}
jtaResult.setText(resultQuery);
}
}
}
//Finding_way.java
//该类用来计算乘车方案。
import.URL;
importjava.sql.*;
publicclassFinding_way
{
privateBeg_end_stainputstation;//起始站点
privatePath[]bestpath;//20个乘车方案
privatebooleanisfinding;//是否找到可行的乘车方案
privateintpathTotal;
privateinterrState=0;//1表示没有直达方案2表示起点站与终点站为同一站点
//3表示间接查询中,起点站不存在5该车次无车站
//6倒一次车的中间站点不存在
publicFinding_way()
{
}
publicFinding_way(Beg_end_stainputstation,Path[]bestpath,booleanisfinding)
{
this.inputstation=inputstation;
this.bestpath=bestpath;
this.isfinding=isfinding;
}
publicFinding_way(Beg_end_stainputstation)
{
this.inputstation=inputstation;
}
publicvoidcreateFindWay(Beg_end_stainputstation)
{
this.inputstation=newBeg_end_sta();
this.inputstation=inputstation;
this.bestpath=newPath[20];
}
publicvoidcreateFindWay(Stationbegining,Stationending)
{
inputstation=newBeg_end_sta();
inputstation.set_be_sta(begining,ending);
bestpath=newPath[20];
for(inti=0;i<20;i++)
{
bestpath[i]=newPath();
}
}
publicvoidcreateFindWay(Stringbegining,Stringending)
{
inputstation=newBeg_end_sta();
inputstation.set_be_sta(newStation(begining),newStation(ending));
bestpath=newPath[20];
for(inti=0;i<20;i++)
{
bestpath[i]=newPath();
}
}
publicvoidsetinputstation(Beg_end_stainputstation)
{
this.inputstation=inputstation;
}
publicBeg_end_stagetinputstation()
{
returninputstation;
}
publicvoidsetbestpath(Path[]bestpath)
{
this.bestpath=bestpath;
}
publicPath[]getbestpath()
{
returnbestpath;
}
publicvoidsetisfinding(booleanisfinding)
{
this.isfinding=isfinding;
}
//给出不倒车直接到达的方案
publicbooleandirect_find()
{
inti=0;
intresBegSeq,resEndSeq;
intresBegSeqShadow,resEndSeqShadow;
intdistance;//起点站到终点站所经过的车站数
String[]resBusNo=newString[20];
Stringbegining,ending;
StringqueryBusNo,queryBegSeq,queryEndSeq,queryPassSta;
StringqueryPath;
//StringbusNo;
begining=inputstation.getBegName();
ending=inputstation.getEndName();
if(begining==ending)
{
//System.out.println("起点和终点是同一站点");
errState=2;//起点和终点是同一站点
returnfalse;
}
queryBusNo="SELECTbus_noFROMbus_tableWHEREstation_name='"+begining+"'ANDbus_noIn(SELECTbus_noFROMbus_tableWHEREstation_name='"+ending+"')";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connectioncon=DriverManager.getConnection("jdbc:
odbc:
bus");
Statementstmt;
stmt=con.createStatement();
ResultSetresultBusNo,resultBegSeq,resultEndSeq,resultPassSta;
resultBusNo=stmt.executeQuery(queryBusNo);
//System.out.println(resultBusNo);
//找到从起点直达终点的一系列公交车次
//System.out.println(resultBusNo);
/*if(resultBusNo)//找到合适的函数来检查是否有有效数据!
!
{
System.out.println("无可行方案");
errState=1;
returnfalse;
}
*/
if(!
resultBusNo.next())
{
errState=1;
//System.out.println(resBusNo[0]+"dd");
returnfalse;
}
else
{
resBusNo[i]=resultBusNo.getString
(1);
bestpath[i].addSegment(resBusNo[i]);
i++;
}
while(resultBusNo.next()&&i<20)
{
resBusNo[i]=resultBusNo.getString
(1);
bestpath[i].addSegment(resBusNo[i]);
//System.out.print("s"+resBusNo[i]+"f");
i++;
}
pathTotal=i;
resultBusNo.close();
//System.out.println("");
//System.out.println("");
//找到各公交车次中从起点车站到终点车站在整条公交线路中所经过的车站
//System.out.println("i="+i);
for(intj=0;j
{
//起点车站所处的次序
//System.out.print("起始车站的序号");
queryBegSeq="SELECTstation_sequenceFROMbus_tableWHEREstation_name='"+begining+"'ANDbus_no='"+resBusNo[j]+"'";
resultBegSeq=stmt.executeQuery(queryBegSeq);
resultBegSeq.next();
resBegSeq=resultBegSeq.getInt("station_sequence");
//System.out.println(resBegSeq);
resultBegSeq.close();
//终点车站所处的次序
//System.out.print("终点车站的序号");
queryEndSeq="SELECTstation_sequenceFROMbus_tableWHEREstation_name='"+ending+"'ANDbus_no='"+resBusNo[j]+"'";
resultEndSeq=stmt.executeQuery(queryEndSeq);
resultEndSeq.next();
resEndSeq=resultEndSeq.getInt("station_sequence");
//System.out.println(resEndSeq);
resultEndSeq.close();
//查找所经过的车站
queryPath="";
resBegSeqShadow=resBegSeq;
resEndSeqShadow=resEndSeq;
distance=resEndSeqShadow-resBegSeqShadow;
if(distance>0)
{
queryPath="";
}
else
{
queryPath="DESC";
}
//System.out.println(queryPath);
queryPath="SELECTstation_nameFROMbus_tableWHEREbus_no='"+resBusNo[j]+"'ANDstation_sequenceBETWEEN"+resBegSeq+"AND"+resEndSeq+"ORDERBYstation_sequence"+queryPath;
//System.out.println(queryPath);
resultPassSta=stmt.executeQuery(queryPath);
//ResultSetMetaDatarsmd=resultPassSta.getMetaData();
//intnumCols=rsmd.getColumnCount();
//System.out.print("乘车路线:
"+resBusNo[j]+"路车方案");
StringbusStation;
intq=0;
while(resultPassSta.next())
{
busStation=resultPassSta.getString
(1);
//System.out.print(busStation+"");
bestpath[j].setPassSegment(busStation,q,0);
//System.out.print("");
q++;
}
//resEndSeq=resultEndSeq.getInt("station_sequence");
//System.out.println(resEndSeq);
resultPassSta.close();
//System.out.println("");
//System.out.println("");
}
//System.out.println("");
//System.out.println("Createsuccessfully!
");
//resultBegSeq.close();
//resultEndSeq.close();
stmt.close();
con.close();
}
catch(SQLExceptionex)
{
System.out.println("\n***SQLExceptionCaught***\n");
while(ex!
=null)
{
System.out.println("SQLState:
"+ex.getSQLState());
System.out.println("Message:
"+ex.getMessage());
System.out.println("Vendor:
"+ex.getErrorCode());
ex=ex.getNextException();
System.out.println("");
}
}
catch(java.lang.Exceptionex)
{
ex.printStackTrace();
}
returntrue;
}
//给出倒一次车的,间接到达方案
publicbooleanindirect_find()
{
Stringbegining=inputstation.getBegName();
Stringending=inputstation.getEndName();
StringqueBegBusNo="SELECTbus_noFROMbus_tableWHEREstation_name='"+begining+"'";
StringqueEndBusNo="SELECTbus_noFROMbus_tableWHEREstation_name='"+ending+"'";
String[]begBusNo=newString[20];
String[]endBusNo=newString[20];
String[]midBusSta=newString[20];
inti=0,j=0;
//System.out.println(queBegBusNo);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connectioncon=DriverManager.getConnection("jdbc:
odbc:
bus");
Statementstmt;
stmt=con.createStatement();
ResultSetresultBegBusNo,resultEndBusNo;
//经过起始站点的线路名称
resultBegBusNo=stmt.executeQuery(queBegBusNo);
if(!
resultBegBusNo.next())
{
//System.out.println(resBusNo[0]+"dd");
//间接查询中,起点站不存在,为错误三
errState=3;
returnfalse;
}
else
{
begBusNo[i]=resultBegBusNo.getString
(1);
//System.out.print(begBusNo[i]+"");
i++;
}
while(resultBegBusNo.next()&&i<20)
{
begBusNo[i]=resultBegBusNo.getString
(1);
//System.out.print(begBusNo[i]+"");
i++;
}
resultBegBusNo.close();
//System.out.println("begingandend");
resultEndBusNo=stmt.executeQuery(queEndBusNo);
if(!
resultEndBusNo.next())
{
//间接查询中,终点站不存在,为错误三
errState=3;
returnfalse;
}
else
{
endBusNo[j]=resultEndBusNo.getString
(1);
//System.out.print(endBusNo[j]+"");
j++;
}
while(resultEndBusNo.next()&&i<20)
{
endBusNo[j]=resultEndBusNo.getString
(1);
//System.out.print(endBusNo[j]+"");
j++;
}
resultEndBusNo.close();
//System.out.println("busstation");
intq=0,l=0,k=0;
//ResultSetresultBegBusNo,resultEndBusNo;
String[]passBegSta=newString[40];
String[]passEndSta=newString[40];
StringquePassBegSta,quePassEndSta;
//System.out.println(i+"busstation"+j);
for(intn=0;n
for(intm=0;m { //查找起点站可以到
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 秦皇岛 公交 信息 查询 系统 单机 测试 平台