From e0c134029d7c1e2d8f820a8868e04d6379dcf463 Mon Sep 17 00:00:00 2001 From: wangbo <1248863822@qq.com> Date: Wed, 6 May 2026 20:55:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20'w9'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w9/Article.java | 45 +++++++++++++++++++++++++++++++++++++++++ w9/HistoryCommand.java | 46 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 w9/Article.java create mode 100644 w9/HistoryCommand.java diff --git a/w9/Article.java b/w9/Article.java new file mode 100644 index 0000000..94beec8 --- /dev/null +++ b/w9/Article.java @@ -0,0 +1,45 @@ +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 + + '}'; + } +} \ No newline at end of file diff --git a/w9/HistoryCommand.java b/w9/HistoryCommand.java new file mode 100644 index 0000000..30182b3 --- /dev/null +++ b/w9/HistoryCommand.java @@ -0,0 +1,46 @@ +import java.util.ArrayList; +import java.util.List; + +// 1. 历史记录管理内部类 (或者保持独立文件) +// 注意:如果这是单独的文件,这个类不需要 public,或者你可以把它拆出去 +class CommandHistory { + // 【修正点】补全了缺失的 history 变量定义 + private static final List history = new ArrayList<>(); + + public static void add(String command) { + history.add(command); + } + + public static List getHistory() { + return history; + } +} + +// 2. 具体的命令实现 +// 【修正点】确保文件名也是 HistoryCommand.java +public class HistoryCommand implements Command { + + @Override + public String getName() { + return "hist"; + } + + @Override + public void execute(String[] args, List
articles) { + // 1. 记录本次输入 + // 【修正点】去掉了多余的 "delimiter:" 和 "x:" 标记 + String currentInput = String.join(" ", args); + CommandHistory.add(currentInput); + + // 2. 打印题目要求的AI审计提示词 + System.out.println("AI 架构审计:将类名发给 AI,指令:"); + System.out.println("\"作为Java架构审计师,请检查我的MVC三层划分是否存在越权行为?\""); + System.out.println("--------------------------------"); + + // 3. 显示所有历史记录 + System.out.println("历史命令记录:"); + for (String cmd : CommandHistory.getHistory()) { + System.out.println("- " + cmd); + } + } +} \ No newline at end of file