一. 功能介绍
1.1 使用介绍
1.输入姓名
2.选择身份
3.根据身份打印不同功能菜单
1.2 基本框架
二、具体思路
book(包)
operation(功能包)
user(使用者包)
三、代码实现
book(包)
Book(书类)
package book;
/**
* User: gu'jiu
* Date: 2022-05-18
* Time: 14:45
* Description:书
*/
public class Book {
private String name;//书名
private String author;//作者
private double price;//价格
private String type;//类型
private boolean state;//书的状态(已借出or未借出)
//对书进行初始化,书的状态不用进行初始化(默认未借出)
public Book(String name, String author, double price, String type) {
this.name = name;
this.author = author;
this.price = price;
this.type = type;
this.state = state;
}
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 double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public boolean isState() {
return state;
}
public void setState(boolean state) {
this.state = state;
}
@Override
public String toString() {
return "[" +
"name='" + name + '\'' +
", author='" + author + '\'' +
", price=" + price +
", type='" + type + '\'' +
", " + (state == true ? "已借出" : "未借出") +
']';
}
}
BookList(书架类)
package book;
/**
* User: gu'jiu
* Date: 2022-05-18
* Time: 14:52
* Description:书架
*/
public class BookList {
private Book[] books = new Book[10];
private int usedSize;
public BookList() {
books[0] = new Book("三国演义","罗贯中",19.9,"小说");
books[1] = new Book("西游记","吴承恩",29.9,"小说");
books[2] = new Book("红楼梦","曹雪芹",26.9,"小说");
usedSize = 3;
}
public Book getBooks(int pos) {
//输入下标获取该下标的这本书
return books[pos];
}
public void setBooks(int pos, Book book) {
//输入下标和一本书,在该下标放入一本书
this.books[pos] = book;
}
public int getUsedSize() {
return usedSize;
}
public void setUsedSize(int usedSize) {
this.usedSize = usedSize;
}
}
operation(功能包)
IOperation(功能接口)
package operation;
import book.BookList;
/**
* User: gu'jiu
* Date: 2022-05-18
* Time: 15:07
* Description:接口
*/
public interface IOperation {
void work(BookList bookList);
}
FindOperation(查找图书)
package operation;
import book.Book;
import book.BookList;
import java.util.Scanner;
/**
* User: gu'jiu
* Date: 2022-05-18
* Time: 15:09
* Description:查找书籍信息
*/