目录
Java实现一个完整的对象:首先我们要找对象
其次是创建对象和使用对象
在图书管理系统中,首先要想到的对象:Book 、Book LIst 、User等等
还有各个operation类,我将把他们放进同一个包里
Book类
public class Book {
private String name;//书名
private String author;//作者
private int price;//价格
private String type;//类型
private boolean 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;
}
public Book(String name, String author, int price, String type) {
this.name = name;
this.author = author;
this.price = price;
this.type = type;
}
@Override
public String toString() {
return "Book{" +
"name='" + name + '\'' +
", author='" + author + '\'' +
", price=" + price +
", type='" + type + '\'' +
((isBorrowed==true)?"已借出":"未借出")+
//", isBorrowed="+isBorrowed+
'}';
}
}
BookList类
public class BookList {
private Book[] books=new Book[10];
private int usedSize;
public BookList(){
books[0]=new Book("三国演义","罗贯中",90,"小说");
books[1]=new Book("西游记","吴承恩",70,"小说");
books[2]=new Book("红楼梦","曹雪芹",89,"小说");
this.usedSize=3;
}