编写book.java_编写一个javabean命名为:Book.java属性包括:
时间: 2024-02-20 09:00:13 浏览: 59
java代码-Book JavaBean
好的,以下是一个简单的 Book.java 的示例代码,包含了一些常见的属性:
```java
public class Book {
private String title; // 书名
private String author; // 作者
private String publisher; // 出版社
private int publishYear; // 出版年份
private double price; // 价格
// 构造方法
public Book(String title, String author, String publisher, int publishYear, double price) {
this.title = title;
this.author = author;
this.publisher = publisher;
this.publishYear = publishYear;
this.price = price;
}
// getter 和 setter 方法
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public int getPublishYear() {
return publishYear;
}
public void setPublishYear(int publishYear) {
this.publishYear = publishYear;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
```
这个 Book 类包含了以下属性:
- title:书名,类型为 String;
- author:作者,类型为 String;
- publisher:出版社,类型为 String;
- publishYear:出版年份,类型为 int;
- price:价格,类型为 double。
同时,还包含了相应的 getter 和 setter 方法,以及一个带参数的构造方法。这些方法可以让我们对 Book 类的属性进行读取和修改。
阅读全文