Browse Source

上传文件至 'W9-李思彤-202506050313'

main
lisitong 1 month ago
parent
commit
710d84b6f6
  1. 36
      W9-李思彤-202506050313/Article.java
  2. 38
      W9-李思彤-202506050313/HistoryCommand.java

36
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; }
}

38
W9-李思彤-202506050313/HistoryCommand.java

@ -0,0 +1,38 @@
package model;
import java.util.ArrayList;
import java.util.List;
/**
* 单例模式全局唯一记录用户所有输入命令
*/
public class HistoryCommand {
// 保存所有命令
private final List<String> 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<String> getAllCommand() {
return commandList;
}
}
Loading…
Cancel
Save