2 changed files with 62 additions and 0 deletions
@ -0,0 +1,33 @@ |
|||||
|
import java.time.LocalDate; |
||||
|
|
||||
|
public class Article { |
||||
|
private String title; |
||||
|
private String content; |
||||
|
private String url; |
||||
|
|
||||
|
private String author; |
||||
|
private LocalDate publishDate; |
||||
|
|
||||
|
public Article(String title, String content, String url, String author, LocalDate publishDate) { |
||||
|
this.title = title; |
||||
|
this.content = content; |
||||
|
this.url = url; |
||||
|
this.author = author; |
||||
|
this.publishDate = publishDate; |
||||
|
} |
||||
|
|
||||
|
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; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
public class HistoryCommand { |
||||
|
// 用List<String>存储所有历史命令
|
||||
|
private final List<String> commandHistory = new ArrayList<>(); |
||||
|
|
||||
|
// 添加命令
|
||||
|
public void addCommand(String command) { |
||||
|
commandHistory.add(command); |
||||
|
} |
||||
|
|
||||
|
// 获取所有历史命令
|
||||
|
public List<String> getHistory() { |
||||
|
// 可选:返回副本,防止外部修改内部状态
|
||||
|
return new ArrayList<>(commandHistory); |
||||
|
} |
||||
|
|
||||
|
// 打印历史命令
|
||||
|
public void printHistory() { |
||||
|
if (commandHistory.isEmpty()) { |
||||
|
System.out.println("暂无历史命令"); |
||||
|
return; |
||||
|
} |
||||
|
for (int i = 0; i < commandHistory.size(); i++) { |
||||
|
System.out.printf("[%d] %s%n", i + 1, commandHistory.get(i)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue