From 710d84b6f62b3a04162bc73f5c855c456a4f37d3 Mon Sep 17 00:00:00 2001 From: lisitong <3312630472@qq.com> Date: Thu, 7 May 2026 15:05:00 +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-=E6=9D=8E=E6=80=9D=E5=BD=A4-202506050313'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- W9-李思彤-202506050313/Article.java | 36 ++++++++++++++++++ W9-李思彤-202506050313/HistoryCommand.java | 38 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 W9-李思彤-202506050313/Article.java create mode 100644 W9-李思彤-202506050313/HistoryCommand.java diff --git a/W9-李思彤-202506050313/Article.java b/W9-李思彤-202506050313/Article.java new file mode 100644 index 0000000..82be1b4 --- /dev/null +++ b/W9-李思彤-202506050313/Article.java @@ -0,0 +1,36 @@ +package model; + +import java.util.Date; + +public class Article { + private String title; + private String content; + private String url; + // 新增字段 + private String author; + private Date publishDate; + + // 无参构造 + public Article() {} + + // 全参构造(方便赋值) + public Article(String title, String content, String url, String author, Date publishDate) { + this.title = title; + this.content = content; + this.url = url; + this.author = author; + this.publishDate = publishDate; + } + + // getter & setter + public String getTitle() { return title; } + public void setTitle(String title) { this.title = title; } + public String getContent() { return content; } + public void setContent(String content) { this.content = content; } + public String getUrl() { return url; } + public void setUrl(String url) { this.url = url; } + public String getAuthor() { return author; } + public void setAuthor(String author) { this.author = author; } + public Date getPublishDate() { return publishDate; } + public void setPublishDate(Date publishDate) { this.publishDate = publishDate; } +} \ No newline at end of file diff --git a/W9-李思彤-202506050313/HistoryCommand.java b/W9-李思彤-202506050313/HistoryCommand.java new file mode 100644 index 0000000..affb14c --- /dev/null +++ b/W9-李思彤-202506050313/HistoryCommand.java @@ -0,0 +1,38 @@ +package model; + +import java.util.ArrayList; +import java.util.List; + +/** + * 单例模式:全局唯一记录用户所有输入命令 + */ +public class HistoryCommand { + // 保存所有命令 + private final List commandList; + + // 单例实例 + private static HistoryCommand instance; + + // 私有构造 + private HistoryCommand() { + commandList = new ArrayList<>(); + } + + // 获取唯一实例 + public static HistoryCommand getInstance() { + if (instance == null) { + instance = new HistoryCommand(); + } + return instance; + } + + // 添加命令 + public void addCommand(String command) { + commandList.add(command); + } + + // 获取所有历史命令 + public List getAllCommand() { + return commandList; + } +} \ No newline at end of file