其他分享
首页 > 其他分享> > 地铁结队开发(一)

地铁结队开发(一)

作者:互联网

 

要求开发一个地铁查询系统,可以进行站点查询,并且显示所经历的最短路径和换乘线路

对于我来说,首先要实现的是非web端的java程序,因为web没学好(尴尬/)

先能让它两个站之间进行换乘:

回忆整理了一下之前的东西:

包的名字是:地铁线

Subway.java

  1 package 地铁线;
  2 import java.io.BufferedReader;
  3 import java.io.File;
  4 import java.io.FileReader;
  5 import java.util.Scanner;
  6 import 界面.xianshi1;
  7 public class Subway
  8 {
  9     Scanner scanner=new Scanner(System.in);
 10     private int hao,huancheng;
 11     private String zhan;
 12     public Subway()
 13     {
 14         this.hao=hao;
 15         this.huancheng=huancheng;
 16         this.zhan=zhan;
 17     }
 18     public void xianshi() 
 19     {
 20         File file=new File("d:\\shijiazhuang-subway.txt");
 21         BufferedReader reader=null;
 22         String temp=null;
 23         int line=0;
 24         int t=0;
 25         try{
 26                 reader=new BufferedReader(new FileReader(file));
 27                 
 28                 while((temp=reader.readLine())!=null)
 29                 {
 30                     char []ar=temp.toCharArray();   
 31                     line++;
 32                     System.out.println(line+" "+temp);
 33                 }
 34                 
 35         }
 36         catch(Exception e){
 37             e.printStackTrace();
 38         }
 39         finally{
 40             if(reader!=null){
 41                 try{
 42                     reader.close();
 43                 }
 44                 catch(Exception e){
 45                     e.printStackTrace();
 46                 }
 47             }
 48         }
 49     }
 50     public void goupiao(int x,int y,int z) 
 51     {
 52         File file=new File("d:\\shijiazhuang-subway.txt");
 53         BufferedReader reader=null;
 54         String temp=null;
 55         int line=1;
 56         xianshi1 xx=new xianshi1();
 57         String []ar=new String [30];
 58         int t=0,i,zhan = 0,qian;
 59         xx.fanhui();
 60         try{
 61                 reader=new BufferedReader(new FileReader(file));
 62                 while((temp=reader.readLine())!=null)
 63                 {
 64                     ar[t]=temp;
 65                     t++;
 66                 }
 67                 if(x<y)
 68                 {
 69                     if(y<=20||x>=21) 
 70                     {
 71                         zhan=y-x;
 72                         {
 73                             for(;line<30;line++)
 74                             if(line>=x&&line<=y)
 75                             {
 76                                 System.out.println(line+" "+ar[line-1]);
 77                             }
 78                         }
 79                     }
 80                     else if(y==21)
 81                     {
 82                         zhan=((x-15)>0?(x-15):(15-x))+1;
 83                         if(x<=15)
 84                         {
 85                             for(line=x;line<=15;line++)
 86                             {
 87                                 System.out.println(line+" "+ar[line-1]);
 88                             }
 89                         }
 90                         else if(x>15)
 91                         {
 92                             for(line=x;line>15;line--)
 93                             {
 94                                 System.out.println(line+" "+ar[line-1]);
 95                             }
 96                         }
 97                         line=22;System.out.println(line+" "+ar[line-1]);
 98                         line=21;System.out.println(line+" "+ar[line-1]);
 99                     }
100                     else if(x<=20&&y>21) 
101                     {
102                         zhan=((x-15)>0?(x-15):(15-x))+(y-22);
103                         if(x<=15)
104                         {
105                             for(line=x;line<=15;line++)
106                             {
107                                 System.out.println(line+" "+ar[line-1]);
108                             }
109                         }
110                         else if(x>15)
111                         {
112                             for(line=x;line>15;line--)
113                             {
114                                 System.out.println(line+" "+ar[line-1]);
115                             }
116                         }
117                         for(line=22;line<=y;line++)
118                         {
119                             System.out.println(line+" "+ar[line-1]);
120                         }
121                     }
122                 }
123                 System.out.println("共"+zhan+"站");
124                 System.out.println("购票单价:3元");
125                 System.out.print("购票金额:");
126                 if(zhan%3==0)System.out.println((zhan/3)*z*3+"元");
127                 else System.out.println((zhan/3+1)*z*3+"元");
128                 
129         }
130         catch(Exception e){
131             e.printStackTrace();
132         }
133         finally
134         {
135             if(reader!=null)
136             {
137                 try
138                 {
139                     reader.close();
140                 }
141                 catch(Exception e)
142                 {
143                     e.printStackTrace();
144                 }
145             }
146         }
147     }
148 };

FirstLineSubway.java

package 地铁线;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class FirstLineSubway extends Subway
{
    public void xianshi1() 
    {
        File file=new File("d:\\shijiazhuang-subway.txt");
        BufferedReader reader=null;
        String temp=null;
        int line=1;
        int t=0;
        try{
                reader=new BufferedReader(new FileReader(file));
                
                while((temp=reader.readLine())!=null)
                { 
                    if(line<=20)System.out.println(line+" "+temp);
                    line++;
                }
                
        }
        catch(Exception e){
            e.printStackTrace();
        }
        finally{
            if(reader!=null){
                try{
                    reader.close();
                }
                catch(Exception e){
                    e.printStackTrace();
                }
            }
        }
    }
}

ThirdLineSubway.java

package 地铁线;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class ThirdLineSubway extends Subway
{
    public void xianshi3() 
    {
        File file=new File("d:\\shijiazhuang-subway.txt");
        BufferedReader reader=null;
        String temp=null;
        int line=1;
        int t=0;
        try{
                reader=new BufferedReader(new FileReader(file));
                
                while((temp=reader.readLine())!=null)
                { 
                    if(line>=21)System.out.println(line+" "+temp);
                    line++;
                }
                
        }
        catch(Exception e){
            e.printStackTrace();
        }
        finally{
            if(reader!=null){
                try{
                    reader.close();
                }
                catch(Exception e){
                    e.printStackTrace();
                }
            }
        }
    }
}
View Code

 xianshi1.java

package 地铁线;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class ThirdLineSubway extends Subway
{
    public void xianshi3() 
    {
        File file=new File("d:\\shijiazhuang-subway.txt");
        BufferedReader reader=null;
        String temp=null;
        int line=1;
        int t=0;
        try{
                reader=new BufferedReader(new FileReader(file));
                
                while((temp=reader.readLine())!=null)
                { 
                    if(line>=21)System.out.println(line+" "+temp);
                    line++;
                }
                
        }
        catch(Exception e){
            e.printStackTrace();
        }
        finally{
            if(reader!=null){
                try{
                    reader.close();
                }
                catch(Exception e){
                    e.printStackTrace();
                }
            }
        }
    }
}
View Code

SubwayManage.java

package main;
import java.io.*;
import java.util.Scanner;

import 地铁线.Subway;
import 地铁线.FirstLineSubway;
import 地铁线.ThirdLineSubway;
import 界面.xianshi1;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
public class SubwayManage
{

    @SuppressWarnings("null")
    public static void main(String[] args)
    {
        Scanner scanner=new Scanner(System.in);
        界面.xianshi1 a=new xianshi1();
        地铁线.Subway S=new Subway();
        地铁线.FirstLineSubway S1=new FirstLineSubway();
        地铁线.ThirdLineSubway S3=new ThirdLineSubway();
        a.huanying();
        int s=scanner.nextInt();
        int qishi;
        int zhongdian;
        int shuliang;
        if(s==1)
        {
            System.out.println("选择1号线请输入1,选择3号线请输入3,都选请输入0");
            s=scanner.nextInt();
            if(s==1)
            {
                S1.xianshi1();    
            }
            if(s==3)
             {
                S3.xianshi3();
            }
              if(s==0)
                {
                    S.xianshi();
                }
            a.goupiao();
            System.out.println("请输入起始站的序号:");
            qishi=scanner.nextInt();
            System.out.println("请输入终点站的序号:");
            zhongdian=scanner.nextInt();
            System.out.println("请输入购票数量:");
            shuliang=scanner.nextInt();
            S.goupiao(qishi,zhongdian,shuliang);
        }
       
        else if(s==2)
        {
            a.goupiao();
            System.out.println("请输入起始站的序号:");
            qishi=scanner.nextInt();
            System.out.println("请输入终点站的序号:");
            zhongdian=scanner.nextInt();
            System.out.println("请输入购票数量:");
            shuliang=scanner.nextInt();
            S.goupiao(qishi,zhongdian,shuliang);
        }
    }
}
View Code

截图

 

 

标签:java,io,reader,new,地铁,开发,import,结队,line
来源: https://www.cnblogs.com/mitang0-0/p/11061289.html