You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
45 lines
1.2 KiB
import java.time.LocalDate; // 或者 java.util.Date
|
|
|
|
public class Article {
|
|
private String title;
|
|
private String url;
|
|
// 新增字段
|
|
private String author;
|
|
private LocalDate publishDate; // 推荐使用 Java 8 的 LocalDate,也可以用 String 或 Date
|
|
|
|
// 构造函数
|
|
public Article(String title, String url, String author, LocalDate publishDate) {
|
|
this.title = title;
|
|
this.url = url;
|
|
this.author = author;
|
|
this.publishDate = publishDate;
|
|
}
|
|
|
|
// Getter 和 Setter 方法
|
|
public String getAuthor() {
|
|
return author;
|
|
}
|
|
|
|
public void setAuthor(String author) {
|
|
this.author = author;
|
|
}
|
|
|
|
public LocalDate getPublishDate() {
|
|
return publishDate;
|
|
}
|
|
|
|
public void setPublishDate(LocalDate publishDate) {
|
|
this.publishDate = publishDate;
|
|
}
|
|
|
|
// 记得更新 toString() 方法以便在控制台打印时能看到新字段
|
|
@Override
|
|
public String toString() {
|
|
return "Article{" +
|
|
"title='" + title + '\'' +
|
|
", url='" + url + '\'' +
|
|
", author='" + author + '\'' +
|
|
", publishDate=" + publishDate +
|
|
'}';
|
|
}
|
|
}
|