图书管理系统(借还图书)--Java实现(附源码)
【摘要】
目录
图书管理系统权限
图书管理系统程序框图
图书管理系统架构
管理员执行流程
学生执行流程
详细代码
源码获取
毕设专栏
图书管理系统权限
管理员:具有 1、查找图书 2、增加图书 3、删除图书 4、显示图书 等功能学生:具有 1、查找图书 2、借阅图书 3、归还图...
目录
图书管理系统权限
- 管理员:具有 1、查找图书 2、增加图书 3、删除图书 4、显示图书 等功能
- 学生:具有 1、查找图书 2、借阅图书 3、归还图书 4、显示图书 等功能
图书管理系统程序框图
图书管理系统架构
管理员执行流程
学生执行流程
详细代码
Book
-
package book;
-
-
public class Book {
-
/*一本书的属性包括书名,作者,价格,类型,编号,以及状态*/
-
private String name;
-
private String author;
-
private int price;
-
private String type;
-
private int num;
-
private boolean status;
-
-
//提供构造方法
-
public Book(String name, String author, int price, String type, int num) {
-
this.name = name;
-
this.author = author;
-
this.price = price;
-
this.type = type;
-
this.num = num;
-
}
-
-
public String getName() {
-
return name;
-
}
-
-
public void setName(String name) {
-
this.name = name;
-
}
-
-
public String getAuthor() {
-
return author;
-
}
-
-
public void setAuthor(String author) {
-
this.author = author;
-
}
-
-
public int getPrice() {
-
return price;
-
}
-
-
public void setPrice(int price) {
-
this.price = price;
-
}
-
-
public String getType() {
-
return type;
-
}
-
-
public void setType(String type) {
-
this.type = type;
-
}
-
-
public int getNum() {
-
return num;
-
}
-
-
public void setNum(int num) {
-
this.num = num;
-
}
-
-
public boolean isStatus() {
-
return status;
-
}
-
-
public void setStatus(boolean status) {
-
this.status = status;
-
}
-
-
//toString 方法打印
-
@Override
-
public String toString() {
-
return "Book{" +
-
"name='" + name + '\'' +
-
", author='" + author + '\'' +
-
", price=" + price +
-
", type='" + type + '\'' +
-
", num=" + num +
-
((status == true) ? " 已借出 " : " 未借出 ") +
-
'}';
-
}
-
}
BookList
-
package book;
-
-
public class BookList {
-
//书都是同一类型的元素,创建一个Book类型的数组
-
private Book[] books;
-
private int size;
-
-
//先给书架放三本书
-
public BookList() {
-
this.books = new Book[10];
-
books[0] = new Book("狂人日记","鲁迅",10,"小说",1);
-
books[1] = new Book("将进酒","李白",23,"诗",3);
-
books[2] = new Book("清明上河图","张择端",20,"书法",2);
-
this.size = 3;
-
}
-
-
-
public int getSize() {
-
return size;
-
}
-
-
public void setSize(int size) {
-
this.size = size;
-
}
-
-
public void setBooks(int pos, Book book) {
-
this.books[pos] = book;
-
}
-
-
public Book getBook(int pos) {
-
return this.books[pos];
-
}
-
}
AddOperation
-
package operation;
-
-
import book.Book;
-
import book.BookList;
-
-
import java.util.Scanner;
-
-
public class AddOperation implements IOperation {
-
@Override
-
public void work(BookList bl) {
-
Scanner sc = new Scanner(System.in);
-
System.out.println("添加图书");
-
System.out.println("请输入图书的名字:");
-
String name = sc.nextLine();
-
System.out.println("请输入图书的作者:");
-
String author = sc.nextLine();
-
System.out.println("请输入图书价格:");
-
int price = sc.nextInt();
-
System.out.println("请输入图书的类型:");
-
String type = sc.next();
-
System.out.println("请输入图书的编号:");
-
int num = sc.nextInt();
-
-
Book book = new Book(name,author,price,type,num);
-
int curSize = bl.getSize();//拿到长度
-
bl.setBooks(curSize,book);
-
bl.setSize(curSize+1);
-
System.out.println("添加成功!");
-
}
-
}
BorrOperation
-
package operation;
-
-
import book.Book;
-
import book.BookList;
-
-
import java.util.Scanner;
-
-
public class BorrOperation implements IOperation{
-
@Override
-
public void work(BookList bl) {
-
System.out.println("借阅书籍");
-
System.out.println("请输入需要借阅的书籍名字:");
-
Scanner sc = new Scanner(System.in);
-
String name = sc.nextLine();
-
for (int i = 0; i < bl.getSize(); i++) {
-
Book book = bl.getBook(i);
-
if(book.getName().equals(name)) {
-
System.out.println("请取走您要的书籍!");
-
book.setStatus(true);
-
System.out.println(book);
-
return;
-
}
-
}
-
System.out.println("没有你需要的书籍!");
-
}
-
}
-
-
DelOperation
-
package operation;
-
-
import book.Book;
-
import book.BookList;
-
-
import java.util.Scanner;
-
-
public class DelOperation implements IOperation{
-
@Override
-
public void work(BookList bl) {
-
System.out.println("删除图书");
-
System.out.println("请输入需要删除的书籍名字:");
-
Scanner sc = new Scanner(System.in);
-
String name = sc.nextLine();
-
int i = 0;
-
for (; i < bl.getSize(); i++) {
-
Book book = bl.getBook(i);
-
if(book.getName().equals(name)){
-
break;
-
}
-
}
-
if(i >= bl.getSize()){
-
System.out.println("没有找到此书籍");
-
return;
-
}
-
int j = i;
-
for(; j < bl.getSize() - 1; j++){
-
Book book = bl.getBook(j + 1);
-
bl.setBooks(j,book);
-
}
-
int cueSize = bl.getSize();
-
bl.setSize(cueSize-1);
-
System.out.println("成功删除此书籍!");
-
}
-
}
DisOperation
-
package operation;
-
-
import book.Book;
-
import book.BookList;
-
-
public class DisOperation implements IOperation{
-
@Override
-
public void work(BookList bl) {
-
System.out.println("显示图书");
-
for (int i = 0; i < bl.getSize(); i++) {
-
Book book = bl.getBook(i);
-
System.out.println(book);
-
}
-
}
-
}
ExiOperation
-
package operation;
-
-
import book.BookList;
-
-
public class ExiOperation implements IOperation{
-
@Override
-
public void work(BookList bl) {
-
System.out.println("退出系统");
-
System.exit(0);
-
}
-
}
Finoperation
-
package operation;
-
-
import book.BookList;
-
-
public class ExiOperation implements IOperation{
-
@Override
-
public void work(BookList bl) {
-
System.out.println("退出系统");
-
System.exit(0);
-
}
-
}
IOperation
-
package operation;
-
-
import book.BookList;
-
-
public interface IOperation {
-
void work(BookList bl);
-
}
RetOperation
-
package operation;
-
-
import book.Book;
-
import book.BookList;
-
-
import java.util.Scanner;
-
-
public class RetOperation implements IOperation{
-
@Override
-
public void work(BookList bl) {
-
System.out.println("归还图书");
-
Scanner sc = new Scanner(System.in);
-
System.out.println("请输入您要归还的书籍名字!");
-
String name = sc.nextLine();
-
for (int i = 0; i < bl.getSize(); i++) {
-
Book book = bl.getBook(i);
-
if(book.getName().equals(name)) {
-
book.setStatus(false);
-
System.out.println(book);
-
return;
-
}
-
}
-
}
-
}
Administrator
-
package user;
-
-
import operation.*;
-
-
import java.util.Scanner;
-
-
public class Administrator extends User{
-
-
public Administrator(String name) {
-
super(name);
-
this.operation = new IOperation[]{new ExiOperation(),new FinOperation(),new AddOperation(),new DelOperation(),new DisOperation()};
-
}
-
-
@Override
-
public int menu() {
-
System.out.println("欢迎" + this.name + "进入图书管理系统!");
-
Scanner sc = new Scanner(System.in);
-
System.out.println("=============");
-
System.out.println("1.查找图书");
-
System.out.println("2.增加图书");
-
System.out.println("3.删除图书");
-
System.out.println("4.显示图书");
-
System.out.println("0.退出系统");
-
System.out.println("=============");
-
int choice = sc.nextInt();
-
return choice;
-
}
-
}
-
Ordinary
-
package user;
-
-
import operation.*;
-
-
import java.util.Scanner;
-
-
public class Ordinary extends User {
-
-
public Ordinary(String name) {
-
super(name);
-
this.operation = new IOperation[]{new ExiOperation(),new FinOperation(),new BorrOperation(),new RetOperation(),new DisOperation()};
-
}
-
-
@Override
-
public int menu() {
-
System.out.println("欢迎" + this.name + "同学进入图书管理系统!");
-
Scanner sc = new Scanner(System.in);
-
System.out.println("==============");
-
System.out.println("1.查找图书");
-
System.out.println("2.借阅图书");
-
System.out.println("3.归还图书");
-
System.out.println("4.显示图书");
-
System.out.println("0.退出系统");
-
System.out.println("==============");
-
int choice = sc.nextInt();
-
return choice;
-
}
-
}
User
-
package user;
-
-
import book.BookList;
-
import operation.IOperation;
-
//抽象类,主要为了被继承
-
public abstract class User {
-
public String name;
-
public IOperation[] operation;
-
-
public User(String name) {
-
this.name = name;
-
}
-
-
public abstract int menu();
-
-
public void doOperation(int choice, BookList bl) {
-
this.operation[choice].work(bl);
-
}
-
}
Main
-
import book.BookList;
-
import user.Administrator;
-
import user.Ordinary;
-
import user.User;
-
-
import java.util.Scanner;
-
-
public class Main {
-
public static User login() {
-
Scanner sc = new Scanner(System.in);
-
System.out.println("请输入姓名:");
-
String name = sc.next();
-
System.out.println("请确认您的身份:1 > 管理员 0 > 学生");
-
int choice = sc.nextInt();
-
if(choice == 1){
-
return new Administrator(name);
-
}else{
-
return new Ordinary(name);
-
}
-
}
-
public static void main(String[] args) {
-
BookList bl = new BookList();
-
//登录
-
User user = login();
-
//选择菜单
-
while(true){
-
int choice = user.menu();
-
user.doOperation(choice,bl);
-
}
-
-
}
-
}
以上为全部源码,有不太明白的同学可以去下载链接直接获取源码
源码获取
毕设专栏
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)