詳細設計

項目名稱:體育場館預訂系統算法

小組名稱:Login團隊數組

項目負責人:程智超佈局

小組成員:彭春陽,田新年,伍驕陽性能

  1. 1.   引言

1.1編寫目的測試

本部分旨在闡明編寫詳細設計的目的,面向讀者對象。spa

本文檔主要描述各個模塊的細節設計,明確系統的結構與實現過程,分析各個模塊,描述模塊的功能、性能和結構等方面包括模塊接口、調用關係、處理過程和算法,以及各個模塊的測試方案。本文檔的主要讀者爲軟件設計人員、模塊開發人員、管理人員、測試人員。設計

1.2項目背景3d

1.2.1項目來源對象

本項目一開始由伍驕陽提出。blog

1.2.2項目實現

本項目由程智超,彭春陽,田新年,伍驕陽共4人共同實現。

1.3參考資料

[1]竇萬峯.軟件工程方法與實踐[M].北京:機械工業出版社,2009.

1.5版本信息

項目編號

修改日期

修改後版本

修改位置

修改內容概述

1

2018-5-20

1.0

全局

完成系統界面的編寫。

 

2

 

2018-6-19

 

2.0

 

全局

實現初步選擇一個時間段功能,完善文檔。

 

3

 

2018-6-25

 

3.0

 

算法完善

增添實現預約多個時間段功能,完成整個系統設計。

 

  1. 2.   整體設計

2.1需求概述

設置系統初始化:自動建立記錄文件和預訂表,且初始化爲記錄表中存入一維數組,數組初始值設爲0。

信息比對:用戶輸入預訂項目和時間段,系統進入記錄表中進行比對,若是某時段該場地已滿,需返回衝突時段幫組用戶從新進行預訂,預訂成功則返回成功信息。

信息存檔:比對成功後,若是能夠預訂,則系統自動將用戶預訂信息寫入預訂表中,方便體育場所管理員瞭解場館預訂信息。

2.2軟件結構

 

 

 

  1. 3.   程序描述

3.1模塊基本信息

3.1.1系統初始化

主要包括:記錄文件和信息表的生成,爲記錄文件自動填入表明場地的一維數組,爲信息表填入表頭。以下所示:

 

 

 

3.1.2系統界面

主要包括:運動場所地圖與界面設置。

3.1.3讀取用戶信息

主要包括:設置時間監聽器,讀取輸入。

3.1.4判斷輸入格式

主要包括:判斷用戶輸入是否符合規範。

3.1.5信息比對

主要包括:判斷所選場地項目的有無,所選時段是否有空位。

3.1.6錯誤彈窗顯示

主要包括:接收到錯誤信息,彈窗顯示錯誤信息。

3.17信息存檔

    主要包括:接收正確信息,進行預訂信息寫入預訂表中。

3.2算法

3-2-1 初始化模塊調用如下算法完成該功能

模塊2-1:

2-1-1 生成記錄文件和信息表

2-1-2 自動填入數組和表頭

3-2-2 界面設置中調用如下算法完成該功能

模塊2-2

2-2-1 界面模塊劃分

2-2-2 界面佈局劃分

3-2-3 信息比對中調用如下算法完成該功能

模塊2-3

2-3-1 調用對應信息表進行比對

2-3-2 調用錯誤彈窗進行正確/錯誤顯示

2-3-3 信息存檔

3.3算法實現

系統初始化:

//創建記錄文件

              fyiyunlanqiu=new File("yiyun/"+dateString+"lanqiu.txt");

              fyiyunzuqiu=new File("yiyun/"+dateString+"zuqiu.txt");

              fyiyunyumaoqiu=new File("yiyun/"+dateString+"yumaoqiu.txt");

              feryunlanqiu=new File("eryun/"+dateString+"lanqiu.txt");

              feryunzuqiu=new File("eryun/"+dateString+"zuqiu.txt");

              feryunwangqiu=new File("eryun/"+dateString+"wangqiu.txt");

              ftiyuguanpingpangqiu=new File("tiyuguan/"+dateString+"pingpangqiu.txt");

              ftiyuguanyumaoqiu=new File("tiyuguan/"+dateString+"yumaoqiu.txt");

              fyiyunyuding=new File("yuding/"+dateString+"yiyunyuding.txt");

              feryunyuding=new File("yuding/"+dateString+"eryunyuding.txt");

              ftiyuguanyuding=new File("yuding/"+dateString+"tiyuguanyuding.txt");

              //若是記錄文件不存在,新建記錄文件

              if(!fyiyunlanqiu.exists()) {

                     fyiyunlanqiu.createNewFile();

                     write(fyiyunlanqiu,q);

              }

              if(!fyiyunzuqiu.exists()) {

                     fyiyunzuqiu.createNewFile();

                     write(fyiyunzuqiu,q);

              }

              if(!fyiyunyumaoqiu.exists()) {

                     fyiyunyumaoqiu.createNewFile();

                     write(fyiyunyumaoqiu,q);

              }

              if(!feryunlanqiu.exists()) {

                     feryunlanqiu.createNewFile();

                     write(feryunlanqiu,q);

              }

              if(!feryunzuqiu.exists()) {

                     feryunzuqiu.createNewFile();

                     write(feryunzuqiu,q);

              }

              if(!feryunwangqiu.exists()) {

                     feryunwangqiu.createNewFile();

                     write(feryunwangqiu,q);

              }

              if(!ftiyuguanyumaoqiu.exists()) {

                     ftiyuguanyumaoqiu.createNewFile();

                     write(ftiyuguanyumaoqiu,q);

              }

              if(!ftiyuguanpingpangqiu.exists()) {

                     ftiyuguanpingpangqiu.createNewFile();

                     write(ftiyuguanpingpangqiu,q);

              }

              if(!fyiyunyuding.exists()) {

                     fyiyunyuding.createNewFile();

                     chushi(fyiyunyuding);

              }

              if(!feryunyuding.exists()) {

                     feryunyuding.createNewFile();

                     chushi(feryunyuding);

              }

              if(!ftiyuguanyuding.exists()) {

                     ftiyuguanyuding.createNewFile();

                     chushi(ftiyuguanyuding);

              }

             

             

              //初始化記錄數組

              yiyunlanqiu=new int[10];

              yiyunzuqiu=new int[10];

              yiyunyumaoqiu=new int[10];

              eryunzuqiu=new int[10];

              eryunlanqiu=new int[10];

              eryunwangqiu=new int[10];

              tiyuguanpingpangqiu=new int[10];

              tiyuguanyumaoqiu=new int[10];

              for(int i=0;i<10;i++)

              {

                             yiyunlanqiu[i]=0;

                             yiyunzuqiu[i]=0;

                             yiyunyumaoqiu[i]=0;

                             eryunzuqiu[i]=0;

                             eryunlanqiu[i]=0;

                             eryunwangqiu[i]=0;

                             tiyuguanpingpangqiu[i]=0;

                             tiyuguanyumaoqiu[i]=0;

              }

//爲預約信息表初始寫入表頭

public static void chushi(File f) {

              try {

                     BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f)));

                     bw.write("場館"+"          "+"項目"+"          "+"姓名"+"                                      "+"學號"+"                               "+"手機號"+"                   "+"時間"+"\n");

                     bw.flush();

                     bw.close();

              }catch(Exception e1){

                     e1.printStackTrace();

              }

       }

       //預訂信息寫入文件中

       public static void write(File f,int e[]){

              try{

                     BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f)));

                     for(int i=0;i<10;i++) {

                            bw.write(String.valueOf(e[i])+"\n");

                            bw.flush();

                     }

                     bw.close();

              }catch(Exception e1){

                     e1.printStackTrace();

              }

       }

       界面佈局算法實現:

       view jf=new view("體育場館預訂系統");

              view.v=jf;

              //讀取圖片

              img=jf.getToolkit().getImage("ditu.png");

              //設置窗口顯示位置和大小

              jf.setBounds(0,0,1580,740);

              //設置窗口大小不可調節

              jf.setResizable(false);

              //禁用佈局管理器

              jf.setLayout(null);

             

             

              //添加選擇場地的單選按鈕

              //新建標籤,添加標題

              Label lchangguan=new Label("場館:");

              //設置標籤位置和大小

              lchangguan.setBounds(1160,10,60,80);

              //添加標籤到窗口

              jf.add(lchangguan);

              //新建條目組

              CheckboxGroup yundongchang=new CheckboxGroup();

              //新建單選按鈕,添加標題,添加到條目組,設置初始狀態

              Checkbox yiyun=new Checkbox("一運",yundongchang,true);

              //設置單選按鈕位置大小

              yiyun.setBounds(1220, 10, 60, 80);

              //添加單選按鈕到窗口

              jf.add(yiyun);

              Checkbox eryun=new Checkbox("二運",yundongchang,false);

              eryun.setBounds(1280, 10, 60, 80);

              jf.add(eryun);

              Checkbox tiyuguan=new Checkbox("體育館",yundongchang,false);

              tiyuguan.setBounds(1340, 10, 60, 80);

              jf.add(tiyuguan);

             

             

             

              Label lxiangmu=new Label("項目:");

              lxiangmu.setBounds(1160,100,60,80);

              jf.add(lxiangmu);

              CheckboxGroup xiangmu=new CheckboxGroup();

              Checkbox pingpangqiu=new Checkbox("乒乓球",xiangmu,false);

              pingpangqiu.setBounds(1220,100,60,80);

              jf.add(pingpangqiu);

              Checkbox lanqiu=new Checkbox("籃球",xiangmu,true);

              lanqiu.setBounds(1280,100,60,80);

              jf.add(lanqiu);

              Checkbox wangqiu=new Checkbox("網球",xiangmu,false);

              wangqiu.setBounds(1340,100,60,80);

              jf.add(wangqiu);

              Checkbox yumaoqiu=new Checkbox("羽毛球",xiangmu,false);

              yumaoqiu.setBounds(1400,100,60,80);

              jf.add(yumaoqiu);

              Checkbox zuqiu=new Checkbox("足球",xiangmu,false);

              zuqiu.setBounds(1460,100,60,80);

              jf.add(zuqiu);

             

             

             

              Label shijian=new Label("時間:");

              shijian.setBounds(1160, 190,60,80);

              jf.add(shijian);

              //新建複選框,設置標題,設置初始狀態

 

             

              Checkbox t8_9=new Checkbox("8~9",false);

              //設置複選框單元位置大小

              t8_9.setBounds(1220, 190, 60, 80);

              //添加複選框單元到窗口

              jf.add(t8_9);

              Checkbox t9_10=new Checkbox("9~10",false);

              t9_10.setBounds(1280, 190, 60, 80);

              jf.add(t9_10);

              Checkbox t10_11=new Checkbox("10~11",false);

              t10_11.setBounds(1340, 190, 60, 80);

              jf.add(t10_11);

              Checkbox t11_12=new Checkbox("11~12",false);

              t11_12.setBounds(1400, 190, 60, 80);

              jf.add(t11_12);

              Checkbox t12_13=new Checkbox("12~13",false);

              t12_13.setBounds(1460, 190, 60, 80);

              jf.add(t12_13);

              Checkbox t13_14=new Checkbox("13~14",false);

              t13_14.setBounds(1220, 280, 60, 80);

              jf.add(t13_14);

              Checkbox t14_15=new Checkbox("14~15",false);

              t14_15.setBounds(1280, 280, 60, 80);

              jf.add(t14_15);

              Checkbox t15_16=new Checkbox("15~16",false);

              t15_16.setBounds(1340, 280, 60, 80);

              jf.add(t15_16);

              Checkbox t16_17=new Checkbox("16~17",false);

              t16_17.setBounds(1400, 280, 60, 80);

              jf.add(t16_17);

              Checkbox t17_18=new Checkbox("17~18",false);

              t17_18.setBounds(1460, 280, 60, 80);

              jf.add(t17_18);

             

             

              Label lxingming=new Label("姓名:");

              lxingming.setBounds(1160,370,60,80);

              jf.add(lxingming);

              //新建文本框設置初始列數

              TextField txingming=new TextField(15);

              //設置文本框位置大小

              txingming.setBounds(1260, 400, 200, 20);

              //添加文本框到窗口

              jf.add(txingming);

             

             

             

              Label lxuehao=new Label("學號:");

              lxuehao.setBounds(1160,460,60,80);

              jf.add(lxuehao);

              TextField txuehao=new TextField(15);

              txuehao.setBounds(1260, 490, 200, 20);

              jf.add(txuehao);

             

             

             

              Label lshoujihao=new Label("手機號:");

              lshoujihao.setBounds(1160,550,60,80);

              jf.add(lshoujihao);

              TextField tshoujihao=new TextField(15);

              tshoujihao.setBounds(1260, 580, 200, 20);

              jf.add(tshoujihao);

             

             

              //新建按鈕,設置標題

              JButton jbqueren=new JButton("確認");

              //設置按鈕位置大小

              jbqueren.setBounds(1320, 640, 80, 40);

              //設置按鈕顏色

              jbqueren.setBackground(Color.LIGHT_GRAY);

              //給按鈕添加鼠標監聽

信息比對算法實現:

       public static boolean iskong(File f,int j){

              String s="";

              for(int i=0;i<10;i++) {

                     if(q[i]==1) {

                            t[i]++;

                     }

              }

              for(int i=0;i<10;i++) {

                     if(t[i]>j) {

                            s=s+String.valueOf(i+8)+"~"+String.valueOf(i+9)+" ";

                     }

              }

              if(s.length()!=0) {

                     error(v,"如下時間段沒法預定:"+s,"預約時間衝突錯誤");

                     return false;

              }

              else {

                     write(f,t);

                     return true;

              }

       }

       //判斷輸入輸入預訂信息的正確性

       public static boolean isRight(){

              if(s1.equals("一運")){

                     if(s2.equals("籃球")){

                            read(fyiyunlanqiu);

                            boolean b=iskong(fyiyunlanqiu,yiyunlanqiu1);

                            if(b==true) {

                                   writetoyuding(fyiyunyuding);

                                   return true;

                            }

                            else {return false;}

                     }

                     if(s2.equals("足球")){

                            read(fyiyunzuqiu);

                            boolean b=iskong(fyiyunzuqiu,yiyunzuqiu1);

                            if(b==true) {

                                   writetoyuding(fyiyunyuding);

                                   return true;

                            }

                            else {

                                   return false;

                            }

                     }

                     if(s2.equals("羽毛球")){

                            read(fyiyunyumaoqiu);

                            boolean b=iskong(fyiyunyumaoqiu,yiyunyumaoqiu1);

                            if(b==true) {

                                   writetoyuding(fyiyunyuding);

                                   return true;

                            }

                            else {

                                   return false;

                            }

                     }

                     if(s2.equals("網球")){

                            error(v,"抱歉,一運沒有網球,請從新預訂。","項目選擇錯誤");

                            return false;

                     }

                     if(s2.equals("乒乓球")){

                            error(v,"抱歉,一運沒有乒乓球,請從新預訂。","項目選擇錯誤");

                            return false;

                     }

              }

              if(s1.equals("二運")){

                     if(s2.equals("籃球")){

                            read(feryunlanqiu);

                            boolean b=iskong(feryunlanqiu,eryunlanqiu1);

                            if(b==true) {

                                   writetoyuding(feryunyuding);

                                   return true;

                            }

                            else {

                                   return false;

                            }

                     }

                     if(s2.equals("足球")){

                            read(feryunzuqiu);

                            boolean b=iskong(feryunzuqiu,eryunzuqiu1);

                            if(b==true) {

                                   writetoyuding(feryunyuding);

                                   return true;

                            }

                            else {

                                   return false;

                            }

                     }

                     if(s2.equals("網球")){

                            read(feryunwangqiu);

                            boolean b=iskong(feryunwangqiu,eryunwangqiu1);

                            if(b==true) {

                                   writetoyuding(feryunyuding);

                                   return true;

                            }

                            else {

                                   return false;

                            }

                     }

                     if(s2.equals("乒乓球")){

                            error(v,"抱歉,二運沒有乒乓球,請從新預訂。","項目選擇錯誤");

                            return false;

                     }

                     if(s2.equals("羽毛球")){

                            error(v,"抱歉,二運沒有羽毛球,請從新預訂。","項目選擇錯誤");

                            return false;

                     }

              }

              if(s1.equals("體育館")){

                     if(s2.equals("乒乓球")){

                            read(ftiyuguanpingpangqiu);

                            boolean b=iskong(ftiyuguanpingpangqiu,tiyuguanpingpangqiu1);

                            if(b==true) {

                                   writetoyuding(ftiyuguanyuding);

                                   return true;

                            }

                            else {

                                   return false;

                            }

                     }

                     if(s2.equals("羽毛球")){

                            read(ftiyuguanyumaoqiu);

                            boolean b=iskong(ftiyuguanyumaoqiu,tiyuguanyumaoqiu1);

                            if(b==true) {

                                   writetoyuding(ftiyuguanyuding);

                                   return true;

                            }

                            else {

                                   return false;

                            }

                     }

                     if(s2.equals("籃球")){

                            error(v,"抱歉,體育館沒有籃球,請從新預訂。","項目選擇錯誤");

                            return false;

                     }

                     if(s2.equals("足球")){

                            error(v,"抱歉,體育館沒有足球,請從新預訂。","項目選擇錯誤");

                            return false;

                     }

                     if(s2.equals("網球")){

                            error(v,"抱歉,體育館沒有網球,請從新預訂。","項目選擇錯誤");

                            return false;

                     }

              }

              return false;

       }

       //錯誤信息彈窗輸出,s爲錯誤消息,title爲窗口標題

       public static void error(view v,String s,String title) {

              JOptionPane.showMessageDialog(v,s,title,JOptionPane.NO_OPTION);

       }

3.4程序流程

 

3.5測試要點

採用黑盒測試方法,對用戶輸入,場館項目超額,信息表記錄進行測試。

相關文章
相關標籤/搜索