图书管理系统(借还图书)--Java实现(附源码)

举报
托马斯-酷涛 发表于 2022/07/18 23:31:23 2022/07/18
【摘要】 目录 图书管理系统权限 图书管理系统程序框图 图书管理系统架构 管理员执行流程 学生执行流程 详细代码 源码获取 毕设专栏   图书管理系统权限 管理员:具有  1、查找图书 2、增加图书 3、删除图书 4、显示图书 等功能学生:具有  1、查找图书 2、借阅图书 3、归还图...

目录

图书管理系统权限

图书管理系统程序框图

图书管理系统架构

管理员执行流程

学生执行流程

详细代码

源码获取

毕设专栏


 

图书管理系统权限

  • 管理员:具有  1、查找图书 2、增加图书 3、删除图书 4、显示图书 等功能
  • 学生:具有  1、查找图书 2、借阅图书 3、归还图书 4、显示图书 等功能

图书管理系统程序框图

 

图书管理系统架构

 

管理员执行流程

 

学生执行流程

 

详细代码

Book


  
  1. package book;
  2. public class Book {
  3. /*一本书的属性包括书名,作者,价格,类型,编号,以及状态*/
  4. private String name;
  5. private String author;
  6. private int price;
  7. private String type;
  8. private int num;
  9. private boolean status;
  10. //提供构造方法
  11. public Book(String name, String author, int price, String type, int num) {
  12. this.name = name;
  13. this.author = author;
  14. this.price = price;
  15. this.type = type;
  16. this.num = num;
  17. }
  18. public String getName() {
  19. return name;
  20. }
  21. public void setName(String name) {
  22. this.name = name;
  23. }
  24. public String getAuthor() {
  25. return author;
  26. }
  27. public void setAuthor(String author) {
  28. this.author = author;
  29. }
  30. public int getPrice() {
  31. return price;
  32. }
  33. public void setPrice(int price) {
  34. this.price = price;
  35. }
  36. public String getType() {
  37. return type;
  38. }
  39. public void setType(String type) {
  40. this.type = type;
  41. }
  42. public int getNum() {
  43. return num;
  44. }
  45. public void setNum(int num) {
  46. this.num = num;
  47. }
  48. public boolean isStatus() {
  49. return status;
  50. }
  51. public void setStatus(boolean status) {
  52. this.status = status;
  53. }
  54. //toString 方法打印
  55. @Override
  56. public String toString() {
  57. return "Book{" +
  58. "name='" + name + '\'' +
  59. ", author='" + author + '\'' +
  60. ", price=" + price +
  61. ", type='" + type + '\'' +
  62. ", num=" + num +
  63. ((status == true) ? " 已借出 " : " 未借出 ") +
  64. '}';
  65. }
  66. }

BookList


  
  1. package book;
  2. public class BookList {
  3. //书都是同一类型的元素,创建一个Book类型的数组
  4. private Book[] books;
  5. private int size;
  6. //先给书架放三本书
  7. public BookList() {
  8. this.books = new Book[10];
  9. books[0] = new Book("狂人日记","鲁迅",10,"小说",1);
  10. books[1] = new Book("将进酒","李白",23,"诗",3);
  11. books[2] = new Book("清明上河图","张择端",20,"书法",2);
  12. this.size = 3;
  13. }
  14. public int getSize() {
  15. return size;
  16. }
  17. public void setSize(int size) {
  18. this.size = size;
  19. }
  20. public void setBooks(int pos, Book book) {
  21. this.books[pos] = book;
  22. }
  23. public Book getBook(int pos) {
  24. return this.books[pos];
  25. }
  26. }

AddOperation


  
  1. package operation;
  2. import book.Book;
  3. import book.BookList;
  4. import java.util.Scanner;
  5. public class AddOperation implements IOperation {
  6. @Override
  7. public void work(BookList bl) {
  8. Scanner sc = new Scanner(System.in);
  9. System.out.println("添加图书");
  10. System.out.println("请输入图书的名字:");
  11. String name = sc.nextLine();
  12. System.out.println("请输入图书的作者:");
  13. String author = sc.nextLine();
  14. System.out.println("请输入图书价格:");
  15. int price = sc.nextInt();
  16. System.out.println("请输入图书的类型:");
  17. String type = sc.next();
  18. System.out.println("请输入图书的编号:");
  19. int num = sc.nextInt();
  20. Book book = new Book(name,author,price,type,num);
  21. int curSize = bl.getSize();//拿到长度
  22. bl.setBooks(curSize,book);
  23. bl.setSize(curSize+1);
  24. System.out.println("添加成功!");
  25. }
  26. }

BorrOperation


  
  1. package operation;
  2. import book.Book;
  3. import book.BookList;
  4. import java.util.Scanner;
  5. public class BorrOperation implements IOperation{
  6. @Override
  7. public void work(BookList bl) {
  8. System.out.println("借阅书籍");
  9. System.out.println("请输入需要借阅的书籍名字:");
  10. Scanner sc = new Scanner(System.in);
  11. String name = sc.nextLine();
  12. for (int i = 0; i < bl.getSize(); i++) {
  13. Book book = bl.getBook(i);
  14. if(book.getName().equals(name)) {
  15. System.out.println("请取走您要的书籍!");
  16. book.setStatus(true);
  17. System.out.println(book);
  18. return;
  19. }
  20. }
  21. System.out.println("没有你需要的书籍!");
  22. }
  23. }

DelOperation


  
  1. package operation;
  2. import book.Book;
  3. import book.BookList;
  4. import java.util.Scanner;
  5. public class DelOperation implements IOperation{
  6. @Override
  7. public void work(BookList bl) {
  8. System.out.println("删除图书");
  9. System.out.println("请输入需要删除的书籍名字:");
  10. Scanner sc = new Scanner(System.in);
  11. String name = sc.nextLine();
  12. int i = 0;
  13. for (; i < bl.getSize(); i++) {
  14. Book book = bl.getBook(i);
  15. if(book.getName().equals(name)){
  16. break;
  17. }
  18. }
  19. if(i >= bl.getSize()){
  20. System.out.println("没有找到此书籍");
  21. return;
  22. }
  23. int j = i;
  24. for(; j < bl.getSize() - 1; j++){
  25. Book book = bl.getBook(j + 1);
  26. bl.setBooks(j,book);
  27. }
  28. int cueSize = bl.getSize();
  29. bl.setSize(cueSize-1);
  30. System.out.println("成功删除此书籍!");
  31. }
  32. }

DisOperation


  
  1. package operation;
  2. import book.Book;
  3. import book.BookList;
  4. public class DisOperation implements IOperation{
  5. @Override
  6. public void work(BookList bl) {
  7. System.out.println("显示图书");
  8. for (int i = 0; i < bl.getSize(); i++) {
  9. Book book = bl.getBook(i);
  10. System.out.println(book);
  11. }
  12. }
  13. }

ExiOperation


  
  1. package operation;
  2. import book.BookList;
  3. public class ExiOperation implements IOperation{
  4. @Override
  5. public void work(BookList bl) {
  6. System.out.println("退出系统");
  7. System.exit(0);
  8. }
  9. }

Finoperation


  
  1. package operation;
  2. import book.BookList;
  3. public class ExiOperation implements IOperation{
  4. @Override
  5. public void work(BookList bl) {
  6. System.out.println("退出系统");
  7. System.exit(0);
  8. }
  9. }

IOperation


  
  1. package operation;
  2. import book.BookList;
  3. public interface IOperation {
  4. void work(BookList bl);
  5. }

RetOperation


  
  1. package operation;
  2. import book.Book;
  3. import book.BookList;
  4. import java.util.Scanner;
  5. public class RetOperation implements IOperation{
  6. @Override
  7. public void work(BookList bl) {
  8. System.out.println("归还图书");
  9. Scanner sc = new Scanner(System.in);
  10. System.out.println("请输入您要归还的书籍名字!");
  11. String name = sc.nextLine();
  12. for (int i = 0; i < bl.getSize(); i++) {
  13. Book book = bl.getBook(i);
  14. if(book.getName().equals(name)) {
  15. book.setStatus(false);
  16. System.out.println(book);
  17. return;
  18. }
  19. }
  20. }
  21. }

Administrator


  
  1. package user;
  2. import operation.*;
  3. import java.util.Scanner;
  4. public class Administrator extends User{
  5. public Administrator(String name) {
  6. super(name);
  7. this.operation = new IOperation[]{new ExiOperation(),new FinOperation(),new AddOperation(),new DelOperation(),new DisOperation()};
  8. }
  9. @Override
  10. public int menu() {
  11. System.out.println("欢迎" + this.name + "进入图书管理系统!");
  12. Scanner sc = new Scanner(System.in);
  13. System.out.println("=============");
  14. System.out.println("1.查找图书");
  15. System.out.println("2.增加图书");
  16. System.out.println("3.删除图书");
  17. System.out.println("4.显示图书");
  18. System.out.println("0.退出系统");
  19. System.out.println("=============");
  20. int choice = sc.nextInt();
  21. return choice;
  22. }
  23. }

Ordinary


  
  1. package user;
  2. import operation.*;
  3. import java.util.Scanner;
  4. public class Ordinary extends User {
  5. public Ordinary(String name) {
  6. super(name);
  7. this.operation = new IOperation[]{new ExiOperation(),new FinOperation(),new BorrOperation(),new RetOperation(),new DisOperation()};
  8. }
  9. @Override
  10. public int menu() {
  11. System.out.println("欢迎" + this.name + "同学进入图书管理系统!");
  12. Scanner sc = new Scanner(System.in);
  13. System.out.println("==============");
  14. System.out.println("1.查找图书");
  15. System.out.println("2.借阅图书");
  16. System.out.println("3.归还图书");
  17. System.out.println("4.显示图书");
  18. System.out.println("0.退出系统");
  19. System.out.println("==============");
  20. int choice = sc.nextInt();
  21. return choice;
  22. }
  23. }

User


  
  1. package user;
  2. import book.BookList;
  3. import operation.IOperation;
  4. //抽象类,主要为了被继承
  5. public abstract class User {
  6. public String name;
  7. public IOperation[] operation;
  8. public User(String name) {
  9. this.name = name;
  10. }
  11. public abstract int menu();
  12. public void doOperation(int choice, BookList bl) {
  13. this.operation[choice].work(bl);
  14. }
  15. }

Main


  
  1. import book.BookList;
  2. import user.Administrator;
  3. import user.Ordinary;
  4. import user.User;
  5. import java.util.Scanner;
  6. public class Main {
  7. public static User login() {
  8. Scanner sc = new Scanner(System.in);
  9. System.out.println("请输入姓名:");
  10. String name = sc.next();
  11. System.out.println("请确认您的身份:1 > 管理员 0 > 学生");
  12. int choice = sc.nextInt();
  13. if(choice == 1){
  14. return new Administrator(name);
  15. }else{
  16. return new Ordinary(name);
  17. }
  18. }
  19. public static void main(String[] args) {
  20. BookList bl = new BookList();
  21. //登录
  22. User user = login();
  23. //选择菜单
  24. while(true){
  25. int choice = user.menu();
  26. user.doOperation(choice,bl);
  27. }
  28. }
  29. }

以上为全部源码,有不太明白的同学可以去下载链接直接获取源码

源码获取

毕设专栏

 https://download.csdn.net/download/m0_54925305/86236726

https://blog.csdn.net/m0_54925305/category_11702151.html?spm=1001.2014.3001.5482

文章来源: tuomasi.blog.csdn.net,作者:托马斯-酷涛,版权归原作者所有,如需转载,请联系作者。

原文链接:tuomasi.blog.csdn.net/article/details/125799982

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。