图书浏览记录类 java代码
时间: 2024-12-21 10:11:46 浏览: 8
在Java中,我们可以创建一个`BookRecord`类来表示用户的图书浏览记录。这个类可以包含一些基本属性,比如书籍ID、标题、作者以及访问时间等。以下是一个简单的类设计:
```java
import java.util.Date;
public class BookRecord {
private int bookId; // 书籍ID
private String title; // 书籍标题
private String author; // 作者名字
private Date visitTime; // 访问时间
// 默认构造函数
public BookRecord() {}
// 参数构造函数
public BookRecord(int bookId, String title, String author, Date visitTime) {
this.bookId = bookId;
this.title = title;
this.author = author;
this.visitTime = visitTime;
}
// 获取和设置方法
public int getBookId() { return bookId; }
public void setBookId(int bookId) { this.bookId = bookId; }
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 Date getVisitTime() { return visitTime; }
public void setVisitTime(Date visitTime) { this.visitTime = visitTime; }
@Override
public String toString() {
return "BookRecord{" +
"bookId=" + bookId +
", title='" + title + '\'' +
", author='" + author + '\'' +
", visitTime=" + visitTime +
'}';
}
}
// 示例用途:
BookRecord record = new BookRecord(1, "Java核心技术", "Thinking in Java", new Date());
System.out.println(record); // 输出图书浏览记录的信息
```
阅读全文