图书管理系统
1. 描述
a> 角色
图书管理系统有两个角色对书进行操作, 分别是普通用户类和管理员类.
b> 操作
操作可划分为: 增添图书, 删除图书, 更新图书, 查找图书, 借阅图书, 归还图书, 退出系统
2. 实现
a> Book 类
package java0126;
/**
* @author FMM
* @version 7.0
* @date 2021/1/26 12:37
*/
public class Book {
private String name;
private String author;
private int price;
private String type;
// 表示没有被借
private boolean isBorrowed = false;
public Book(String name, int price, String author, String type) {
this.name = name;
this.price = price;
this.author = author;
this.type = type;
}
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 boolean isBorrowed() {
return isBorrowed;
}
public void setBorrowed(boolean borrowed) {
this.isBorrowed = borrowed;
}
public void bookImformation() {
System.out.println(this.name + " " + this.price + " "
+ this.author + " " + this.type + " " + this.isBorrowed);
}
}
b> BookList 类
package java0126;
import java.util.Scanner;
/**
* @author FMM
* @version 7.0
* @date 2021/1/26 12:37
*/
public class BookList {
private Book[] books = new Book[100] ;
private int size;
// 图书管理系统的关闭和开启条件
private boolean isOpen = true;
public BookList() {
this.books[this.size++] = new Book("三国演义",100, "罗贯中","历史小说");
}
public void addBook(String name, int price, String author, String type) {
this.books[size++] = new Book(name, price, author, type);
}
public Book getBook(int index) {
if (!checkIndex(index)) {
return null;
}
return this.books[index];
}
public void setSize(int size) {
this.size = size;
}
public boolean isOpen() {
return isOpen;
}
public void setOpen(boolean open) {
this.isOpen = open;
}
public int getSize() {
return this.size;
}
public void borrowBook(int index) {
if (!checkIndex(index)) {
return;
}
if (!this.books[index].isBorrowed()) {
this.books[index].setBorrowed(true);
}
}
public void displayBook() {
if (