![[IT-计算机]全国交通咨询模拟数据结构Jaa课程设计.doc_第1页](http://file.renrendoc.com/FileRoot1/2019-12/22/1cbb4956-5c29-4a51-97c0-69dfb08f2da5/1cbb4956-5c29-4a51-97c0-69dfb08f2da51.gif)
![[IT-计算机]全国交通咨询模拟数据结构Jaa课程设计.doc_第2页](http://file.renrendoc.com/FileRoot1/2019-12/22/1cbb4956-5c29-4a51-97c0-69dfb08f2da5/1cbb4956-5c29-4a51-97c0-69dfb08f2da52.gif)
![[IT-计算机]全国交通咨询模拟数据结构Jaa课程设计.doc_第3页](http://file.renrendoc.com/FileRoot1/2019-12/22/1cbb4956-5c29-4a51-97c0-69dfb08f2da5/1cbb4956-5c29-4a51-97c0-69dfb08f2da53.gif)
![[IT-计算机]全国交通咨询模拟数据结构Jaa课程设计.doc_第4页](http://file.renrendoc.com/FileRoot1/2019-12/22/1cbb4956-5c29-4a51-97c0-69dfb08f2da5/1cbb4956-5c29-4a51-97c0-69dfb08f2da54.gif)
![[IT-计算机]全国交通咨询模拟数据结构Jaa课程设计.doc_第5页](http://file.renrendoc.com/FileRoot1/2019-12/22/1cbb4956-5c29-4a51-97c0-69dfb08f2da5/1cbb4956-5c29-4a51-97c0-69dfb08f2da55.gif)
已阅读5页,还剩41页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
数据结构课程设计报告全国交通咨询模拟 学院(系): 计算机科学与工程学院 班 级: 学生姓名: 学号 指导教师: 时间: 从2011年12月19日 到2011年12月23日一、课程设计概述:使用语言: java编译环境:java虚拟机二、课程设计题目一实验内容全国交通咨询模拟问题描述1、 管理员可以添加、修改、删除各交通路线信息。2、 用户查询从某一地点到另一地点的信息,提供查询转车次数最少、花费最少、所用时间最少的相关信息。需求分析1、 管理员和用户拥有不同的操作界面。管理员从键盘输入个交通路线并保存在traininformation.txt中。2、 对文件traininformation.txt中的数据进行处理,要求具有如下功能:、 城市信息进行编辑。、 对列车时刻表进行编辑(增设或删除)的功能。、 提供三种最优决策:最省钱到达,转车最少。、 提供各列车详细信息。3、 界面美观概要设计class moneyleast/求出两站点花费最少的路径class traincontral/从文件中读出列车的所有信息或者将列车的信息写入到文件class traingraph/列车航线交通图class admframe/管理员登陆界面class searchinframe/用户查询信息和显示信息界面 存储结构class city/城市存储private string cityname;class train /列车存储 private string trainid; private city startcity; private city endcity; private date startdate; private date enddate;private int money; 详细设计- city-/* * 城市的对象 * 城市有城市名 * 实现序列化 * 重写equals方法和tostring方法 */package com.consel;import java.io.serializable;/实现序列化的接口public class city implements serializable private static final long serialversionuid = 5612649006026227701l; private string cityname; public city(string cityname) this.cityname = cityname; public string getcityname() return cityname; public void setcityname(string cityname) this.cityname = cityname; override public string tostring() return cityname; override public boolean equals(object obj) if (obj instanceof city) city temp = (city) obj; if (this.cityname.equals(temp.cityname) return true; return false; - moneyleast-/* * moneyleast 查找从花费最少的路径,及乘车路径 * 使用的是普里姆算法 */package com.consel;public class moneyleast final static int maxmoney = 10000; int n; int s;/s用来存储n个节点的标记 int minmoney, u = 0; /t为列车信息图,c为起始城市,数组money是用来存储最少花费的路径,path是用来存储节点的上一节点 public void leastmoney(traingraph t, city c, int money, city path) throws exception n = t.getnumofver(); s = new intn; for (int i = 0; i n; i+) moneyi = t.getmoney(c, t.city.get(i); si = 0; if (moneyi maxmoney) pathi = c; else pathi = null; st.city.indexof(c) = 1; for (int i = 0; i n; i+) minmoney = maxmoney; for (int j = 0; j n; j+) if (sj = 0 & moneyj minmoney) u = j; minmoney = moneyj; if (minmoney = maxmoney) return; su = 1; city city = t.city.get(u); for (int j = 0; j n; j+) if (sj = 0 & t.getmoney(city, t.city.get(j) maxmoney & moneyu + t.getmoney(city, t.city.get(j) moneyj) moneyj = moneyu + t.getmoney(city, t.city.get(j); pathj = city; - moneytest-package com.consel;import java.util.iterator;import java.util.stack;public class moneytest moneyleast ml = new moneyleast(); traingraph tg = new traingraph(); int money; city path; public stack st = new stack(); public moneytest() int n = tg.city.size(); money = new intn; path = new cityn; for (int i = 0; i n; i+) moneyi = tg.maxmoney; pathi = null; public stack findmoneyleast(city c1,city c2) throws exception ml.leastmoney(tg, c1,money, path); stack s = new stack(); s.add(c2); while (!c2.equals(c1) city c3 = pathtg.city.indexof(c2); s.add(c3); traincontral ct = new traincontral(); ct.trainread(); iterator i = ct.train.iterator(); while(i.hasnext() train temp = i.next(); if(temp.getstartcity().equals(c3) & temp.getendcity().equals(c2) st.add(temp); c2 = c3; return s; - train-/* * train 序列化,存储列车的信息,包括id,起始站,终点站,发车时间,到站时间,价格 */package com.consel;import java.util.*;import java.io.serializable;public class train implements serializable private static final long serialversionuid = 5612649006026227700l; private string trainid;/列车号 private city startcity;/起始站 private city endcity;/终点站 private date startdate;/发车时间 private date enddate;/到站时间 private int money;/价格 public train(string trainid, city startcity, city endcity, date startdate, date enddate, int money) this.trainid = trainid; this.startcity = startcity; this.endcity = endcity; this.startdate = startdate; this.enddate = enddate; this.money = money; /* * return the trainid */ public string gettrainid() return trainid; /* * return the money */ public int getmoney() return money; /* * return the startcity */ public city getstartcity() return startcity; /* * return the endcity */ public city getendcity() return endcity; /* * return the startdate */ public date getstartdate() return startdate; /* * return the enddate */ public date getenddate() return enddate; - traincontral-/* * traincontral 从文件traininformation.txt中读出各列车信息或将各列车信息写入到文件traininformation.txt中 */package com.consel;import java.io.*;import java.util.*;public class traincontral file filename = new file(config/traininformation.txt); objectinputstream ois; objectoutputstream oos; public list train = new arraylist(); /* * 从traininformation.txt读出所有列车的信息 * 并存储于链表train中 */ public void trainread() try ois = new objectinputstream(new fileinputstream(filename);/文件输入流 train = (list) ois.readobject(); catch (filenotfoundexception ex) ex.printstacktrace(); catch (ioexception ex) ex.printstacktrace(); catch (classnotfoundexception ex) ex.printstacktrace(); finally try ois.close();/ 关闭文件输入流 catch (exception exx) exx.printstacktrace(); /* * 将链表t中的所有火车信息写入到traininformation.txt中 * param t */ public void trainwrite(list t) try oos = new objectoutputstream(new fileoutputstream(filename);/ 文件输出流 oos.writeobject(t); catch (filenotfoundexception ex) ex.printstacktrace(); catch (ioexception ex) ex.printstacktrace(); finally try oos.flush();/关闭文件缓冲流 oos.close();/关闭文件流 catch (exception exx) exx.printstacktrace(); - traingraph-/* * traingraph 表示所有列车的信息 * 查找以一个城市作为起点站,可以到达的另一个城市 */package com.consel;import java.util.*;public class traingraph final static int maxmoney = 10000; list city = new arraylist(); traincontral tc = new traincontral(); int edges; public list train; stack stack1 = new stack(); public stack stack = new stack();/*临时保存路径节点的栈*/ public arraylist sers = new arraylist();/*存储路径的集合*/ public int getnumofver() return city.size(); public traingraph() /构造方法 tc.trainread();/从文件中读出所有列车的信息 int n = tc.train.size(); train = tc.train; iterator it = train.iterator(); /* * 存储交通路线中所有涉及到的城市 */ while (it.hasnext() train t = (train) it.next(); city c1 = t.getstartcity(); city c2 = t.getendcity(); int x = city.indexof(c1); int y = city.indexof(c2); if (x 0) city.add(c1); if (y 0) city.add(c2); edges = new intcity.size()city.size(); for (int i = 0; i city.size(); i+) for (int j = 0; j = 0) return getfirstneighbor(n); return - 1; /查找邻接的城市 private int getfirstneighbor(int v) throws exception if (v city.size() throw new exception(参数错误!); for (int col = 0; col 0) return col; return -1; /查找下一个邻接城市 public int getnextneighbor(city c1, city c2) throws exception int m = city.indexof(c1); int n = city.indexof(c2); if (m = 0 & n = 0) return getnextneighbor(m, n); return -1; /查找下一个邻接城市 private int getnextneighbor(int v1, int v2) throws exception if (v1 city.size() | v2 city.size() throw new exception(参数错误!); for (int col = v2 + 1; col 0) return col; return -1; /返回从c1到c2直达所花费的钱 public int getmoney(city c1, city c2) throws exception int m = city.indexof(c1); int n = city.indexof(c2); if (m 0 | n 0) throw new exception(城市c1或c2错误!); else iterator i = train.iterator(); train temp = null; boolean flag = false; while (i.hasnext() temp = i.next(); if (temp.getstartcity().equals(c1) & temp.getendcity().equals(c2) flag = true; break; if (flag) return temp.getmoney(); else return maxmoney; private boolean iscityinstack(city city) /判断节点是否在栈中 iterator it = stack.iterator(); while (it.hasnext() city node1 = it.next(); if (city.equals(node1) return true; return false; / 存储一条通路 private void savepath() stack temp = new stack(); iterator i = stack.iterator(); while (i.hasnext() city c = i.next(); temp.add(c); sers.add(temp); /*转储*/ / 查找从startcity到endcity的所有路径 public void getpaths(city startcity, city endcity) throws exception stack.push(startcity); int n = getfirstneighbor(startcity); if (n = 0) city c = city.get(n); getpaths(startcity, endcity, c, startcity); while (c != null) n = getnextneighbor(startcity, c); if (n 0) c = city.get(n); getpaths(startcity, endcity, c, startcity); else c = null; / 用递归的方法求startcity到endcity的路径currentcity是当前的城市,percity是currentcity的上一个城市 private boolean getpaths(city startcity, city endcity, city currentcity, city percity) throws exception city ncity = null; if (currentcity != null & percity != null & currentcity.equals(percity) return false; if (currentcity != null) stack.push(currentcity); if (currentcity.equals(endcity) savepath(); stack.pop(); return true; else int n = getfirstneighbor(currentcity); if (n = 0) ncity = city.get(n); else ncity = null; while (ncity != null) if (percity != null & (ncity.equals(startcity) | percity.equals(ncity) | iscityinstack(ncity) n = getnextneighbor(currentcity, ncity); if (n = 0) ncity = city.get(n); else ncity = null; continue; if (getpaths(startcity, endcity, ncity, currentcity) if (!stack.isempty() stack.pop(); n = getnextneighbor(currentcity, ncity); if (n = 0) ncity = city.get(n); else ncity = null; if (!stack.isempty() stack.pop(); return false; else return false; - admframe-/* * 管理员登陆界面 * 用户名为:adm * 口令为:123456 */package com.desgin;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class admframe imageicon img = new imageicon(config/adm.gif); jlabel background = new jlabel(img); jframe admframe = new jframe(); jlabel user = new jlabel(用户名:); jtextfield userinput = new jtextfield(20); jlabel password = new jlabel(口 令:); jpasswordfield passwordin = new jpasswordfield(20); jpanel panel = new jpanel(); jbutton login = new jbutton(登陆); jbutton exit = new jbutton(退出); public admframe() admframe.setlayout(null); admframe.settitle(administrator); admframe.setsize(img.geticonwidth(), img.geticonheight() + 20); admframe.setlocationrelativeto(null); admframe.setdefaultcloseoperation(jframe.exit_on_close); panel.setlayout(new gridlayout(2, 2, 20, 20); panel.add(user); user.sethorizontalalignment(jtextfield.right); password.sethorizontalalignment(jtextfield.right); panel.add(userinput); panel.add(password); panel.add(passwordin); panel.setbounds(40, 50, 250, 60); jpanel temppanel = new jpanel(); temppanel.add(login); temppanel.add(exit); temppanel.setbounds(130, 130, 200, 40); admframe.add(panel); admframe.add(temppanel); admframe.add(background); background.setbounds(0, 0, img.geticonwidth(), img.geticonheight(); admframe.setvisible(true); admframe.setresizable(false); exit.addactionlistener(new actionlistener() public void actionperformed(actionevent e) system.exit(0); ); login.addactionlistener(new actionlistener() public void actionperformed(actionevent e) if (userinput.gettext().trim().equals() | passwordin.gettext().trim().equals() joptionpane.showmessagedialog(null, 请输入用户名或口令!, warning, joptionpane.warning_message); else if (userinput.gettext().equals(adm) & passwordin.gettext().equals(123456) admframe.dispose(); admmainwindow amw = new admmainwindow(); amw.setvisible(true); else joptionpane.showmessagedialog(null, 用户名或口令错误,请重新输入!, 用户名或口令错误, joptionpane.error_message); ); public static void main(string args) admframe af = new admframe(); - admmflistener-/* * 管理员登陆后的界面监听器 * 对添加、修改、删除作出相应的变化 */package com.desgin;import com.consel.*;import com.consel.traincontral;import java.awt.event.*;import java.util.*;import javax.swing.joptionpane;public class admmflistener extends mous
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025版绿色建筑土建工程承包合作协议
- 2025年度制造业短期生产线操作人员劳务派遣合同
- 2025聘请全职律师合同范本
- 红酒柜知识培训课件
- 红酒基本知识培训内容
- 语文知识书籍培训课件
- 红茶品鉴培训课件
- 2025年租车服务免责合同协议书
- 2025年劳动合同法实践:员工擅自解约公司有权提起劳动仲裁
- 生产流程标准化操作指南
- 避免车祸安全知识培训课件
- 胸腰椎压缩骨折课件
- 音乐课简谱教学课件
- 2025年放射工作人员培训考试试题及答案
- 2025-2026学年统编版(2024)小学语文一年级上册教学计划及进度表
- 中小学教师中高级职称答辩备考试题及答案(50题)
- 剖析我国公立医院管理体制:问题洞察与改革路径探究
- 胰腺超声标准切面
- 2025年法院书记员招聘考试笔试试题附答案
- 未成年人违法犯罪警示教育
- 律师事务所客户数据安全管理制度
评论
0/150
提交评论