文章目录
1.设计要求
- 登录(普通用户、管理员)
- 普通用户支持的操作
a)根据书名查询书籍
d)借书
c)还书
d)退出 - 管理员支持的操作
a)查询图书
b)增加图书
c)删除图书
d)展示所有图书
e)退出
2.类设计
2.1设计思路
2.2具体类
2.3整体流程
1.程序启动,登录系统并创建用户。
2.循环调用用户中 menu
方法,提示用户输入要操作的选项。
3.根据选项调用 DoAction
方法,执行到对应的 Action
中的逻辑。
4.根据 Action
中的 work
方法来完成最终的操作。
3.程序测试
3.1book包
Book类
package library.book;
public class Book {
private String name;
private String author;
private int price;
private String type; // 小说, 散文......
private boolean isBorrowed; // 默认false 未借出
public Book(String name, String author, int price, String type, boolean isBorrowed) {
this.name = name;
this.author = author;
this.price = price;
this.type = type;
this.isBorrowed = isBorrowed;
}
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) {
isBorrowed = borrowed;
}
@Override
public String toString() {
return "Book{" +
"name='" + name + '\'' +
", author='" + author + '\'' +
", price=" + price +
", type='" + type + '\'' +
", isBorrowed=" + isBorrowed +
'}';
}
}
BookList类
package library.book;
import library.book.Book;
//用来表示多本书
public class BookList {
private Book[] books = new Book[100]; //相当于顺序表
private int size = 0;//有效元素个数
public BookList(){
// 先默认添加几个数据进去, 方便后续测试
books[0] = new Book("三国演义","罗贯中",100,"古典名著",false);
size++;
books[1] = new Book("西游记","吴承恩",120,"古典名著",false);
size++;
books[2] = new Book("金瓶梅","兰陵笑笑生",200,"古典名著",false);
size++;
}
public Book getBook(int pos){
return books[pos];
}
public void setBook(int pos,Book book){
books[pos] = book;
}
public int getSize() {
return size;
}
public void setSize(int size