Java图书管理系统设计报告

上传人:无*** 文档编号:80200742 上传时间:2022-04-25 格式:DOC 页数:29 大小:262KB
返回 下载 相关 举报
Java图书管理系统设计报告_第1页
第1页 / 共29页
Java图书管理系统设计报告_第2页
第2页 / 共29页
Java图书管理系统设计报告_第3页
第3页 / 共29页
点击查看更多>>
资源描述
成都信息工程学院计算机学院课 程 实 验 报 告实验课程: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;this.nameOfBook = 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+图书书名:+booKj.nameOfBook);+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+图书书名:+booKj.nameOfBook);+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+学生姓名 :+STUDENTj.name+学生性别: +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(-欢迎来到+Lib.nameOfLibrary+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;/借书数量限制int NowStudentsNumber = 200;float Money =15;Library Lib;int i = 1;public Student()studentNum = 0;major = noMajor;name = noName;gender = noGender;birthDate = noBirthDate;public Student(String studentNum,String major,String name,String gender,String birthDate)this.studentNum = studentNum;this.major = major;this.name = name;this.gender = gender;this.birthDate = birthDate;private void writeObject(ObjectOutputStream out) throws IOException out.writeUTF(studentNum);out.writeUTF(major);out.writeUTF(name);out.writeUTF(gender);out.writeUTF(birthDate);private void readObject(ObjectInputStream in) throws IOException studentNum=in.readUTF();major=in.readUTF();name=in.readUTF();gender=in.readUTF();birthDate=in.readUTF();public Student(Library lib)this();/调用当前类的其他无参构造函数this.Lib = lib;public void returnBook()byte buffer = new byte128;String tomp5 = null;boolean tmp = true;while(tmp)System.out.println(请输入学生的学生信息:以空格 隔开);System.out.println(学生姓名 学号 班级 :);tryFileOutputStream f = new FileOutputStream(C:StudentReturn.txt);while(true)int n = System.in.read(buffer);if(buffer0=)break;f.write(buffer,0,n);f.write(n);f.close();System.out.println(已经保存你的还书情况!);catch(IOException io)System.out.println(io.toString();ruturnBooknumber+=1;System.out.println(你目前为止已经借了+ruturnBooknumber);System.out.print(请问你是否还需要继续还书吗?:1(确认)Or其他(退出);try tomp5 = MainTest.initiate2(); catch (IOException e) / TODO Auto-generated catch blocke.printStackTrace();int middle4 = Integer.pa
展开阅读全文
相关资源
相关搜索

最新文档


当前位置:首页 > 办公文档


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!