diff --git a/w9/Article.java b/w9/Article.java new file mode 100644 index 0000000..0d10469 --- /dev/null +++ b/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; + } + +} \ No newline at end of file diff --git a/w9/HistoryCommand.java b/w9/HistoryCommand.java new file mode 100644 index 0000000..7fcb234 --- /dev/null +++ b/w9/HistoryCommand.java @@ -0,0 +1,29 @@ +import java.util.ArrayList; +import java.util.List; + +public class HistoryCommand { + // 用List存储所有历史命令 + private final List commandHistory = new ArrayList<>(); + + // 添加命令 + public void addCommand(String command) { + commandHistory.add(command); + } + + // 获取所有历史命令 + public List 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)); + } + } +} \ No newline at end of file