Java实验报告之图书管理系统.docx
- 文档编号:6085222
- 上传时间:2023-01-03
- 格式:DOCX
- 页数:16
- 大小:18.17KB
Java实验报告之图书管理系统.docx
《Java实验报告之图书管理系统.docx》由会员分享,可在线阅读,更多相关《Java实验报告之图书管理系统.docx(16页珍藏版)》请在冰豆网上搜索。
Java实验报告之图书管理系统
Java实验报告
图书管理系统
1.管理员界面
<<密码验证
<<展示所有图书
<<查找图书
<<添加书籍
<<删除书籍
<<修改密码
<<返回上一层
<<结束
2.学生界面
<<身份识别
<<查找图书
<<借阅图书
<<归还书籍
<<返回上一层
<<结束
3.退出程序
源代码:
Main.java
packagepany;
importjava.util.Date;
importjava.util.Scanner;
publicclassMain{
publicstaticvoidmain(String[]args){
//writeyourcodehere
UserU;
LibraryL=newLibrary("东北大学图书馆");
System.out.println("欢迎来到东北大学图书馆");
Bookb1=newBook("java编程思想","sdhf","554532",newDate(2016,12,13),15);
Bookb2=newBook("C++编程","nimei","15654",newDate(2017,5,13),5);
Studentss1=newUndergraduate("黎明","20175821");
Studentss2=newMaster("狭隘","20164545");
b1.BookUser.add(s2);
b1.BookUser.add(s1);
b2.BookUser.add(s2);
b2.BookUser.add(s1);
L.addBook(b1);
L.addBook(b2);
//在以上的代码中都是为了增加图书馆中的藏书
Scannersc=newScanner(System.in);
Stringorder;
//命令操作板
while(true){
System.out.println("命令操作符\n< System.out.print("<<"); order=sc.next(); if(order.equals("AccessADInterface")){ AdministratorsA=newAdministrators(); if(A.getPassWord()==1){ while(true){ System.out.println("命令操作符\n< System.out.print("<<"); order=sc.next(); if(order.equals("ShowAllBook")){ L.ShowBook(); }elseif(order.equals("SearchBook")){ L.ShowBook(L.SearchBook()); }elseif(order.equals("AddBook")){ L.addBook(); }elseif(order.equals("DeleteBook")){ L.DeleteBook(); }elseif(order.equals("ChangePassWord")){ A.changePassWord(); }elseif(order.equals("GoBack")){ break; }elseif(order.equals("over")){ System.out.println("已退出图书管理系统"); System.exit(0); } } } else{ System.exit(0); } }elseif(order.equals("AccessSTInterface")){ U=L.UserComing(); while(true){ System.out.println("< System.out.print("<<"); order=sc.next(); if(order.equals("SearchBook")){ L.ShowBook(L.SearchBook()); } elseif(order.equals("BorrowBook")){ L.SearchBook().BookBorrow(U); } elseif(order.equals("ReturnBook")){ L.ReturnBook(U); } elseif(order.equals("GoBack")){ break; } } } elseif(order.equals("over")){ System.out.println("已退出图书管理系统"); System.exit(0); } else{ System.out.println("输入了错误的指令"); continue; } } } } Library.java packagepany; importjava.util.Scanner; importjava.util.Vector; publicclassLibrary{ publicstaticfinalintOK=1; publicstaticfinalintERROR=1; Vector privateStringLibraryname; Scannersc=newScanner(System.in); Library(Stringname){ this.Libraryname=name; } publicUserUserComing(){ intkind; UserU; Scannersc=newScanner(System.in); System.out.println("如果你是老师请输入1,若是学生请输入2"); while(true){ while(true){ kind=sc.nextInt(); if(kind==1){ U=newTeacher(); returnU; }elseif(kind==2){ System.out.println("如果你是本科生请输入1,若是硕士研究生请输入2"); while(true){ kind=sc.nextInt(); if(kind==1){ U=newUndergraduate(); returnU; } elseif(kind==2){ U=newMaster(); returnU; }else{ System.out.println("输入错误"); break; } } }else{ System.out.println("输入错误"); System.out.println("请重新输入: "); break; } } } } publicvoidaddBook(Bookb){ book.add(b); } publicvoidaddBook(){ inti; i=1; Bookb; while(i==1){ b=newBook(); this.addBook(b); System.out.println("如果要继续输入书本信息就输入1,否则就输入2"); i=sc.nextInt(); } } publicBookSearchBook(){ StringBookName; Bookb; System.out.println("请输入你要借查询的书"); BookName=sc.next(); for(inti=0;i b=(Book)this.book.elementAt(i); if(b.bookName.equals(BookName)){ returnb; } } returnnull; } publicvoidReturnBook(UserU){ Useru; Bookb; b=this.SearchBook(); for(inti=0;i u=(User)b.BookUser.elementAt(i); if(u==U){ U.numBookBor--; b.BookUser.remove(i); b.surplus++; System.out.println("还书成功"); return; } else{ System.out.println("您不是这本书的借阅者,不能还书"); return; } } System.out.println("找不到你要的书"); } publicvoidDeleteBook(){ StringBookName; Bookb; System.out.println("请输入你要删除的书"); BookName=sc.next(); for(inti=0;i b=(Book)this.book.elementAt(i); if(b.bookName.equals(BookName)){ if(b.BookUser.size()==0){ this.book.remove(i); System.out.println("已经成功的删除书籍"); } else{ System.out.println("还有人尚未还书,不能够删除书籍"); } } } } publicvoidShowBook(){ Bookb; for(inti=0;i b=(Book)book.elementAt(i); System.out.println((i+1)+"\t"+b.bookName+"\t"+b.auther+"\t"+b.bookNum+"\t"+b.depositTime.getYear()+"\t"+b.depositTime.getMonth()+"\t"+b.depositTime.getDay()+"\t"+b.surplus); } } publicvoidShowBook(Bookb){ System.out.println("\t"+b.bookName+"\t"+b.auther+"\t"+b.bookNum+"\t"+b.depositTime.getYear()+"\t"+b.depositTime.getMonth()+"\t"+b.depositTime.getDay()+"\t"+b.surplus); } } Book.java packagepany; importjava.util.Scanner; importjava.util.Vector; publicclassLibrary{ publicstaticfinalintOK=1; publicstaticfinalintERROR=1; Vector privateStringLibraryname; Scannersc=newScanner(System.in); Library(Stringname){ this.Libraryname=name; } publicUserUserComing(){ intkind; UserU; Scannersc=newScanner(System.in); System.out.println("如果你是老师请输入1,若是学生请输入2"); while(true){ while(true){ kind=sc.nextInt(); if(kind==1){ U=newTeacher(); returnU; }elseif(kind==2){ System.out.println("如果你是本科生请输入1,若是硕士研究生请输入2"); while(true){ kind=sc.nextInt(); if(kind==1){ U=newUndergraduate(); returnU; } elseif(kind==2){ U=newMaster(); returnU; }else{ System.out.println("输入错误"); break; } } }else{ System.out.println("输入错误"); System.out.println("请重新输入: "); break; } } } } publicvoidaddBook(Bookb){ book.add(b); } publicvoidaddBook(){ inti; i=1; Bookb; while(i==1){ b=newBook(); this.addBook(b); System.out.println("如果要继续输入书本信息就输入1,否则就输入2"); i=sc.nextInt(); } } publicBookSearchBook(){ StringBookName; Bookb; System.out.println("请输入你要借查询的书"); BookName=sc.next(); for(inti=0;i b=(Book)this.book.elementAt(i); if(b.bookName.equals(BookName)){ returnb; } } returnnull; } publicvoidReturnBook(UserU){ Useru; Bookb; b=this.SearchBook(); for(inti=0;i u=(User)b.BookUser.elementAt(i); if(u==U){ U.numBookBor--; b.BookUser.remove(i); b.surplus++; System.out.println("还书成功"); return; } else{ System.out.println("您不是这本书的借阅者,不能还书"); return; } } System.out.println("找不到你要的书"); } publicvoidDeleteBook(){ StringBookName; Bookb; System.out.println("请输入你要删除的书"); BookName=sc.next(); for(inti=0;i b=(Book)this.book.elementAt(i); if(b.bookName.equals(BookName)){ if(b.BookUser.size()==0){ this.book.remove(i); System.out.println("已经成功的删除书籍"); } else{ System.out.println("还有人尚未还书,不能够删除书籍"); } } } } publicvoidShowBook(){ Bookb; for(inti=0;i b=(Book)book.elementAt(i); System.out.println((i+1)+"\t"+b.bookName+"\t"+b.auther+"\t"+b.bookNum+"\t"+b.depositTime.getYear()+"\t"+b.depositTime.getMonth()+"\t"+b.depositTime.getDay()+"\t"+b.surplus); } } publicvoidShowBook(Bookb){ System.out.println("\t"+b.bookName+"\t"+b.auther+"\t"+b.bookNum+"\t"+b.depositTime.getYear()+"\t"+b.depositTime.getMonth()+"\t"+b.depositTime.getDay()+"\t"+b.surplus); } } User.java packagepany; importjava.util.Date; importjava.util.Scanner; classUser{ publicStringname; publicintnumBookBor;//借书的数量 //publicDateborrowTime; publicStringId; publicScannersc=newScanner(System.in); User(){} } classStudentsextendsUser{ } //想想其实也不过如此 classUndergraduateextendsStudents{ Undergraduate(StringsName,Stringid){ this.name=sName; this.Id=id; } Undergraduate(){ System.out.println("请输入你的姓名: "); this.name=sc.next(); System.out.println("请输入你的学号: "); this.Id=sc.next(); this.numBookBor=0; } } classMasterextendsStudents{ Master(StringsName,Stringid){ this.name=sName; this.Id=id; } Master(){ System.out.println("请输入你的姓名: "); this.name=sc.next(); System.out.println("请输入你的学号: "); this.Id=sc.next(); this.numBookBor=0; } } classTeacherextendsUser{ Teacher(StringtName,Stringid){ this.name=tName; this.Id=id; } Teacher(){ System.out.println("请输入你的姓名: "); this.name=sc.next(); System.out.println("请输入你的工号: "); this.Id=sc.next(); this.numBookBor=0; } } Administrators/java packagepany; importjava.util.Scanner; publicclassAdministrators{ ;privateStringpassWod; Scannersc=newScanner(System.in); Administrators(){ this.passWod="neu123"; } publicintgetPassWord(){ StringpassWord; for(inti=0;i<3;i++){ System.out.println("请输入密码: "); System.out.print("<<"); passWord=sc.next(); if(passWord.equals(this.passWod)){ return1; } else{ System.out.println("密码错误,您还有"+(2-i)+"机会"); } } return0; } publicvoidchangePassWord(){ StringpassWord; for(inti=0;i<3;i++){ System.out.println("请输入原密码: \n<<"); passWord=sc.next(); if(passWord.equals(this.passWod)){ System.out.println("请输入新密码: \n<<"); this.passWod=sc.next(); break; } else{ System.out.println("密码错误,您还有"+(2-i)+"机会"); } } } }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 实验 报告 图书 管理 系统