地铁合作的第一周

一、题目要求

1.数据库设计:将石家庄地铁线路图的各个线路,各个站点,换乘信息等用数据库的形式保存起来,应该保存的信息有 {线路号,线路的各个站名,车站的换乘信息}。

2.站点查询:用户可以输入任一一条线路或输入出发地和目的地信息,可以查询到相关内容。

二、团队成员

盖楠 刘雨馨

 

三、编程过程

这周我们主要是在思考怎么建立石家庄地铁网站的后台,如何去计算最短路线,本来我们思考了一个方法:

 两个站之间路线的查询:
 1. 输入两个站名,分别为起始站(startStation)和终点站(endStation)
 2. 遍历出起始站和终点站所属的线路(若属换乘站、可能存在两条)(startLine[2]和endLine[2],若没有第二条则为0)
 3. StatisticLine(),保存为line
 4. MultipleTransfer(),若传出非空,则覆盖line
输出line

MultipleTransfer(String startStation,String endStation,int currentCount)输入:起点、终点、计数剩余(startStation,endStation,currentCount)
输出:line[100]
1. 遍历起始站所属表中,距离起始点站距离小于currentCount的换乘站点(String tStationName[15])
2. 开始循环:
3. 变量currentCount记录 count-起始站点与当前换乘站点的距离,保存线路至currentLine[100]
4. 更新起始点为第一个换乘站点,StatisticLine(startStation,endStation),比较currentCount和返回数组的长度
5. 若currentCount>length,将返回的数组增加到currentLine中,并将其复制给line[100],并进行下一个循环。若没有,直接进行下一个循环

StatisticLine(String startStation,String endStation)输入:起点、终点
输出:line[100]
1. 判断起始点和终点是否在同一条线路中,若不在,则遍历换乘表,查询出同时包含起始站线和终点站线的换乘点(String transferStationName[5])(可能存在多个)
2. 通过顺序号,计算换乘站点距离始末站点的距离,并保存这条线路(String line[100]),用一个全局变量count记录这条线路途经的站数

但是后来发现我们思路有些困顿,关键对于递归我们也不是很熟练,然后目前为止我们只写出了这些代码,还写了一点网站,

但是后来又发现地图有问题,我们的数据库又建立失败了一次,这是目前的代码

package com.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import com.bean.StationBean;
import com.db.DB;


public class Dao 
{
    private int count;
    
    public String[] StatisticLine(String startStationName,String endStationName) 
    {
        StationBean[] startStation = Query(startStationName);
        StationBean[] endStation = Query(endStationName);
        if(startStation[0].getLine() == endStation[0].getLine()) {
            
        }
    }
    
    //query the message of stationName
    public StationBean[] Query(String stationName) 
    {
        String[] tablename = new String[] {"one","two","three","four","five","six"};
        DB db=new DB();
        Connection con = db.getCon();
        StationBean[] stationBean = null;
        
        //there are six tables in total to used remenber station message
        for(int j=0,i=0;i<6;i++)
        {
            try
            {
                Statement stm = con.createStatement();
                ResultSet rs = stm.executeQuery("select * from "+tablename[i]+" where 站名='" + stationName + "'");
                if(rs.next())
                {
                    System.out.println("select the stationBean from mysql");
                    stationBean[j++] = new StationBean(rs.getString("站名"),i,rs.getInt("是否换乘站"),rs.getInt("换乘线"),rs.getInt("顺序号"));
                    System.out.println("name of the bean is "+rs.getString("name"));
                }
                db.close(rs,stm, con);
            }catch(Exception e)
            {
                e.printStackTrace();
            }
        }
        System.out.println("query true");
        return stationBean;
    }
    
    public String[] QueryRangeOfSameLine(String startStationName,String endStationName,int line)
    {
        String[] way = null;
        DB db=new DB();
        Connection con = db.getCon();
        String tablename = null;
        
        int startNum = 0;
        int endNum = 0;
        
        switch(line)
        {
            case 1:tablename = "one";break;
            case 2:tablename = "two";break;
            case 3:tablename = "three";break;
            case 4:tablename = "four";break;
            case 5:tablename = "five";break;
            case 6:tablename = "six";break;
        }
        try
        {
            Statement stm = con.createStatement();
            ResultSet rs1 = stm.executeQuery("select 顺序号 from "+tablename+" where 站名='" + startStationName + "'");
            if(rs1.next())
            {
                startNum = rs1.getInt("顺序号");
                System.out.println("number of the start is "+rs1.getString("站名"));
            }
            db.close(rs1,stm, con);
            ResultSet rs2 = stm.executeQuery("select 顺序号 from "+tablename+" where 站名='" + endStationName + "'");
            if(rs2.next())
            {
                endNum = rs2.getInt("顺序号");
                System.out.println("number of the end is "+rs2.getString("站名"));
            }
            db.close(rs2,stm, con);
        }catch(Exception e)
        {
            e.printStackTrace();
        }
        count = endNum - startNum + 1 ;
        
        
    }
}

 这是我们的数据库思路

数据库:
六个表,代表六条线路
一个表,记录换乘站点
每个线路表中记录了站名、是否换乘站、换乘线路、顺序号
换乘表中记录了站名、换乘线1、换乘线2
这是我们针对数据库ps做的图片
这就是我们这周的成果
 
 
原文地址:https://www.cnblogs.com/love-nan/p/10688900.html