diff --git a/w9/Article.java b/w9/Article.java new file mode 100644 index 0000000..f48d3e1 --- /dev/null +++ b/w9/Article.java @@ -0,0 +1,34 @@ +package Article; + +import java.time.LocalDate; + +public class Article { + private String title; + private String content; + private String author; + private LocalDate publishDate; + + public Article(String title, String content, String author, LocalDate publishDate) { + this.title = title; + this.content = content; + this.author = author; + this.publishDate = publishDate; + } + + // getters and setters + public String getTitle() { return title; } + public String getContent() { return content; } + public String getAuthor() { return author; } + public LocalDate getPublishDate() { return publishDate; } + + public void setTitle(String title) { this.title = title; } + public void setContent(String content) { this.content = content; } + public void setAuthor(String author) { this.author = author; } + public void setPublishDate(LocalDate publishDate) { this.publishDate = publishDate; } + + @Override + public String toString() { + return String.format("Article{title='%s', author='%s', publishDate=%s}", + title, author, publishDate); + } +} \ No newline at end of file diff --git a/w9/HistoryCommand.java b/w9/HistoryCommand.java new file mode 100644 index 0000000..2fc4e56 --- /dev/null +++ b/w9/HistoryCommand.java @@ -0,0 +1,40 @@ +package Article; + +import java.util.ArrayList; +import java.util.List; + +public class HistoryCommand { + private List commandHistory; + + public HistoryCommand() { + this.commandHistory = new ArrayList<>(); + } + + public void addCommand(String command) { + if (command != null && !command.trim().isEmpty()) { + commandHistory.add(command); + } + } + + public List getAllCommands() { + return new ArrayList<>(commandHistory); // 返回副本,保护内部数据 + } + + public String getLastCommand() { + return commandHistory.isEmpty() ? null : commandHistory.get(commandHistory.size() - 1); + } + + public void printHistory() { + for (int i = 0; i < commandHistory.size(); i++) { + System.out.println((i + 1) + ". " + commandHistory.get(i)); + } + } + + public void clear() { + commandHistory.clear(); + } + + public int size() { + return commandHistory.size(); + } +} \ No newline at end of file diff --git a/w9/ai询问.txt b/w9/ai询问.txt new file mode 100644 index 0000000..06d7405 Binary files /dev/null and b/w9/ai询问.txt differ