zoukankan      html  css  js  c++  java
  • 2019.9.30极限测试 04.JAVA语言课堂测试试卷-极限测试

    题目存储在上传的文件当中。

    • 代码实现

    Subway 类:

     1 package ClassroomTest;
     2 
     3 public class Subway {
     4     
     5     private String railway;
     6     private String station[];
     7     private String information;
     8     
     9     public String getRailway() {
    10         return railway;
    11     }
    12 
    13     public void setRailway(String railway) {
    14         this.railway = railway;
    15     }
    16 
    17     public String[] getStation() {
    18         return station;
    19     }
    20 
    21 
    22 
    23     public Subway() {
    24         super();
    25         this.railway = railway;
    26         this.station = station;
    27         this.information = information;
    28     }
    29 
    30     public void setStation(String[] station) {
    31         this.station = station;
    32     }
    33 
    34     public String getInformation() {
    35         return information;
    36     }
    37 
    38     public void setInformation(String information) {
    39         this.information = information;
    40     }
    41     
    42 
    43 }

    SubwayManger 类

      1 package ClassroomTest;
      2 /*
      3  * 信1805-2 
      4  * 20183547
      5  * 崔星宇
      6  */
      7 import java.io.File;
      8 import java.io.FileInputStream;
      9 import java.io.FileNotFoundException;
     10 import java.io.IOException;
     11 import java.io.InputStream;
     12 import java.util.Scanner;
     13 
     14 public class SubwayManager {
     15    static Scanner sc=new Scanner(System.in);
     16     
     17     public static void main(String[] args) throws IOException {
     18         Subway first=new Subway();
     19         Subway third=new Subway();
     20         String []b1=new String[30];
     21         String []b2=new String[10];
     22         File file=new File("D://百度网盘//shijiazhuang-subway.txt");
     23          InputStream in=new FileInputStream(file); //实例化FileInputStream
     24          byte b[]=new byte[1024];
     25          int len=in.read(b);
     26          in.read(b);
     27          in.close();  //关闭输入流
     28          String d=new String(b,0,len);
     29          String[] words = d.split(" ");
     30          first.setRailway(words[0]);
     31          first.setInformation(words[21]);
     32          int j=0;
     33          for(int i=1;i<21;i++) {
     34              b1[j++]=words[i];
     35          }
     36          third.setRailway(words[22]);
     37          third.setInformation(words[29]);
     38          j=0;
     39          for(int i=23;i<29;i++) {
     40              b2[j++]=words[i];
     41          }
     42          third.setStation(b2);
     43          System.out.println("***************************************************************");
     44         System.out.println("            欢迎乘坐石家庄地铁            ");
     45         System.out.println("****************************************************************");
     46         System.out.println("        1、    显示具体线路信息;        ");
     47         System.out.println("        2、    购票        ");
     48         System.out.println("****************************************************************");
     49         int a;
     50         sc=new Scanner(System.in);
     51         a=sc.nextInt();
     52         // 线路图
     53         if(a==1) {
     54             System.out.println("请选择需要查找的线路:");
     55             System.out.println("0 :全部 ");
     56             System.out.println("1:一号线 ");
     57             System.out.println("2:三号线 ");
     58             sc=new Scanner(System.in);
     59             int b11=sc.nextInt();
     60                 System.out.println("***************************************************************");
     61                 System.out.println("            石家庄地铁线路图        ");
     62                 System.out.println("***************************************************************");
     63                 int i=0;
     64                  j=0;
     65                 if(b11==1)
     66                 {  i=0;
     67                     System.out.print("1号线:");
     68                     while(b1[i]!=null) {
     69                         System.out.print(b1[i]+" ");
     70                         i++;
     71                     }
     72                 System.out.println();
     73                 } 
     74                 /*else*/ if(b11==2) {
     75                 System.out.print("3号线:");
     76                     j=0;
     77                     while(b2[j]!=null) {
     78                         System.out.print(b2[j]+" ");
     79                         j++;
     80                     }
     81                     System.out.println();
     82                     } 
     83                 if(b11!=1&&b11!=2){
     84                      System.out.println("1号线:");
     85                      i=0;
     86                         while(b1[i]!=null) {
     87                             System.out.print(b1[i]+" ");
     88                             i++;
     89                         }
     90                         System.out.println();
     91                      System.out.println("3号线:");
     92                      j=0;
     93                      while(b2[j]!=null) {
     94                             System.out.print(b2[j]+" ");
     95                             j++;
     96                         }
     97                      System.out.println();
     98                 }
     99                 System.out.println("***************************************************************");
    100         }
    101         //购票
    102         else {
    103             System.out.println("****************************************************************");
    104                System.out.println("            欢迎乘坐石家庄地铁            ");
    105                System.out.println("****************************************************************");
    106                System.out.println("        起始站:");
    107                System.out.println("        终点站:");
    108                System.out.println("        购票数量:");
    109                System.out.println("****************************************************************");
    110                sc=new Scanner(System.in);
    111                String a1=null;
    112                String a2=null;
    113                int number=0;
    114                a1=sc.next();
    115                a2=sc.next();
    116                number=sc.nextInt();
    117                int address1=0,address2=0;
    118                int address3=0,address4=0;
    119                int number1=0,number2=0;
    120                int number3=0,number4=0;
    121                int price=0;
    122                int mail=0;
    123                int i = 0;
    124                int k1=0;
    125                int k2=0;
    126                while(b1[i]!=null) {
    127                    if(b1[i].compareTo(a1)==0) {
    128                        address1=i;
    129                        k1++;
    130                    }
    131                if(b1[i].compareTo(a2)==0) {
    132                    address2=i;
    133                    k1++;
    134                }
    135                i++;
    136              }
    137                i=0;
    138              while(b2[i]!=null) {
    139                  if(b2[i].compareTo(a1)==0) {
    140                      address3=i;
    141                  }
    142                  if(b2[i].compareTo(a2)==0) {
    143                      address4=i;
    144                  }
    145                  i++;
    146              }
    147              //全在一号线
    148              if(k1==2) {
    149                  k2=Math.abs(address2-address1);
    150                  if(k2<=3) {
    151                      price=1;
    152                  }
    153                  else {
    154                      int k=0;
    155                      if(k2%3==0) {
    156                          k=0;
    157                      }else {
    158                          k=1;
    159                      }
    160                      price=k2/3+k;
    161                  }
    162               if(address1>address2) 
    163               {
    164                   int temp=address1;
    165                   address1=address2;
    166                   address2=temp;
    167               }
    168               System.out.println("***************************************************************");
    169               System.out.println("            欢迎乘坐石家庄地铁            ");
    170               System.out.println("****************************************************************");
    171               System.out.println(k2+"站");  
    172               for(int i1=address1;i1<=address2;i1++) {
    173                   System.out.println(b1[i1]);
    174               }
    175             System.out.println("购票单价:"+price+"元");
    176             System.out.println("购票金额:"+price*number+"元"); 
    177              }
    178              String station="新百广场";
    179              //全在三号线 或者 一个在新百广场 一个在三号线  k1=1 一个站点在三号线上 另一个在新百广场或者一号线其他位置
    180              if(k1==0||(k1==1&&(a1.compareTo(station)==0||a2.compareTo(station)==0))) {
    181                 k2=Math.abs(address3-address4); 
    182                 if(k2<=3) {
    183                     price=1;
    184                 }else {
    185                      int k=0;
    186                      if(k2%3==0) {
    187                          k=0;
    188                      }else {
    189                          k=1;
    190                      }
    191                      price=k2/3+k;
    192                 }
    193                   if(address3>address4) 
    194                   {
    195                       int temp=address3;
    196                       address3=address2;
    197                       address4=temp;
    198                   }
    199                 System.out.println("***************************************************************");
    200                 System.out.println("            欢迎乘坐石家庄地铁            ");
    201                 System.out.println("****************************************************************");
    202                 System.out.println(k2+"站"); 
    203                   for(int i1=address3;i1<=address4;i1++) {
    204                       System.out.println(b2[i1]);
    205                   }
    206                 System.out.println("购票单价:"+price+"元");
    207                 System.out.println("购票金额:"+price*number+"元");
    208              }
    209              //换乘 一个在三号线且另一个不在新百广场
    210               if(k1==1&&a1.compareTo(station)!=0&&a2.compareTo(station)!=0) {
    211                   if(address2!=0) {
    212                       address1=address2;
    213                   }
    214                   if(address4!=0) {
    215                       address3=address4;
    216                   }
    217                   int k21=0;
    218                   int k22=0;
    219                k21=Math.abs(address1-14);
    220                k22=Math.abs(address3-1);
    221                k2=k21+k22;
    222                if(k2<=3) {
    223                    price=1;
    224                }else {
    225                    int k=0;
    226                    if(k2%3==0) {
    227                        k=0;
    228                    }else {
    229                        k=1;
    230                    }
    231                    price=k2/3+k;
    232                }
    233                System.out.println("***************************************************************");
    234                System.out.println("            欢迎乘坐石家庄地铁            ");
    235                System.out.println("****************************************************************");
    236                System.out.println(k2+"站"); 
    237               if(address1<14) {
    238                    for(int i1=address1;i1<15;i1++)
    239                        System.out.println(b1[i1]);
    240                }else {
    241                    for(int i1=address1;i1>13;i1--) {
    242                        System.out.println(b1[i1]);
    243                    }
    244                }
    245               System.out.println("(换乘站)");
    246               if(address3<1) {
    247                    for(int i1=address3;i1<1;i1++) {
    248                        System.out.println(b2[i1]);
    249                    }
    250                }else {
    251                    for(int i1=address3;i1>1;i1--) {
    252                        System.out.println(b2[i1]);
    253                    }
    254                }
    255                System.out.println("购票单价:"+price+"元");
    256                System.out.println("购票金额:"+price*number+"元");
    257               }
    258             }
    259     }
    260 }

    测试结果当只在一号线或者旨在三号线的时候没有问题,对于换线的情况,从左到右没有任何问题,如果顺序不按照从左到右,输出结果会出现混乱(顺序不正确),除此之外,在录入信息的时候会出现错误,没有解决。

    • 设计思路

    该系统主要分为查询线路与订购车票两个功能,两个功能不会同时运行,即可同时分为两组情况,每种情况分别输出,对于线路查询没有问题,对于订购车票(并输出线路与价格,还有站点的计算问题),首先把简单的一条线路的情况写出来,除此之外,我认为

    对于其中的特殊点换乘站点要去去除特殊化,将其平凡化处理,对于换乘路线要避免换乘点的重复相加。站点的计算不计算起始站点,记录下车站点。

  • 相关阅读:
    C++小结
    进程
    JavaScript中如何获取当前点击对象信息!
    form表单中enctype="multipart/form-data"的传值问题
    WebMagic框架总结
    工具类:自己总结的利用fileupload包上传文件的工具类!
    工具类:关于如何找到两个List数组中不同的数据的算法!
    工具类:关于解决数据库中的日期格式,经过response.getWriter().write(json)打到前台日期格式混乱的问题的总结
    工具类:将其他编码类型转换成UTF-8或者其他类型的工具类
    博主收藏的前端框架,极力推荐!
  • 原文地址:https://www.cnblogs.com/cxy0210/p/11636730.html
Copyright © 2011-2022 走看看