




已阅读5页,还剩17页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
数据结构与算法设计课程设计专业 信息与计算科学 班级 信息0802 学号200801010201 姓名楼茂成(签名) 完成日期 2010.06.14 指导教师 李元觉(签名)1、 程序设计说明书【设计题目】 图书馆业务模拟程序【问题描述】这是一个模拟用户对图书分类查询、借书和还书的小程序,为了实现图书馆日常业务模拟。 【软件功能】1.实现用户对图书的分类查询,如书名、作者、时间。2.通过线性表实现mybook的建立、存储、插入、查找和删除。3.运用string数组来输入mybook的内容,如书名、时间,科类。4.运用kindstr实现科目的分类,如自然科学、计算机、工业类 等等。5.输入year,month,day,type,price查询书籍的借用情况。【算法思想】1.运用swing实现图书馆界面。2.通过线性表实现mybook的建立、存储、插入、查找和删除。3.用ActionListener()对主类BookSystem进行监听,用actionPerformed()对MenuBar的监听。4.使用Vector类以实现类似动态数组的功能。5.用catch(Exception ie)函数捕获异常。【类的设计】public class BookSystem implements ActionListener/主类 Vector books=new Vector(20,5); JTextField jtf=new JTextField7; JLabel jlb=new JLabel5; JPanel panel; Choice kind=new Choice(); String kindstr=选择分类,自然科学,计算机 ,金融类 ,工业类 ,汽车类 ;【存储结构设计】【模块划分及调用关系】【模块流程图】【界面设计】【用户手册】2、 程序上机调试报告【语法错误及其排除】 if(jtf1.getText().length()=0|jtf1.getText().length()4|jtf2.getText().length()=0|Integer.parseInt(jtf2.getText()12|ext().length()=0|Integer.parseInt(jtf3.getText()30)正确 if(jtf1.getText().length()=0|jtf1.getText().length()4|jtf2.getText().length()=0|Integer.parseInt(jtf2.getText()12|jtf3.getText().length()=0|Integer.parseInt(jtf3.getText()30)【算法错误及其排除】一开始没有进行异常处理,后来加进去。程序测试结果【测试数据】数据结构 王学军 26 1996.06.06【输出结果】【程序性能评价】用于图书馆管理系统的数据的输入、删除、查找等等。【性能改进方向】可以添加背景使页面更加美观。【收获及体会】3、 源程序代码/package 图书管理系统;import java.io.*;import java.util.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.table.DefaultTableModel;class MyBook int year,month,day,type,price; String name,author; public MyBook(String name,String author,int type,int price,int year,int month,int day) =name; this.author=author; this.type=type; this.price=price; this.year=year; this.month=month; this.day=day; public String print()/输出MyBook对象的所有内容 String str=name+-+author+-+type+-+price+-+year+-; if(month10) str+=0+month+-; else str+=month+-; if(day10) str+=0+day; else str+=day; return str; public int getdata()/获得时间数 String str=year+; if(month10) str+=0+month; else str+=month; if(day10) str+=0+day; else str+=day; return Integer.parseInt(str); public String getstr()/获得用于JTable的内容数组 String str=new String5; str0=name; str1=author; str2=type+; str3=price+; str4=year+-+month+-+day; return str; public String getName()/获得书名 return name; public class BookSystem implements ActionListener/主类 Vector books=new Vector(20,5); JTextField jtf=new JTextField7; JLabel jlb=new JLabel5; JPanel panel; Choice kind=new Choice(); String kindstr=选择分类,自然科学,计算机 ,金融类 ,工业类 ,汽车类 ; public BookSystem()/界面 JFrame frame=new JFrame(书籍管理系统); frame.setBackground(Color.white); frame.setSize(400, 291); frame.setVisible(true); frame.setLayout(new BorderLayout(); MenuBar menubar=new MenuBar(); Menu filemenu=new Menu(文件); Menu editmenu=new Menu(编辑); Menu displaymenu=new Menu(显示); Menu sortmenu=new Menu(排序); Menu statisticsmenu=new Menu(统计); MenuItem f_new=new MenuItem(新建); MenuItem f_open=new MenuItem(打开); MenuItem f_save=new MenuItem(保存); MenuItem f_exit=new MenuItem(退出); MenuItem e_insert=new MenuItem(插入); MenuItem e_delete=new MenuItem(删除); MenuItem e_update=new MenuItem(更新); MenuItem displayItem=new MenuItemkindstr.length; for(int i=0;ikindstr.length;i+) if(i=0)displayItemi=new MenuItem(查看全部); elsedisplayItemi=new MenuItem(kindstri); displaymenu.add(displayItemi); MenuItem sort=new MenuItem(排序); MenuItem statistics=new MenuItem(统计所有图书); menubar.add(filemenu); menubar.add(editmenu); menubar.add(displaymenu); menubar.add(sortmenu); menubar.add(statisticsmenu); filemenu.add(f_new); filemenu.add(f_open); filemenu.add(f_save); filemenu.addSeparator(); filemenu.add(f_exit); editmenu.add(e_insert); editmenu.add(e_delete); editmenu.add(e_update); sortmenu.add(sort); statisticsmenu.add(statistics); frame.setMenuBar(menubar); panel=new JPanel(new BorderLayout(); panel.setBackground(Color.white); panel.add(new JLabel(new ImageIcon(Image图书管理系统.jpg),BorderLayout.CENTER); frame.add(panel,BorderLayout.CENTER); f_new.addActionListener(this); f_open.addActionListener(this); f_save.addActionListener(this); f_exit.addActionListener(this); e_insert.addActionListener(this); e_delete.addActionListener(this); e_update.addActionListener(this); sort.addActionListener(this); statistics.addActionListener(this); displayItem0.addActionListener(this); displayItem1.addActionListener(this); displayItem2.addActionListener(this); displayItem3.addActionListener(this); displayItem4.addActionListener(this); displayItem5.addActionListener(this); for(int i=0;ikindstr.length;i+) kind.addItem(kindstri); frame.setSize(400, 300); public static void main(String args)/main函数 new BookSystem(); public void file(int n)/文件模块 String str2=成功,str1=null; int flag=1; if(n=0)/收到新建命令 if(f_new()str1=新建成功;edit(0); else str2=错误;str1=新建失败;flag=0; else if(n=1)/收到打开命令 if(f_open()str1=打开成功;jtable(books,panel); else str2=错误;str1=打开失败;flag=0; else if(n=2)/收到保存命令 if(f_save()str1=保存成功; else str2=错误;str1=保存失败;flag=0; JOptionPane.showMessageDialog(null,str1,str2,flag); public boolean f_new()/新建文件 books.removeAllElements(); if(!new File(books.dat).exists() else new File(books.dat).delete(); try return new File(books.dat).createNewFile(); catch(IOException e) e.printStackTrace(); return true; public boolean f_open()/打开文件 books.removeAllElements(); try BufferedReader input=new BufferedReader(new FileReader(books.dat); String s=null; while(s=input.readLine()!=null) String str=s.split(-); books.add(new MyBook(str0,str1,Integer.parseInt(str2),Integer.parseInt(str3),Integer.parseInt(str4),Integer.parseInt(str5),Integer.parseInt(str6); return true; catch(Exception e)e.printStackTrace(); return false; public boolean f_save()/保存文件 if(new File(books.dat).exists() new File(books.dat).delete(); try FileOutputStream fos=new FileOutputStream(new File(books.dat); for(int i=0;ibooks.size();i+)fos.write(books.elementAt(i).print()+rn).getBytes(); fos.close(); return true; catch(Exception e) e.printStackTrace(); return false; public void edit(int n)/编辑模块 if(n=0)/edit受到插入命令 for(int i=0;i7;i+)if(i4) jtfi=new JTextField(2); JButton bn1=new JButton(确定); JButton bn2=new JButton(返回); panel.removeAll();/重绘panel panel.setBackground(Color.white); panel.setLayout(new GridLayout(6,1); JPanel p1=new JPanel(new FlowLayout(FlowLayout.LEFT); JPanel p2=new JPanel(new FlowLayout(FlowLayout.LEFT); JPanel p3=new JPanel(new FlowLayout(FlowLayout.LEFT); JPanel p4=new JPanel(new FlowLayout(FlowLayout.LEFT); JPanel p5=new JPanel(new FlowLayout(FlowLayout.LEFT); JPanel p6=new JPanel(new FlowLayout(FlowLayout.LEFT,1,1); JPanel p7=new JPanel(new FlowLayout(FlowLayout.CENTER); panel.add(p1); panel.add(p2); panel.add(p3); panel.add(p4); panel.add(p5); panel.add(p7); p1.add(new Label(书名:); p1.add(jtf0); p1.add(jlb0); p2.add(new Label(作者:); p2.add(jtf1); p2.add(jlb1); p3.add(new Label(选择分类:); p3.add(kind); p3.add(jlb2); p4.add(new Label(价格:); p4.add(jtf3); p4.add(jlb3); p5.add(new Label(时间:); p5.add(p6); p6.add(jtf4); p6.add(new Label(-); p6.add(jtf5); p6.add(new Label(-); p6.add(jtf6); p5.add(jlb4); p7.add(bn1); p7.add(bn2); panel.validate(); bn1.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e) int flag=0; for(int i=0;i4|jtf5.getText().length()=0|Integer.parseInt(jtf5.getText()12|jtf6.getText().length()=0|Integer.parseInt(jtf6.getText()30) flag+; jlb4.setText(请输入正确的时间); if(flag=0) intdate(jtf5, jtf6); if(e_insert(new MyBook(jtf0.getText(),jtf1.getText(),kind.getSelectedIndex()-1,Integer.parseInt(jtf3.getText(),Integer.parseInt(jtf4.getText(),Integer.parseInt(jtf5.getText(),Integer.parseInt(jtf6.getText() for(int i=0;i4|jtf2.getText().length()=0|Integer.parseInt(jtf2.getText()12|jtf3.getText().length()=0|Integer.parseInt(jtf3.getText()30) flag+; jlb1.setText(请输入正确的时间); if(flag=0) intdate(jtf2, jtf3); if(e_delete(jtf0.getText(), Integer.parseInt(jtf1.getText()+jtf2.getText()+jtf3.getText() jtable(books,panel); JOptionPane.showMessageDialog(null,删除成功,成功,1); else JOptionPane.showMessageDialog(null,删除失败,错误,0); ); bn2.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e) jtable(books,panel); ); else if(n=2)/收到更新命令 jtf0=new JTextField(12); jtf1=new JTextField(3); jtf2=new JTextField(2); jtf3=new JTextField(2); jlb0=new JLabel(); jlb1=new JLabel(); JButton bn1=new JButton(查询); JButton bn2=new JButton(返回); panel.removeAll(); panel.setBackground(Color.white); panel.setLayout(new GridLayout(2,1); JPanel pu=new JPanel(new BorderLayout(); JPanel pd=new JPanel(new GridLayout(3,1); JPanel p1=new JPanel(new FlowLayout(FlowLayout.LEFT); JPanel p2=new JPanel(new FlowLayout(FlowLayout.LEFT); JPanel p3=new JPanel(new FlowLayout(FlowLayout.LEFT,1,1); JPanel p4=new JPanel(new FlowLayout(FlowLayout.CENTER); panel.add(pu); panel.add(pd); jtable(books, pu); pd.add(p1); pd.add(p2); pd.add(p4); p1.add(new Label(书名:); p1.add(jtf0); p1.add(jlb0); p2.add(new Label(时间:); p2.add(p3); p3.add(jtf1); p3.add(new Label(-); p3.add(jtf2); p3.add(new Label(-); p3.add(jtf3); p3.add(jlb1); p4.add(bn1); p4.add(bn2); panel.validate(); bn1.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e) int flag=0; jlb0.setText(); jlb1.setText(); if(jtf0.getText().length()=0) flag+; jlb0.setText(请输入书名); if(jtf1.getText().length()=0|jtf1.getText().length()4|jtf2.getText().length()=0|Integer.parseInt(jtf2.getText()12|jtf3.getText().length()=0|Integer.parseInt(jtf3.getText()30) flag+; jlb1.setText(请输入正确的时间); if(flag=0) intdate(jtf2, jtf3); System.out.println(jtf0.getText()+-+Integer.parseInt(jtf1.getText()+jtf2.getText()+jtf3.getText(); final int q=e_update(jtf0.getText(), Integer.parseInt(jtf1.getText()+jtf2.getText()+jtf3.getText(); System.out.println(q=+q); if(q!=-1)/找到要更新的数据 MyBook mb=books.elementAt(q); JButton btn1=new JButton(确定); JButton btn2=new JButton(返回); for(int i=0;i7;i+) if(i4) jtfi=new JTextField(2); panel.removeAll(); panel.setBackground(Color.white); panel.setLayout(new GridLayout(6,1); JPanel p1=new JPanel(new FlowLayout(FlowLayout.LEFT); JPanel p2=new JPanel(new FlowLayout(FlowLayout.LEFT); JPanel p3=new JPanel(new FlowLayout(FlowLayout.LEFT); JPanel p4=new JPanel(new FlowLayout(FlowLayout.LEFT); JPanel p5=new JPanel(new FlowLayout(FlowLayout.LEFT); JPanel p6=new JPanel(new FlowLayout(FlowLayout.LEFT,1,1); JPanel p7=new JPanel(new FlowLayout(FlowLayout.CENTER); panel.add(p1); panel.add(p2); panel.add(p3); panel.add(p4); panel.add(p5); panel.add(p7); p1.add(new Label(书名:); p1.add(jtf0); jtf0.setText(); p1.add(jlb0); p2.add(new Label(作者:); p2.add(jtf1); jtf1.setText(mb.author); p2.add(jlb1); p3.add(new Label(选择分类:); p3.add(kind); kind.select(mb.type+1); p3.add(jlb2); p4.add(new Label(价格:); p4.add(jtf3); jtf3.setText(mb.price+); p4.add(jlb3); p5.add(new Label(时间:); p5.add(p6); p6.add(jtf4); jtf4.setText(mb.year+); p6.add(new Label(-); p6.add(jtf5); jtf5.setText(mb.month+); p6.add(new Label(-); p6.add(jtf6); jtf6.setText(mb.day+); p5.add(jlb4); p7.add(btn1); p7.add(btn2); panel.validate(); btn1.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e) int flag=0; for(int i=0;i4|jtf5.getText().length()=0|Integer.parseInt(jtf5.getText()12|jtf6.getText().length()=0|Integer
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025美容化妆人员每日一练试卷及参考答案详解(完整版)
- 2023年度自考专业(国贸)考前冲刺练习试题及答案详解(有一套)
- 法律硕士全真模拟模拟题附完整答案详解【夺冠】
- 2024年中医助理医师综合提升测试卷【含答案详解】
- 计算机一级模考模拟试题附答案详解【预热题】
- 2024年自考专业(公共关系)考试历年机考真题集附参考答案详解(培优)
- 企业内部培训师培养与发展方案
- 乡村文旅IP文创产品设计与推广方案
- 2025年泰州职业技术学院单招《物理》考试彩蛋押题含答案详解(完整版)
- 湖南安全技术职业学院单招《物理》自我提分评估及参考答案详解【考试直接用】
- 赛轮埃及年产300万条半钢子午线轮胎项目可行性研究报告
- 催收行业培训课件
- 保护牙齿爱护牙齿2025年全国爱牙日全文课件
- 2025年海南事业单位联考笔试历年典型考题及考点剖析附带答案详解
- 新疆G20联盟文海大联考2025-2026学年高三上学期起点物理考试题(含答案)
- 2025年水发集团有限公司招聘(216人)备考练习试题及答案解析
- 2025年高考四川卷生物真题试卷(解析版)
- 2025年度保姆专业照护老年呼吸道疾病患者服务合同-温馨呵护
- 媒介素养教育培训课件
- 2025年地方病防治知识及技能考察试卷答案及解析
- 视频监控系统确保安全文明施工的技术组织措施
评论
0/150
提交评论