diff --git a/W9/.gitignore b/W9/.gitignore new file mode 100644 index 0000000..0925d0a --- /dev/null +++ b/W9/.gitignore @@ -0,0 +1,4 @@ +*.jar +*.jar +*.class +*.log \ No newline at end of file diff --git a/W9/Article.java b/W9/Article.java new file mode 100644 index 0000000..bcd04bf --- /dev/null +++ b/W9/Article.java @@ -0,0 +1,75 @@ +package com.example.datacollect.model; + +import java.time.LocalDate; + +public class Article { + private String title; + private String url; + private String content; + private String author; + private LocalDate publishDate; + + public Article(String title, String url, String content) { + this.title = title; + this.url = url; + this.content = content; + } + + public Article(String title, String url, String content, String author, LocalDate 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(String author) { + this.author = author; + } + + public LocalDate getPublishDate() { + return publishDate; + } + + public void setPublishDate(LocalDate publishDate) { + this.publishDate = publishDate; + } + + @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..515671e --- /dev/null +++ b/W9/HistoryCommand.java @@ -0,0 +1,45 @@ +package com.example.datacollect.command; + +import com.example.datacollect.model.Article; +import com.example.datacollect.view.ConsoleView; +import java.util.ArrayList; +import java.util.List; + +public class HistoryCommand implements Command { + private static final List commandHistory = new ArrayList<>(); + private final ConsoleView view; + + public HistoryCommand(ConsoleView view) { + this.view = view; + } + + @Override + public String getName() { + return "history"; + } + + @Override + public void execute(String[] args, List
articles) { + if (commandHistory.isEmpty()) { + view.printInfo("No command history."); + return; + } + + view.printInfo("Command History:"); + for (int i = 0; i < commandHistory.size(); i++) { + view.printInfo((i + 1) + ". " + commandHistory.get(i)); + } + } + + public static void addCommand(String command) { + commandHistory.add(command); + } + + public static List getCommandHistory() { + return new ArrayList<>(commandHistory); + } + + public static void clearHistory() { + commandHistory.clear(); + } +} \ No newline at end of file diff --git a/W9/README.md b/W9/README.md new file mode 100644 index 0000000..f8af0e4 --- /dev/null +++ b/W9/README.md @@ -0,0 +1,17 @@ +# DataCollect 教学项目 — 最小可运行版本 + +这是一个最小可用的 Java CLI 演示工程,目标:打印帮助信息以验证运行环境。 + +构建: +```bash +mvn -q package +``` + +运行(示例): +```bash +java -jar target/datacollect-cli-0.1.0-jar-with-dependencies.jar --help +``` + +项目结构(最小): +- `src/main/java/com/example/datacollect/Main.java` — CLI 入口,打印帮助 +- `pom.xml` — Maven 构建配置,生成可执行 jar diff --git a/W9/datacollect-cli-0.1.0-jar-with-dependencies.jar b/W9/datacollect-cli-0.1.0-jar-with-dependencies.jar new file mode 100644 index 0000000..27a079d Binary files /dev/null and b/W9/datacollect-cli-0.1.0-jar-with-dependencies.jar differ diff --git a/W9/pom.xml b/W9/pom.xml new file mode 100644 index 0000000..f07fa5a --- /dev/null +++ b/W9/pom.xml @@ -0,0 +1,45 @@ + + 4.0.0 + com.example + datacollect-cli + 0.1.0 + + 11 + 11 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + org.apache.maven.plugins + maven-assembly-plugin + 3.3.0 + + + + com.example.datacollect.Main + + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + +