Java图书图书管理系统报告_第1页
Java图书图书管理系统报告_第2页
Java图书图书管理系统报告_第3页
Java图书图书管理系统报告_第4页
Java图书图书管理系统报告_第5页
已阅读5页,还剩34页未读 继续免费阅读

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、成都信息工程学院计算机学院课程实验报实验课程:Java程序设计实验项目:图书管理系统指导教师:汤蓉学生姓名:向浩学生学号:2011051020班级:计科111班实验地点:6306上交时间:2012 年 1 月 12实验成绩:源代码import java.io.*;public class Book impiements Serializable/ 书的基类public String author;/ 作者public String published;/ 出版商public String nameOfBook;/ 书名p rivate int Book nu mbers = 200;p ubl

2、ic Book()p ublic Book(Stri ng author,Stri ng p ublished,Stri ng n ameofBook) this.author = author;this .p ublished = p ublished;this .n ameOfBook = n ameofBook;p rivate void writeObject(ObjectOut putStream out) throws IOExce pti on out.writeUTF(author);out.writeUTF (p ublished);out.writeUTF( nameOfB

3、ook);p rivate void readObject(Object Inpu tStream in) throws IOExce pti on author =in. readUTF();p ublished=in. readUTF();n ameOfBook=i n.readUTF();p rivate boolea n bool = false;P ublic synchroni zed void borrowBook()if(bool)trywait();/多线程通信机制catch(I nterrup tedExce pti on e)System.out.println(Book

4、 类出现异常);elsebool = false;Book nu mbers-;System.out.println(”目前图书馆的馆藏图书一共有+Booknumbers+册);notify。;/其他的线程被唤醒p ublic synchroni zed void retur nBook() if(bool)trywait();/多线程通信机制catch(I nterrup tedExce pti on e)System.out.println(Book 类出现异常);elsebool = true;Book nu mbers+;System.out.println(”目前图书馆的馆藏图书一共

5、有+Booknumbers+册);notify。;/通知其他的线程被唤醒p ublic class BorrowedBookOutOfLimitExce ptio n exte nds Exce ptio n 借书的数量超过了规定最大的数量抛出的异常 p ublic class BorrowThread impi eme nts Runn ableBook book;p ublic BorrowThread(Book Bo)book = Bo;p ublic void run()trybook.borrowBook();Thread.slee p(10);catch(I nterrup ted

6、Exce pti on io)System.out.printin(BorrowThread 出现异常);import java.awt.*;import java.awt.Eve nt.*;import java.awt.eve nt.MouseEve nt;import java.awt.eve nt.MouseListe ner;P ublic class Butt on 1Ha ndler imp leme nts MouseListe ner p ublic void mouseClicked(MouseEve nt e) UserLogi n tft = new UserLogi

7、n();/p ublic void mouseE ntered(MouseEve nt e)Picture.lb3.setText(”你已经可以进行单击操作。P ublic void mouse Pressed(MouseEve nt e)Picture.lb3.setText(” 你已按下按钮!);p ublic void mouseRelesed(MouseEve nt e)。);Overridep ublic void mouseReleased(MouseEve nt e) / TODO Auto-ge nerated method stubOverridep ublic void m

8、ouseExited(MouseEve nt e) / TODO Auto-ge nerated method stubimport java.awt.eve nt.Act ionEvent;import java.awt.eve nt.Act ion Liste ner;p ublic class Butt on 2Ha ndler imp leme nts Actio nListe ner p ublic void actio nP erformed(Actio nEvent e)System.exit(O);import java.awt.*;import java.awt.Eve nt

9、.*;import java.awt.eve nt.MouseEve nt;import java.awt.eve nt.MouseListe ner;import java.io.IOExce ptio n;p ublic class Butt on 5Ha ndler imp leme nts MouseListe ner p ublic void mouseClicked(MouseEve nt e) Mai nTest Main = new Mai nTest();/p ublic void mouseE ntered(MouseEve nt e)Picture.lb3.setText

10、(”你已经可以进行单击操作。P ublic void mouse Pressed(MouseEve nt e)Picture.lb3.setText(” 你已按下按钮!);p ublic void mouseRelesed(MouseEve nt e)。);Overridep ublic void mouseReleased(MouseEve nt e) / TODO Auto-ge nerated method stubOverridep ublic void mouseExited(MouseEve nt e) / TODO Auto-ge nerated method stubimpor

11、t java.awt.eve nt.FocusEve nt;import java.awt.eve nt.FocusListe ner;p ublic class focusHa ndler imp leme nts FocusListe nerp ublic void focusGa in ded(FocusEve nt e)p ublic void focusLost(FocusEve nt e)Object ob = e.getSource(); if(ob=UserLogi n. txtName);/System.out. println( UserLogi n. txtName.ge

12、tText();if(ob=UserLogi n.txtP ass)System.out. println( UserLogi n.txtP ass.getText();Overridep ublic void focusGa in ed(FocusEve nt e) / TODO Auto-ge nerated method stubimport java.awt.eve nt.KeyEve nt;import java.awt.eve nt.KeyListe ner;p ublic class keyHa ndler impi eme nts KeyListe nerp ublic voi

13、d keyP ressed(KeyEve nt e)Object ob = e.getSource();if(ob=UserLogi n. txtName )&(e.getKeyCode()=10)/System.out. println( UserLogi n. txtName.getText();else if(ob=UserLogi n. txtName )&(e.getKeyCode()=10)/System.out. println( UserLogi n.txtP ass.getText();p ublic void keyReleased(KeyEve nt e)p ublic

14、void keyT yp ed(KeyEve nt e)import java.io.*;p ublic class Library exte nds Stude ntp ublic static int no wBook nu mber= 0;p ublic Stri ng nameOfLibrary = CUIT Library;p ublic static int no wStude ntNumber = 0;p ublic Stude nt STUDENT;p ublic Book booK;p ublic Library()STUDENT=new Stude nt30;booK =

15、new Book20;p ublic void AddNewBook() throws IOExce pti on ,ClassNotF oun dExce pti onboolea n cha nge = true;String tomp 1,to mp 2,to mp 3,to mp5;tomp1 = new Stri ng();tomp2 = new Stri ng();tomp3 = new Stri ng();tomp5 = new Stri ng();while(cha nge)+no wBook nu mber;System.out.println(”请输入加入图书的作者:”);

16、try tomp1 = Mai nTest.i ni tiate2(); catch (IOExce pti on e) / TODO Auto-ge nerated catch blocke.prin tStackTrace();System.out.println(”请输入加入图书书名:”);try tomp2 = Mai nTest.i ni tiate2(); catch (IOExce pti on e) / TODO Auto-ge nerated catch blocke.prin tStackTrace();System.out.println(”请输入加入图书的出版商:”);

17、try tomp3 = Mai nTest.i ni tiate2(); catch (IOExce pti on e) e.prin tStackTrace();booK no wBook nu mber = new Book(to mp 1,to mp 2,to mp 3);Main Test.oos1.writeObject(booK no wBook nu mber);System.out.print(请问你还需要继续加入学生吗?1代表继续添加其他代表退出”);try tomp5 = Main Test.i nitiate2(); catch (lOExce pti on e) e.p

18、rin tStackTrace();int middle = In teger. parse In t(to mp 5.trim(); if(middle = 1)cha nge = true;elsecha nge = false;p ublic Book dis playBook In formatio n() throws IOExce pti on, ClassNotF oun dExce pti on int j = 0;FileI npu tStream fis = new FileI np utStream(C:AddNewBook.txt); Object Inpu tStre

19、am ois = new Object Inpu tStream(fis);trywhile(true)booKj = (Book)ois.readObject();System.out.printin(” 图书名称:+booKj.author+ +booKj.published+图书书名:+booKOfBook);+j;catch(Exce pti on e)图书出版商:no wBook nu mber = j;if(no wBook nu mber=0)System.out.println(”你暂时还没有添加图书的相关的信息 return n ull;return booK;注

20、:下面这个方法和上面这个方法是一样的,我们只是为了能够在 找的时候能够用得到”);Student 类查public Book ClassNotF oun dExce ptio ndis playBook In formatio n1()throwsIOExce pti j = 0;Filel np utStream fis = new File Inp utStream(C:AddNewBook.txt); ObjectI np utStream ois = new ObjectI npu tStream(fis);trywhile(true)/booKj = (Book)ois

21、.readObject();System.out.printin(” 图书名称:+booK|j.author+图书出版商:+booKj.published+图书书名:+booKOfBook);+j;catch(Exce pti on e) no wBook nu mber = j;if(no wBook nu mber=0)System.out. printin(你暂时还没有添加图书的相关的信息 ); return n ull;return booK;p ublic void addNewReader() throws lOExce pti on,N otSerializableE

22、xce pti on boolea n cha nge = true;String tomp 1,to mp 2,to mp 3,to mp 4,to mp5,nu mber = nu II; tompl = new Stri ng();tomp2 = new Stri ng();tomp3 = new Stri ng();tomp4 = new Stri ng();tomp5 = new Stri ng();while(cha nge)+no wStude ntNumber;”);System.out.println(”请输入加入学生的姓名:try tompl = Mai nTest.i n

23、i tiate2(); catch (lOExce pti on e) / TODO Auto-ge nerated catch blocke.prin tStackTrace();System.out.println(”请输入加入学生的性别:”);try tomp# = Mai nTest.i ni tiate2(); catch (IOExce pti on e) / TODO Auto-ge nerated catch blocke.prin tStackTrace(););System.out.println(”请输入加入学生的出生年月:try tomp3 = Mai nTest.i

24、ni tiate2(); catch (IOExce pti on e) / TODO Auto-ge nerated catch blocke.prin tStackTrace();”);System.out.println(”请输入加入学生的专业:try tomp4 = Mai nTest. in itiate2(); catch (IOExce pti on e) / TODO Auto-ge nerated catch blocke.prin tStackTrace();”);System.out.println(”请输入加入学生的学号:try nu mber = Main Test.

25、 in itiate2(); catch (IOExce pti on e) / TODO Auto-ge nerated catch blocke.prin tStackTrace();newSTUDENT n owStude ntNumber=Stude nt(to mp 1,to mp 2,to mp 3,to mp4,nu mber);Mai nTest.oos2.writeObject(STUDENT no wStude ntNumber);System.out.print(请问你还需要继续加入学生吗?1代表继续添加其他代表退出);try tomp5 = Main Test.i ni

26、tiate2(); catch (lOExce pti on e) / TODO Auto-ge nerated catch block e.prin tStackTrace();int middle = In teger. parse In t(to mp 5.trim(); if(middle = 1)cha nge = true;elseCha nge = false;P ublic void dis playReaderl nformatio n() throws IOExce ptio n, ClassNotF oun dExce ptio nint j = 0;FileI np u

27、tStream fis1 = new FileI np utStream(C:AddNewReader.txt);Object Inpu tStream ois1 = new Object Inpu tStream(fis1);trywhile(true)STUDENTS = (Stude nt)ois1.readObject();System.out.println(” 学生学号: +STUDENTj.studentNum+学生专 业 :+STUDENTj.major+ 学生姓名 :+STUDENT+ 学生性另U : +STUDENTj.ge nder+出生日期:+STUDENT

28、j.birthDate);+j;catch(Exce pti on io) no wStude ntNumber = j;if(no wStude ntNumber=0) System.out. printin(你暂时还没有添加读者的相关的信息);return ;p ublic void modifyI nformatio n() throws IOExce ptio n, ClassNotF oun dExce ptio n boolea n cha nge = true,ch n = true;String tomp 1,to mp 2,to mp 3,to mp 4,to mp 5,to

29、 mp 6,to mp7;tomp1 = new Stri ng();tomp2 = new Stri ng();tomp3 = new Stri ng();tomp4 = new Stri ng();tomp5 = new Stri ng();tomp6 = new Stri ng();tomp7 = new Stri ng();while(ch n)System.out .print(请输入你要更改的学生的姓名或者学号:”);try tomp1 = Mai nTest.i ni tiate2(); catch (IOExce pti on e) / TODO Auto-ge nerated

30、 catch blocke.prin tStackTrace();for(i nt j=1;j= no wStude ntNumber)”);1(确认)0r其他System.out.println(”没有找到该学生的基本信息: break ;/退出子函数System.out.print(请问你需要继续修改其他的同学的信息: 数字(退出):”);try tomp7 = Main Test.i nitiate2(); catch (lOExce pti on e) / TODO Auto-ge nerated catch block e.prin tStackTrace();int middle5

31、 = In teger. parse In t(to mp 7.trim(); if(middle5 = 1)chn = true;elsechn = false;import java.io.File;import java.io.FileOut putStream;import java.io.IOExce ptio n;import java.io.ObjectOut putStream;p ublic class Main Test oos1;oos2;oos3;oos4;args) throws lOExce ptio n. In terr up tedExce pti on.p u

32、blic static FileOut putStream fos1; static p ublic ObjectOut putStream p ublic static FileOut putStream fos2; static p ublic ObjectOut putStream p ublic static FileOut putStream fos3; static p ublic ObjectOut putStream p ublic static FileOut putStream fos4; static p ublic ObjectOut pu tStream public

33、 static void main(String ClassNotF oun dExce ptio nBook oo = new Book(); Library Lib = new Library(); Stude nt Stu = new Stude nt(Lib); Stri ng tmp, to mp5 = n ull; int middle1;boolea n chi n = true;File file1 = new File(C:AddNewBook.txt); fos1 = new FileOut pu tStream(file1,true); if(file1.le ngth(

34、) 1) oos1 = new ObjectOut pu tStream(fos1); else oos1 = new MyObjectOut pu tStream(fos1);File file2 = new File(C:AddNewReader.txt); fos2 = new FileOut putStream(file2,true); if(file2.le ngth() 1)oos2 = new ObjectOut pu tStream(fos2); else oos2 = new MyObjectOut pu tStream(fos2);File file3 = new File

35、(C:Stude ntBorrow.txt); fos3 = new FileOut putStream(file3,true); if(file3.le ngth() 1)oos3 = new ObjectOut pu tStream(fos3);elseoos3 = new MyObjectOut putStream(fos3); File file4 = new File(C:Stude ntReturn.txt); fos4 = new FileOut putStream(file4,true); if(file4.le ngth() 1)oos4 = new ObjectOut pu

36、tStream(fos4);elseoos4 = new MyObjectOut putStream(fos4);while(chi n)System.out. prin tl n(”欢迎来到+LOfLibrary+of图书管理系统1 :向图书馆里面添加新书的信息I);:向图书馆里面添加读者的信息|);:显示新书的相关的信息 1);:显示学生的相关的信息 1);:修改学生的相关信息 1);:目前学生已经借书的数量(注意:要先借书才T);7:目前学生已经还书的数量(注意:要先借书才 1);8:按照作者来搜索图书9:按照来出版商搜索图书10:按照书名来搜索图书l);System.ou

37、t .prin tl n(System.out.println(”2System.out.println(”3System.out.printing4System.out.printing5System.out.printing6可以还书)换行后以结束的借书的情况System.out.printing-可以还书)换行后以结束的借书的情况System.out.printin(”8: 按照作者来搜索图书1);System.out.printin(”9: 按照来出版商搜索图书 1);System.out.printing10: 按照书名来搜索图书 1);System.out.print(请根据上述菜

38、单进行自己的选择:);tmp = in itiate2();int middle = In teger. parsel nt(t mp .trim(); switch(middle)case 1:Lib.AddNewBook();break;case 2:Lib.addNewReader();break;case 3:Lib.dis pl ayBook In formati on( );break;case 4:Lib.dis pl ayReaderI nformati on( );break;case 5:Lib.modify In formati on( );break;case 6:St

39、u.returnBook();/Lib.STUDENTmiddle2.returnBook();Thread t1 = new Thread( new BorrowThread(oo); t1.start();t1.jo in( );break;case 7:Stu.returnBook();Thread t2 = new Thread( new Retur nThread(oo);t2.start();t2.jo in( );break;case 8:Stu.searchBookByAuthor();break;case 9:Stu.searchBookBy Published();brea

40、k;case 10:Stu.searchBookByNameOfBook();break;1(确认)0rSystem.out. print(请问你需要继续回到(主界面)进行操作吗? 其他(退出):);tomp5 = in itiate2();middlel = In teger. parse In t(to mp 5.trim();if( middle1= 1)chi n = true;elsechi n = false;oos1.close();oos2.close();oos3.close();oos4.close();P ublic static String in itiate2()

41、throws lOExce ptio n 从键盘读入多位数II从键盘读入日期,回车结尾byte ba = new byte10;int len gth = System.i n. read(ba);String s = new String(ba, 0, length);构建 String 对象,回车占两个字节return s;import java.io.*;p ublic class MyObjectOut pu tStream exte nds ObjectOut pu tStream p ublic MyObjectOut pu tStream()throws IOExce ption

42、 sup er();p ublic MyObjectOut pu tStream(Out pu tStream out) throws IOExce pti on sup er(out); Overridep rotected void writeStreamHeader() throws IOExce pti on return;p ublic abstract class PersonStri ng n ame;/ 姓名Stri ng gen der;/ 性别String birthDate;/ 出生年月import java.awt.*;import java.awt.Eve nt.*;

43、p ublic 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.File

44、NotF oun dExce ptio n;import java.io.IOExce ptio n;p ublic in terface Readerpublic abstract void returnBook();/ 还书p ublic abstract void borrowBook() throws BorrowedBookOutOfLimitExce ptio n;/借书p ublic abstract void searchBookByAuthor() throwsIOExce pti on,ClassNotFoundException;/以作者的形式搜索图书p ublic ab

45、stract voidsearchBookB yP ublished()throwsIOExce pti on,ClassNotFoundException;/以出版商的形式搜索图书public abstract void searchBookByNameOfBook() throws FileNotFoundException, IOException, ClassNotFoundException;/ 以书名的形式搜索图书p ublic class Retur nThread impI eme nts Runn ableBook book;p ublic ReturnThread(Book

46、 Bo)book = Bo;p ublic void run()trybook.retur nBook();Thread.slee p(10);catch(I nterrup tedExce pti on io)System.out.println(ReturnThread 出现异常);import java.io.*;class Stude nt exte nds Person impi eme nts ReaderSerializable String studentNum;/ 学号String major;/ 专业int ruturnBooknumber = 0;/ 还书数量int bo

47、rrowedBooks = 0;/ 借书数量int borrowedBookLimit = 10;/ 借书数量限制int NowStude ntsNumber = 200;float Money =15;Library Lib;int i = 1;p ublic Stude nt()stude ntNum = 0;major = no Major;n ame = no Name;gen der = noGen der; birthDate = n oBirthDate;p ublic Stude nt(Stri ng stude ntNum,Stri ng major,Stri ng n am

48、e,Stri ng gen der,Stri ng birthDate)this.stude ntNum = stude ntNum;this.major = major;this. name = n ame;this.ge nder = gen der; this.birthDate = birthDate;p rivate void writeObject(ObjectOut pu tStream out) throws lOExce pti on out.writeUTF(stude ntNum);out.writeUTF(major);out.writeUTF (n ame);out.writeUTF(ge nder);out.writeUTF(birthDate);p rivate void readObject(Object Inpu tStream in) throws IOExce pti on stude ntNu m=in. readUTF();major=i n.readUTF();n ame=i n.readUTF();gen der= in. readUTF();birthDate=i n.readUTF();

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论