package book;
public class Book {
private String name;//书名
private String author;//作者
private int price;//价格
private String type;//类型
private boolean isBorrowed;//是否借出
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 voidsetName(String name){
this.name = name;}
public String getAuthor(){
return author;}
public voidsetAuthor(String author){
this.author = author;}
public intgetPrice(){
return price;}
public voidsetPrice(int price){
this.price = price;}
public String getType(){
return type;}
public voidsetType(String type){
this.type = type;}
public boolean isBorrowed(){
return isBorrowed;}
public voidsetBorrowed(boolean borrowed){
isBorrowed = borrowed;}
@Override
public String toString(){
return"Book{"+"name='"+ name +'\''+", author='"+ author +'\''+", price="+ price +", type='"+ type +'\''+((isBorrowed == true)?" 已经被借出 ":" 未被借出 ")+'}';}}
(2)BookList
package book;
public class BookList {
private Book[] books = new Book[10];
private int usedSize;
public BookList(){
books[0]= new Book("三国演义","罗贯中",17,"小说");
books[1]= new Book("西游记","吴承恩",47,"小说");
books[2]= new Book("水浒传","施耐庵",37,"小说");
this.usedSize =3;}
public intgetUsedSize(){
return usedSize;}
public voidsetUsedSize(int usedSize){
this.usedSize = usedSize;}//获取到pos位置的一本书
public Book getPos(int pos){
return this.books[pos];}//设置Pos下标为一本书->[添加一本书]
public voidsetBook(int pos,Book book){
this.books[pos]= book;}