zhangkunqiu 1 month ago
parent
commit
c012e7407c
  1. 33
      w9/Article.java
  2. 29
      w9/HistoryCommand.java

33
w9/Article.java

@ -0,0 +1,33 @@
import java.time.LocalDate;
public class Article {
private String title;
private String content;
private String url;
private String author;
private LocalDate publishDate;
public Article(String title, String content, String url, String author, LocalDate publishDate) {
this.title = title;
this.content = content;
this.url = url;
this.author = author;
this.publishDate = publishDate;
}
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;
}
}

29
w9/HistoryCommand.java

@ -0,0 +1,29 @@
import java.util.ArrayList;
import java.util.List;
public class HistoryCommand {
// 用List<String>存储所有历史命令
private final List<String> commandHistory = new ArrayList<>();
// 添加命令
public void addCommand(String command) {
commandHistory.add(command);
}
// 获取所有历史命令
public List<String> getHistory() {
// 可选:返回副本,防止外部修改内部状态
return new ArrayList<>(commandHistory);
}
// 打印历史命令
public void printHistory() {
if (commandHistory.isEmpty()) {
System.out.println("暂无历史命令");
return;
}
for (int i = 0; i < commandHistory.size(); i++) {
System.out.printf("[%d] %s%n", i + 1, commandHistory.get(i));
}
}
}
Loading…
Cancel
Save