package 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) {
this.name = name;
this.author = author;
this.price = price;
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) {
isBorrowed = borrowed;
}
@Override
public String toString() {
return "Book{" +
"name='" + name + '\'' +
", author='" + author + '\'' +
", price=" + price +
", type='" + type + '\'' +
(isBorrowed == true ? " 已借出" : " 未借出") +
'}';
}
}
BookList
package book;
public class BookList {
private Book[] bookList = new Book[10];
private int usedSize;//当前书架上有几本书
public BookList(){
this.bookList[0] = new Book("三国演义","罗贯中",18,"小说");
this.bookList[1] = new Book("西游记","吴承恩",20,"小说");
this.bookList[2] = new Book("红楼梦","曹雪芹",45,"小说");