




已阅读5页,还剩24页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
成都信息工程学院计算机学院课 程 实 验 报 告实验课程:Java程序设计实验项目:图书管理系统指导教师:汤蓉学生姓名:向浩学生学号:2011051020班 级:计科111班实验地点: 6306上交时间:2012年1月12实验成绩:29一、 源代码import java.io.*; public class Book implements Serializable/书的基类public String author;/作者public String published;/出版商public String nameOfBook;/书名private int Booknumbers = 200;public Book()public Book(String author,String published,String nameofBook)this.author = author;this.published = published;OfBook = nameofBook;private void writeObject(ObjectOutputStream out) throws IOException out.writeUTF(author);out.writeUTF(published);out.writeUTF(nameOfBook);private void readObject(ObjectInputStream in) throws IOException author=in.readUTF();published=in.readUTF();nameOfBook=in.readUTF();private boolean bool = false;public synchronized void borrowBook()if(bool)trywait();/多线程通信机制catch(InterruptedException e)System.out.println(Book类出现异常);elsebool = false;Booknumbers-;System.out.println(目前图书馆的馆藏图书一共有+Booknumbers+册);notify();/其他的线程被唤醒public synchronized void returnBook()if(bool)trywait();/多线程通信机制catch(InterruptedException e)System.out.println(Book类出现异常);elsebool = true;Booknumbers+;System.out.println(目前图书馆的馆藏图书一共有+Booknumbers+册);notify();/通知其他的线程被唤醒public class BorrowedBookOutOfLimitException extends Exception /借书的数量超过了规定最大的数量抛出的异常public class BorrowThread implements RunnableBook book;public BorrowThread(Book Bo)book = Bo;public void run()trybook.borrowBook();Thread.sleep(10);catch(InterruptedException io)System.out.println(BorrowThread出现异常);import java.awt.*;import java.awt.Event.*; import java.awt.event.MouseEvent;import java.awt.event.MouseListener;public class Button1Handler implements MouseListenerpublic void mouseClicked(MouseEvent e)UserLogin tft = new UserLogin();public void mouseEntered(MouseEvent e)/Picture.lb3.setText(你已经可以进行单击操作。);public void mousePressed(MouseEvent e)/Picture.lb3.setText(你已按下按钮!);public void mouseRelesed(MouseEvent e)Overridepublic void mouseReleased(MouseEvent e) / TODO Auto-generated method stubOverridepublic void mouseExited(MouseEvent e) / TODO Auto-generated method stubimport java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class Button2Handler implements ActionListenerpublic void actionPerformed(ActionEvent e)System.exit(0);import java.awt.*;import java.awt.Event.*; import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.io.IOException;public class Button5Handler implements MouseListenerpublic void mouseClicked(MouseEvent e)MainTest Main = new MainTest();public void mouseEntered(MouseEvent e)/Picture.lb3.setText(你已经可以进行单击操作。);public void mousePressed(MouseEvent e)/Picture.lb3.setText(你已按下按钮!);public void mouseRelesed(MouseEvent e)Overridepublic void mouseReleased(MouseEvent e) / TODO Auto-generated method stubOverridepublic void mouseExited(MouseEvent e) / TODO Auto-generated method stubimport java.awt.event.FocusEvent;import java.awt.event.FocusListener;public class focusHandler implements FocusListenerpublic void focusGainded(FocusEvent e)public void focusLost(FocusEvent e)Object ob = e.getSource();if(ob=UserLogin.txtName);/System.out.println(UserLogin.txtName.getText();if(ob=UserLogin.txtPass)/System.out.println(UserLogin.txtPass.getText();Overridepublic void focusGained(FocusEvent e) / TODO Auto-generated method stubimport java.awt.event.KeyEvent;import java.awt.event.KeyListener;public class keyHandler implements KeyListenerpublic void keyPressed(KeyEvent e)Object ob = e.getSource();if(ob=UserLogin.txtName)&(e.getKeyCode()=10)/System.out.println(UserLogin.txtName.getText();else if(ob=UserLogin.txtName)&(e.getKeyCode()=10)/System.out.println(UserLogin.txtPass.getText();public void keyReleased(KeyEvent e)public void keyTyped(KeyEvent e)import java.io.*;public class Library extends Studentpublic static int nowBooknumber= 0;public String nameOfLibrary = CUIT Library;public static int nowStudentNumber = 0;public Student STUDENT;public Book booK;public Library()STUDENT=new Student30;booK = new Book20;public void AddNewBook() throws IOException,ClassNotFoundExceptionboolean change = true;String tomp1,tomp2,tomp3,tomp5;tomp1 = new String();tomp2 = new String();tomp3 = new String();tomp5 = new String();while(change)+nowBooknumber;System.out.println(请输入加入图书的作者:);try tomp1 = MainTest.initiate2(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();System.out.println(请输入加入图书书名:);try tomp2 = MainTest.initiate2(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();System.out.println(请输入加入图书的出版商:);try tomp3 = MainTest.initiate2(); catch (IOException e) e.printStackTrace();booKnowBooknumber = new Book(tomp1,tomp2,tomp3);MainTest.oos1.writeObject(booKnowBooknumber); System.out.print(请问你还需要继续加入学生吗?1代表继续添加其他代表退出);try tomp5 = MainTest.initiate2(); catch (IOException e) e.printStackTrace();int middle = Integer.parseInt(tomp5.trim();if(middle = 1)change = true;elsechange = false;public Book displayBookInformation() throws IOException, ClassNotFoundExceptionint j = 0;FileInputStream fis = new FileInputStream(C:AddNewBook.txt);ObjectInputStream ois = new ObjectInputStream(fis); trywhile(true)booKj = (Book)ois.readObject();System.out.println(图书名称:+booKj.author+图书出版商:+booKj.published+图书书名:+booKOfBook);+j;catch(Exception e)nowBooknumber = j;if(nowBooknumber=0)System.out.println(你暂时还没有添加图书的相关的信息);return null;return booK;/注:下面这个方法和上面这个方法是一样的,我们只是为了能够在Student类查找的时候能够用得到public Book displayBookInformation1() throws IOException, ClassNotFoundExceptionint j = 0;FileInputStream fis = new FileInputStream(C:AddNewBook.txt);ObjectInputStream ois = new ObjectInputStream(fis); trywhile(true)booKj = (Book)ois.readObject();/System.out.println(图书名称:+booKj.author+图书出版商:+booKj.published+图书书名:+booKOfBook);+j;catch(Exception e)nowBooknumber = j;if(nowBooknumber=0)System.out.println(你暂时还没有添加图书的相关的信息);return null;return booK;public void addNewReader() throws IOException,NotSerializableExceptionboolean change = true;String tomp1,tomp2,tomp3,tomp4,tomp5,number = null;tomp1 = new String();tomp2 = new String();tomp3 = new String();tomp4 = new String();tomp5 = new String();while(change)+nowStudentNumber;System.out.println(请输入加入学生的姓名:);try tomp1 = MainTest.initiate2(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();System.out.println(请输入加入学生的性别:);try tomp2 = MainTest.initiate2(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();System.out.println(请输入加入学生的出生年月:);try tomp3 = MainTest.initiate2(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();System.out.println(请输入加入学生的专业:);try tomp4 = MainTest.initiate2(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();System.out.println(请输入加入学生的学号:);try number = MainTest.initiate2(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();STUDENTnowStudentNumber= new Student(tomp1,tomp2,tomp3,tomp4,number);MainTest.oos2.writeObject(STUDENTnowStudentNumber); System.out.print(请问你还需要继续加入学生吗?1代表继续添加其他代表退出);try tomp5 = MainTest.initiate2(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();int middle = Integer.parseInt(tomp5.trim();if(middle = 1)change = true;elsechange = false;public void displayReaderInformation() throws IOException, ClassNotFoundExceptionint j = 0;FileInputStream fis1 = new FileInputStream(C:AddNewReader.txt);ObjectInputStream ois1 = new ObjectInputStream(fis1);trywhile(true)STUDENTj = (Student)ois1.readObject();System.out.println(学生学号:+STUDENTj.studentNum+学生专业 :+STUDENTj.major+学生姓名 :+STUDENT+学生性别: +STUDENTj.gender+出生日期:+STUDENTj.birthDate);+j;catch(Exception io)nowStudentNumber = j;if(nowStudentNumber=0)System.out.println(你暂时还没有添加读者的相关的信息);return ;public void modifyInformation() throws IOException, ClassNotFoundExceptionboolean change = true,chn = true;String tomp1,tomp2,tomp3,tomp4,tomp5,tomp6,tomp7;tomp1 = new String();tomp2 = new String();tomp3 = new String();tomp4 = new String();tomp5 = new String();tomp6 = new String();tomp7 = new String();while(chn)System.out.print(请输入你要更改的学生的姓名或者学号:);try tomp1 = MainTest.initiate2(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();for(int j=1;j= nowStudentNumber)System.out.println(没有找到该学生的基本信息:);break ;/退出子函数System.out.print(请问你需要继续修改其他的同学的信息:1(确认)Or其他数字(退出):);try tomp7 = MainTest.initiate2(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();int middle5 = Integer.parseInt(tomp7.trim();if(middle5 = 1)chn = true;elsechn = false;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.ObjectOutputStream;public class MainTest public static FileOutputStream fos1;static public ObjectOutputStream oos1;public static FileOutputStream fos2;static public ObjectOutputStream oos2;public static FileOutputStream fos3;static public ObjectOutputStream oos3;public static FileOutputStream fos4;static public ObjectOutputStream oos4;public static void main(String args) throws IOException, InterruptedException, ClassNotFoundExceptionBook oo = new Book();Library Lib = new Library();Student Stu = new Student(Lib);String tmp,tomp5 = null;int middle1;boolean chin = true;File file1 = new File(C:AddNewBook.txt);fos1 = new FileOutputStream(file1,true);if(file1.length() 1)oos1 = new ObjectOutputStream(fos1);elseoos1 = new MyObjectOutputStream(fos1);File file2 = new File(C:AddNewReader.txt);fos2 = new FileOutputStream(file2,true);if(file2.length() 1)oos2 = new ObjectOutputStream(fos2);elseoos2 = new MyObjectOutputStream(fos2);File file3 = new File(C:StudentBorrow.txt);fos3 = new FileOutputStream(file3,true);if(file3.length() 1)oos3 = new ObjectOutputStream(fos3);elseoos3 = new MyObjectOutputStream(fos3);File file4 = new File(C:StudentReturn.txt);fos4 = new FileOutputStream(file4,true);if(file4.length() 1)oos4 = new ObjectOutputStream(fos4);elseoos4 = new MyObjectOutputStream(fos4);while(chin)System.out.println(-欢迎来到+LOfLibrary+of图书管理系统-|);System.out.println(-1:向图书馆里面添加新书的信息-|);System.out.println(-2:向图书馆里面添加读者的信息-|);System.out.println(-3:显示新书的相关的信息-|);System.out.println(-4:显示学生的相关的信息-|);System.out.println(-5:修改学生的相关信息-|);System.out.println(-6:目前学生已经借书的数量(注意:要先借书才可以还书)换行后以结束的借书的情况-|);System.out.println(-7: 目前学生已经还书的数量(注意:要先借书才可以还书)换行后以结束的借书的情况-|);System.out.println(-8: 按照作者来搜索图书-|);System.out.println(-9: 按照来出版商搜索图书-|);System.out.println(-10: 按照书名来搜索图书-|);System.out.print(请根据上述菜单进行自己的选择:);tmp = initiate2();int middle = Integer.parseInt(tmp.trim();switch(middle)case 1:Lib.AddNewBook();break;case 2:Lib.addNewReader();break;case 3:Lib.displayBookInformation();break;case 4:Lib.displayReaderInformation();break;case 5:Lib.modifyInformation();break;case 6: Stu.returnBook();/Lib.STUDENTmiddle2.returnBook();Thread t1 = new Thread(new BorrowThread(oo);t1.start();t1.join();break;case 7:Stu.returnBook();Thread t2 = new Thread(new ReturnThread(oo);t2.start();t2.join();break;case 8:Stu.searchBookByAuthor();break;case 9:Stu.searchBookByPublished();break;case 10:Stu.searchBookByNameOfBook();break;System.out.print(请问你需要继续回到(主界面)进行操作吗?1(确认)Or其他(退出): );tomp5 = initiate2();middle1 = Integer.parseInt(tomp5.trim();if( middle1= 1)chin = true;elsechin = false;oos1.close();oos2.close();oos3.close();oos4.close();public static String initiate2() throws IOException /从键盘读入多位数byte ba = new byte10;int length = System.in.read(ba);/从键盘读入日期,回车结尾String s = new String(ba, 0, length);/构建String对象,回车占两个字节return s; import java.io.*;public class MyObjectOutputStream extends ObjectOutputStream public MyObjectOutputStream()throws IOException super(); public MyObjectOutputStream(OutputStream out) throws IOException super(out); Override protected void writeStreamHeader() throws IOException return;public abstract class PersonString name;/姓名String gender;/性别String birthDate;/出生年月import java.awt.*;import java.awt.Event.*;public class Picture static Frame f = new Frame(成都信息工程学院校园图书馆欢迎您);static Label lb1= new Label(成都信息工程学院已经走过了60个春秋);static Label lb2 = new Label(滋润着一代又一代有理想的年轻人);static Label lb3 = new Label(相信你也会有所收获de);static Button b1 = new Button(进入页面);static Button b2 = new Button(退出登录); import java.io.FileNotFoundException;import java.io.IOException;public interface Reader public abstract void returnBook();/还书public abstract void borrowBook() throws BorrowedBookOutOfLimitException;/借书public abstract void searchBookByAuthor() throws IOException, ClassNotFoundException;/以作者的形式搜索图书public abstract void searchBookByPublished() throws IOException, ClassNotFoundException;/以出版商的形式搜索图书public abstract void searchBookByNameOfBook() throws FileNotFoundException, IOException, ClassNotFoundException;/以书名的形式搜索图书public class ReturnThread implements RunnableBook book;public ReturnThread(Book Bo)book = Bo;public void run()trybook.returnBook();Thread.sleep(10);catch(InterruptedException io)System.out.println(ReturnThread出现异常);import java.io.*;class Student extends Person implements Reader,SerializableString studentNum;/学号String major;/专业int ruturnBooknumber = 0;/还书数量int borrowedBooks = 0;/借书数量int borrowedBookLimit = 10;/借书数量
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 软枣猕猴桃栽培技术分析
- 职业培训讲解
- 中医内科头痛诊疗体系
- 企业档案培训
- 商业综合体室外摊位布局与路灯照明一体化施工合同
- 城市交通枢纽车辆收费员劳动派遣合同
- 《绿色建筑设计与施工监理合同》
- 矿山土地权属变更与资源开采权许可协议
- 柴油发动机改装服务合同范本
- 餐饮企业商铺租赁及品牌拓展合同
- (2025)《公共基础知识》试真题库与答案
- 江西省南昌市第一中学教育集团2023-2024学年八年级下学期数学期末试卷(含答案)
- 2025盘锦市双台子区辅警考试试卷真题
- 教研员考试题库及答案
- 地生中考模拟试题及答案
- 慢性病管理中心建设实施方案
- T/CCMA 0163-2023履带式液压挖掘机维修工时定额
- 2025年下半年山西焦煤西山煤电集团公司招聘270人易考易错模拟试题(共500题)试卷后附参考答案
- 小红书《家的一平米》招商方案
- 2025年二十大党章试题库
- 尺骨骨折护理课件
评论
0/150
提交评论