Java图书图书管理系统报告.docx

上传人:b****7 文档编号:16375841 上传时间:2023-07-13 格式:DOCX 页数:39 大小:24.46KB
下载 相关 举报
Java图书图书管理系统报告.docx_第1页
第1页 / 共39页
Java图书图书管理系统报告.docx_第2页
第2页 / 共39页
Java图书图书管理系统报告.docx_第3页
第3页 / 共39页
Java图书图书管理系统报告.docx_第4页
第4页 / 共39页
Java图书图书管理系统报告.docx_第5页
第5页 / 共39页
Java图书图书管理系统报告.docx_第6页
第6页 / 共39页
Java图书图书管理系统报告.docx_第7页
第7页 / 共39页
Java图书图书管理系统报告.docx_第8页
第8页 / 共39页
Java图书图书管理系统报告.docx_第9页
第9页 / 共39页
Java图书图书管理系统报告.docx_第10页
第10页 / 共39页
Java图书图书管理系统报告.docx_第11页
第11页 / 共39页
Java图书图书管理系统报告.docx_第12页
第12页 / 共39页
Java图书图书管理系统报告.docx_第13页
第13页 / 共39页
Java图书图书管理系统报告.docx_第14页
第14页 / 共39页
Java图书图书管理系统报告.docx_第15页
第15页 / 共39页
Java图书图书管理系统报告.docx_第16页
第16页 / 共39页
Java图书图书管理系统报告.docx_第17页
第17页 / 共39页
Java图书图书管理系统报告.docx_第18页
第18页 / 共39页
Java图书图书管理系统报告.docx_第19页
第19页 / 共39页
Java图书图书管理系统报告.docx_第20页
第20页 / 共39页
亲,该文档总共39页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

Java图书图书管理系统报告.docx

《Java图书图书管理系统报告.docx》由会员分享,可在线阅读,更多相关《Java图书图书管理系统报告.docx(39页珍藏版)》请在冰点文库上搜索。

Java图书图书管理系统报告.docx

Java图书图书管理系统报告

成都信息工程学院

计算机学院

课程实验报告

实验课程:

Java程序设计

实验项目:

图书管理系统

指导教师:

汤蓉

学生姓名:

向浩

学生学号:

2011051020

班级:

计科111班

实验地点:

6306

上交时间:

2012年1月12

实验成绩:

一、源代码

importjava.io.*;

publicclassBookimplementsSerializable{//书的基类

publicStringauthor;//作者

publicStringpublished;//出版商

publicStringnameOfBook;//书名

privateintBooknumbers=200;

publicBook(){}

publicBook(Stringauthor,Stringpublished,StringnameofBook){

this.author=author;

this.published=published;

this.nameOfBook=nameofBook;

}

privatevoidwriteObject(ObjectOutputStreamout)throwsIOException{

out.writeUTF(author);

out.writeUTF(published);

out.writeUTF(nameOfBook);

}

privatevoidreadObject(ObjectInputStreamin)throwsIOException{

author=in.readUTF();

published=in.readUTF();

nameOfBook=in.readUTF();

}

privatebooleanbool=false;

publicsynchronizedvoidborrowBook(){

if(bool){

try{

wait();//多线程通信机制

}catch(InterruptedExceptione){

System.out.println("Book类出现异常");

}

}

else{

bool=false;

Booknumbers--;

System.out.println("目前图书馆的馆藏图书一共有"+Booknumbers+"册");

notify();//其他的线程被唤醒

}

}

publicsynchronizedvoidreturnBook(){

if(bool)

{

try{

wait();//多线程通信机制

}catch(InterruptedExceptione){

System.out.println("Book类出现异常");

}

}

else{

bool=true;

Booknumbers++;

System.out.println("目前图书馆的馆藏图书一共有"+Booknumbers+"册");

notify();//通知其他的线程被唤醒

}

}

}

publicclassBorrowedBookOutOfLimitExceptionextendsException{

}//借书的数量超过了规定最大的数量抛出的异常

publicclassBorrowThreadimplementsRunnable{

Bookbook;

publicBorrowThread(BookBo){

book=Bo;

}

publicvoidrun(){

try{

book.borrowBook();

Thread.sleep(10);

}catch(InterruptedExceptionio){

System.out.println("BorrowThread出现异常");

}

}

}

importjava.awt.*;

importjava.awt.Event.*;

importjava.awt.event.MouseEvent;

importjava.awt.event.MouseListener;

publicclassButton1HandlerimplementsMouseListener{

publicvoidmouseClicked(MouseEvente)

{

UserLogintft=newUserLogin();

}

publicvoidmouseEntered(MouseEvente)

{

//Picture.lb3.setText("你已经可以进行单击操作。

");

}

publicvoidmousePressed(MouseEvente)

{

//Picture.lb3.setText("你已按下按钮!

");

}

publicvoidmouseRelesed(MouseEvente)

{

}

@Override

publicvoidmouseReleased(MouseEvente){

//TODOAuto-generatedmethodstub

}

@Override

publicvoidmouseExited(MouseEvente){

//TODOAuto-generatedmethodstub

}

}

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

publicclassButton2HandlerimplementsActionListener{

publicvoidactionPerformed(ActionEvente)

{

System.exit(0);

}

}

importjava.awt.*;

importjava.awt.Event.*;

importjava.awt.event.MouseEvent;

importjava.awt.event.MouseListener;

importjava.io.IOException;

publicclassButton5HandlerimplementsMouseListener{

publicvoidmouseClicked(MouseEvente)

{

MainTestMain=newMainTest();

}

publicvoidmouseEntered(MouseEvente)

{

//Picture.lb3.setText("你已经可以进行单击操作。

");

}

publicvoidmousePressed(MouseEvente)

{

//Picture.lb3.setText("你已按下按钮!

");

}

publicvoidmouseRelesed(MouseEvente)

{

}

@Override

publicvoidmouseReleased(MouseEvente){

//TODOAuto-generatedmethodstub

}

@Override

publicvoidmouseExited(MouseEvente){

//TODOAuto-generatedmethodstub

}

}

importjava.awt.event.FocusEvent;

importjava.awt.event.FocusListener;

publicclassfocusHandlerimplementsFocusListener{

publicvoidfocusGainded(FocusEvente)

{

}

publicvoidfocusLost(FocusEvente)

{

Objectob=e.getSource();

if(ob==UserLogin.txtName);

{

//System.out.println(UserLogin.txtName.getText());

}

if(ob==UserLogin.txtPass)

{

//System.out.println(UserLogin.txtPass.getText());

}

}

@Override

publicvoidfocusGained(FocusEvente){

//TODOAuto-generatedmethodstub

}

}

importjava.awt.event.KeyEvent;

importjava.awt.event.KeyListener;

publicclasskeyHandlerimplementsKeyListener{

publicvoidkeyPressed(KeyEvente)

{

Objectob=e.getSource();

if((ob==UserLogin.txtName)&&(e.getKeyCode()==10))

{

//System.out.println(UserLogin.txtName.getText());

}

elseif((ob==UserLogin.txtName)&&(e.getKeyCode()==10))

{

//System.out.println(UserLogin.txtPass.getText());

}

}

publicvoidkeyReleased(KeyEvente)

{

}

publicvoidkeyTyped(KeyEvente)

{

}

}

importjava.io.*;

publicclassLibraryextendsStudent

{

publicstaticintnowBooknumber=0;

publicStringnameOfLibrary="CUITLibrary";

publicstaticintnowStudentNumber=0;

publicStudent[]STUDENT;

publicBookbooK[];

publicLibrary()

{

STUDENT=newStudent[30];

booK=newBook[20];

}

publicvoidAddNewBook()throwsIOException,ClassNotFoundException

{

booleanchange=true;

Stringtomp1,tomp2,tomp3,tomp5;

tomp1=newString();

tomp2=newString();

tomp3=newString();

tomp5=newString();

while(change){

++nowBooknumber;

System.out.println("请输入加入图书的作者:

");

try{

tomp1=MainTest.initiate2();

}catch(IOExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

System.out.println("请输入加入图书书名:

");

try{

tomp2=MainTest.initiate2();

}catch(IOExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

System.out.println("请输入加入图书的出版商:

");

try{

tomp3=MainTest.initiate2();

}catch(IOExceptione){

e.printStackTrace();

}

booK[nowBooknumber]=newBook(tomp1,tomp2,tomp3);

MainTest.oos1.writeObject(booK[nowBooknumber]);

System.out.print("请问你还需要继续加入学生吗?

1代表继续添加其他代表退出");

try{

tomp5=MainTest.initiate2();

}catch(IOExceptione){

e.printStackTrace();

}

intmiddle=Integer.parseInt(tomp5.trim());

if(middle==1)

{

change=true;

}

else

{

change=false;

}

}

}

publicBook[]displayBookInformation()throwsIOException,ClassNotFoundException

{

intj=0;

FileInputStreamfis=newFileInputStream("C:

\\AddNewBook.txt");

ObjectInputStreamois=newObjectInputStream(fis);

try

{

while(true)

{

booK[j]=(Book)ois.readObject();

System.out.println("图书名称:

"+booK[j].author+"图书出版商:

"+booK[j].published+"图书书名:

"+booK[j].nameOfBook);

++j;

}

}catch(Exceptione)

{

}

nowBooknumber=j;

if(nowBooknumber<=0)

{

System.out.println("你暂时还没有添加图书的相关的信息");

returnnull;

}

returnbooK;

}

//注:

下面这个方法和上面这个方法是一样的,我们只是为了能够在Student类查找的时候能够用得到

publicBook[]displayBookInformation1()throwsIOException,ClassNotFoundException

{

intj=0;

FileInputStreamfis=newFileInputStream("C:

\\AddNewBook.txt");

ObjectInputStreamois=newObjectInputStream(fis);

try

{

while(true)

{

booK[j]=(Book)ois.readObject();

//System.out.println("图书名称:

"+booK[j].author+"图书出版商:

"+booK[j].published+"图书书名:

"+booK[j].nameOfBook);

++j;

}

}catch(Exceptione)

{

}

nowBooknumber=j;

if(nowBooknumber<=0)

{

System.out.println("你暂时还没有添加图书的相关的信息");

returnnull;

}

returnbooK;

}

publicvoidaddNewReader()throwsIOException,NotSerializableException

{

booleanchange=true;

Stringtomp1,tomp2,tomp3,tomp4,tomp5,number=null;

tomp1=newString();

tomp2=newString();

tomp3=newString();

tomp4=newString();

tomp5=newString();

while(change){

++nowStudentNumber;

System.out.println("请输入加入学生的姓名:

");

try{

tomp1=MainTest.initiate2();

}catch(IOExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

System.out.println("请输入加入学生的性别:

");

try{

tomp2=MainTest.initiate2();

}catch(IOExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

System.out.println("请输入加入学生的出生年月:

");

try{

tomp3=MainTest.initiate2();

}catch(IOExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

System.out.println("请输入加入学生的专业:

");

try{

tomp4=MainTest.initiate2();

}catch(IOExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

System.out.println("请输入加入学生的学号:

");

try{

number=MainTest.initiate2();

}catch(IOExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

STUDENT[nowStudentNumber]=newStudent(tomp1,tomp2,tomp3,tomp4,number);

MainTest.oos2.writeObject(STUDENT[nowStudentNumber]);

System.out.print("请问你还需要继续加入学生吗?

1代表继续添加其他代表退出");

try{

tomp5=MainTest.initiate2();

}catch(IOExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

intmiddle=Integer.parseInt(tomp5.trim());

if(middle==1)

{

change=true;

}

else

{

change=false;

}

}

}

publicvoiddisplayReaderInformation()throwsIOException,ClassNotFoundException

{

intj=0;

FileInputStreamfis1=newFileInputStream("C:

\\AddNewReader.txt");

ObjectInputStreamois1=newObjectInputStream(fis1);

try{

while(true)

{

STUDENT[j]=(Student)ois1.readObject();

System.out.println("学生学号:

"+STUDENT[j].studentNum+"学生专业:

"+STUDENT[j].major+"学生姓名:

"+STUDENT[j].name+"学生性别:

"+STUDENT[j].gender+"出生日期:

"+STUDENT[j].birthDate);

++j;

}

}catch(Exceptionio)

{

}

nowStudentNumber=j;

if(nowStudentNumber<=0)

{

System.out.println("你暂时还没有添加读者的相关的信息");

return;

}

}

publicvoidmodifyInformation()throwsIOException,ClassNotFoundException

{

booleanchange=true,chn=true;

Stringtomp1,tomp2,tomp3,tomp4,tomp5,tomp6,tomp7;

tomp1=newString();

tomp2=newString();

tomp3=newString();

tomp4=newString();

tomp5=newStrin

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2