Java实验报告之图书管理系统(共12页).docx

上传人:飞****2 文档编号:14460751 上传时间:2022-05-04 格式:DOCX 页数:12 大小:28.98KB
返回 下载 相关 举报
Java实验报告之图书管理系统(共12页).docx_第1页
第1页 / 共12页
Java实验报告之图书管理系统(共12页).docx_第2页
第2页 / 共12页
点击查看更多>>
资源描述

《Java实验报告之图书管理系统(共12页).docx》由会员分享,可在线阅读,更多相关《Java实验报告之图书管理系统(共12页).docx(12页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、精选优质文档-倾情为你奉上Java实验报告图书管理系统1. 管理员界面密码验证展示所有图书查找图书添加书籍删除书籍修改密码返回上一层结束2. 学生界面身份识别查找图书借阅图书归还书籍返回上一层结束3. 退出程序源代码:Main.javapackage pany;import java.util.Date;import java.util.Scanner;public class Main public static void main(String args) / write your code here User U; Library L=new Library(东北大学图书馆); Syst

2、em.out.println(欢迎来到东北大学图书馆); Book b1=new Book(java编程思想,sdhf,new Date(2016,12,13),15); Book b2=new Book(C+编程,nimei,15654,new Date(2017,5,13),5); Students s1=new Undergraduate(黎明,); Students s2=new Master(狭隘,); b1.BookUser.add(s2); b1.BookUser.add(s1); b2.BookUser.add(s2); b2.BookUser.add(s1); L.addBo

3、ok(b1); L.addBook(b2); /在以上的代码中都是为了增加图书馆中的藏书 Scanner sc=new Scanner(System.in); String order; /命令操作板 while(true) System.out.println(命令操作符nAccessADInterfacenAccessSTInterfacenover); System.out.print(); order=sc.next(); if(order.equals(AccessADInterface) Administrators A=new Administrators(); if (A.ge

4、tPassWord() = 1) while(true) System.out.println(命令操作符nShowAllBooknSearchBooknAddBooknDeleteBooknChangePassWordnGoBacknover); System.out.print(); order = sc.next(); if (order.equals(ShowAllBook) L.ShowBook(); else if (order .equals( SearchBook) L.ShowBook(L.SearchBook(); else if (order.equals( AddBoo

5、k) ) L.addBook(); else if (order .equals( DeleteBook) L.DeleteBook(); else if(order.equals(ChangePassWord) A.changePassWord(); else if (order .equals( GoBack) break; else if (order .equals( over) System.out.println(已退出图书管理系统); System.exit(0); else System.exit(0); else if(order.equals(AccessSTInterfa

6、ce) U=L.UserComing(); while (true) System.out.println(SearchBooknBorrowBooknReturnBooknGoBacknover); System.out.print(); order=sc.next(); if(order.equals(SearchBook) L.ShowBook(L.SearchBook(); else if(order.equals(BorrowBook) L.SearchBook().BookBorrow(U); else if(order.equals(ReturnBook) L.ReturnBoo

7、k(U); else if(order.equals(GoBack) break; else if(order.equals(over) System.out.println(已退出图书管理系统); System.exit(0); else System.out.println(输入了错误的指令); continue; Library.javapackage pany;import java.util.Scanner;import java.util.Vector;public class Library public static final int OK=1; public static

8、final int ERROR=1; Vector book= new Vector();/用来存储书类 丹书类中也存有用户类 private String Libraryname; Scanner sc=new Scanner(System.in); Library (String name) this.Libraryname=name; public User UserComing() int kind; User U; Scanner sc = new Scanner(System.in); System.out.println(如果你是老师请输入1,若是学生请输入2); while (

9、true) while(true) kind = sc.nextInt(); if (kind = 1) U = new Teacher(); return U; else if (kind = 2) System.out.println(如果你是本科生请输入1,若是硕士研究生请输入2); while (true) kind=sc.nextInt(); if(kind=1) U = new Undergraduate(); return U; else if(kind=2) U=new Master(); return U; else System.out.println(输入错误); bre

10、ak; else System.out.println(输入错误); System.out.println(请重新输入:); break; public void addBook(Book b) book.add(b); public void addBook() int i; i=1; Book b; while(i=1) b=new Book(); this.addBook(b); System.out.println(如果要继续输入书本信息就输入1,否则就输入2); i=sc.nextInt(); public Book SearchBook() String BookName; Boo

11、k b; System.out.println(请输入你要借查询的书); BookName=sc.next(); for(int i=0;ithis.book.size();i+) b=(Book)this.book.elementAt(i); if(b.bookName.equals(BookName) return b; return null; public void ReturnBook(User U) User u; Book b; b=this.SearchBook(); for(int i=0;ib.BookUser.size();i+) u=(User) b.BookUser.

12、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(找不到你要的书); public void DeleteBook() String BookName; Book b; System.out.println(请输入你要删除的书); BookName=sc.next(); for(int i=0;ith

13、is.book.size();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(还有人尚未还书,不能够删除书籍); public void ShowBook() Book b; for(int i=0;ithis.book.size();i+) b=(Book)book.elementAt(i); System.o

14、ut.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); public void ShowBook(Book b) System.out.println(t+b.bookName+t+b.auther+t+b.bookNum+t+b.depositTime.getYear()+t+b.depositTime.getMonth()+t+b.depositTime.get

15、Day()+t+b.surplus); Book.javapackage pany;import java.util.Scanner;import java.util.Vector;public class Library public static final int OK=1; public static final int ERROR=1; Vector book= new Vector();/用来存储书类 丹书类中也存有用户类 private String Libraryname; Scanner sc=new Scanner(System.in); Library (String n

16、ame) this.Libraryname=name; public User UserComing() int kind; User U; Scanner sc = new Scanner(System.in); System.out.println(如果你是老师请输入1,若是学生请输入2); while (true) while(true) kind = sc.nextInt(); if (kind = 1) U = new Teacher(); return U; else if (kind = 2) System.out.println(如果你是本科生请输入1,若是硕士研究生请输入2)

17、; while (true) kind=sc.nextInt(); if(kind=1) U = new Undergraduate(); return U; else if(kind=2) U=new Master(); return U; else System.out.println(输入错误); break; else System.out.println(输入错误); System.out.println(请重新输入:); break; public void addBook(Book b) book.add(b); public void addBook() int i; i=1;

18、 Book b; while(i=1) b=new Book(); this.addBook(b); System.out.println(如果要继续输入书本信息就输入1,否则就输入2); i=sc.nextInt(); public Book SearchBook() String BookName; Book b; System.out.println(请输入你要借查询的书); BookName=sc.next(); for(int i=0;ithis.book.size();i+) b=(Book)this.book.elementAt(i); if(b.bookName.equals(

19、BookName) return b; return null; public void ReturnBook(User U) User u; Book b; b=this.SearchBook(); for(int i=0;ib.BookUser.size();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(您不是这本书的借阅者,不能还书

20、); return; System.out.println(找不到你要的书); public void DeleteBook() String BookName; Book b; System.out.println(请输入你要删除的书); BookName=sc.next(); for(int i=0;ithis.book.size();i+) b=(Book)this.book.elementAt(i); if(b.bookName.equals(BookName) if(b.BookUser.size()=0) this.book.remove(i); System.out.printl

21、n(已经成功的删除书籍); else System.out.println(还有人尚未还书,不能够删除书籍); public void ShowBook() Book b; for(int i=0;ithis.book.size();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);

22、public void ShowBook(Book b) 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.javapackage pany;import java.util.Date;import java.util.Scanner;class User public String name; public int numBookBor;/借

23、书的数量 /public Date borrowTime; public String Id; public Scanner sc=new Scanner(System.in); User() class Students extends User/想想其实也不过如此class Undergraduate extends Students Undergraduate(String sName,String id) this.name=sName; this.Id=id; Undergraduate() System.out.println(请输入你的姓名:); this.name=sc.nex

24、t(); System.out.println(请输入你的学号:); this.Id=sc.next(); this.numBookBor=0; class Master extends Students Master(String sName,String id) this.name=sName; this.Id=id; Master() System.out.println(请输入你的姓名:); this.name=sc.next(); System.out.println(请输入你的学号:); this.Id=sc.next(); this.numBookBor=0; class Tea

25、cher extends User Teacher(String tName,String id) 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/javapackage pany;import java.util.Scanner;public class Administrators ; priva

26、te String passWod; Scanner sc=new Scanner(System.in); Administrators() this.passWod=neu123; public int getPassWord() String passWord; for(int i=0;i3;i+) System.out.println(请输入密码:); System.out.print(); passWord=sc.next(); if( passWord.equals(this.passWod) return 1; else System.out.println(密码错误,您还有+(2-i)+机会); return 0; public void changePassWord() String passWord; for(int i=0;i3;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)+机会); 专心-专注-专业

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

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

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁