Browse Source

上传文件至 'W9周梓浩202506050319'

main
zhouzihao 1 month ago
parent
commit
f6629e3740
  1. 57
      W9周梓浩202506050319/Article.java
  2. 33
      W9周梓浩202506050319/HistoryCommand.java

57
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 + '\''
+ '}';
}
}

33
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<String> history;
public HistoryCommand(ConsoleView view, List<String> history) {
this.view = view;
this.history = history;
}
@Override
public String getName() {
return "history";
}
@Override
public void execute(String[] args, List<Article> articles) {
if (history.isEmpty()){
view.printInfo("No command has been executed yet.");
} else {
view.printInfo("History commands:");
for (int i=0; i<history.size(); i++){
String s = history.get(i);
view.printInfo((i+1) + "." + s);
}
}
}
}
Loading…
Cancel
Save