2 changed files with 91 additions and 0 deletions
@ -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 + |
|||
'}'; |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
// 1. 历史记录管理内部类 (或者保持独立文件)
|
|||
// 注意:如果这是单独的文件,这个类不需要 public,或者你可以把它拆出去
|
|||
class CommandHistory { |
|||
// 【修正点】补全了缺失的 history 变量定义
|
|||
private static final List<String> history = new ArrayList<>(); |
|||
|
|||
public static void add(String command) { |
|||
history.add(command); |
|||
} |
|||
|
|||
public static List<String> getHistory() { |
|||
return history; |
|||
} |
|||
} |
|||
|
|||
// 2. 具体的命令实现
|
|||
// 【修正点】确保文件名也是 HistoryCommand.java
|
|||
public class HistoryCommand implements Command { |
|||
|
|||
@Override |
|||
public String getName() { |
|||
return "hist"; |
|||
} |
|||
|
|||
@Override |
|||
public void execute(String[] args, List<Article> 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); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue