From f6629e374054a4af5e341ee483c80664c2491dd9 Mon Sep 17 00:00:00 2001 From: zhouzihao Date: Wed, 6 May 2026 23:22:16 +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=E5=91=A8=E6=A2=93=E6=B5=A9202506050319'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- W9周梓浩202506050319/Article.java | 57 +++++++++++++++++++++ W9周梓浩202506050319/HistoryCommand.java | 33 ++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 W9周梓浩202506050319/Article.java create mode 100644 W9周梓浩202506050319/HistoryCommand.java diff --git a/W9周梓浩202506050319/Article.java b/W9周梓浩202506050319/Article.java new file mode 100644 index 0000000..83c5ea8 --- /dev/null +++ b/W9周梓浩202506050319/Article.java @@ -0,0 +1,57 @@ +package com.example.datacollect.model; + +public class Article { + private String title; + private String url; + private String content; + private String author; + private String publishDate; + + public Article(String title, String url, String content,String author,String publishDate) { + this.title = title; + this.url = url; + this.content = content; + this.author=author; + this.publishDate=publishDate; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getAuthor(){return author;} + + public void setAuthor(){this.author=author;} + + public String getPublishDate(){return publishDate;} + + public void setPublishDate(){this.publishDate=publishDate;} + + @Override + public String toString() { + return "Article{" + + "title='" + title + '\'' + + ", url='" + url + '\'' + + '}'; + } +} diff --git a/W9周梓浩202506050319/HistoryCommand.java b/W9周梓浩202506050319/HistoryCommand.java new file mode 100644 index 0000000..dd55484 --- /dev/null +++ b/W9周梓浩202506050319/HistoryCommand.java @@ -0,0 +1,33 @@ +package com.example.datacollect.command; + +import com.example.datacollect.model.Article; +import com.example.datacollect.view.ConsoleView; +import java.util.List; + +public class HistoryCommand implements Command { + private final ConsoleView view; + private final List history; + + public HistoryCommand(ConsoleView view, List history) { + this.view = view; + this.history = history; + } + + @Override + public String getName() { + return "history"; + } + + @Override + public void execute(String[] args, List
articles) { + if (history.isEmpty()){ + view.printInfo("No command has been executed yet."); + } else { + view.printInfo("History commands:"); + for (int i=0; i