Browse Source

上传文件至 'w9'

main
Yuanruirui 1 month ago
parent
commit
2632f76b05
  1. 34
      w9/Article.java
  2. 40
      w9/HistoryCommand.java
  3. BIN
      w9/ai询问.txt

34
w9/Article.java

@ -0,0 +1,34 @@
package Article;
import java.time.LocalDate;
public class Article {
private String title;
private String content;
private String author;
private LocalDate publishDate;
public Article(String title, String content, String author, LocalDate publishDate) {
this.title = title;
this.content = content;
this.author = author;
this.publishDate = publishDate;
}
// getters and setters
public String getTitle() { return title; }
public String getContent() { return content; }
public String getAuthor() { return author; }
public LocalDate getPublishDate() { return publishDate; }
public void setTitle(String title) { this.title = title; }
public void setContent(String content) { this.content = content; }
public void setAuthor(String author) { this.author = author; }
public void setPublishDate(LocalDate publishDate) { this.publishDate = publishDate; }
@Override
public String toString() {
return String.format("Article{title='%s', author='%s', publishDate=%s}",
title, author, publishDate);
}
}

40
w9/HistoryCommand.java

@ -0,0 +1,40 @@
package Article;
import java.util.ArrayList;
import java.util.List;
public class HistoryCommand {
private List<String> commandHistory;
public HistoryCommand() {
this.commandHistory = new ArrayList<>();
}
public void addCommand(String command) {
if (command != null && !command.trim().isEmpty()) {
commandHistory.add(command);
}
}
public List<String> getAllCommands() {
return new ArrayList<>(commandHistory); // 返回副本,保护内部数据
}
public String getLastCommand() {
return commandHistory.isEmpty() ? null : commandHistory.get(commandHistory.size() - 1);
}
public void printHistory() {
for (int i = 0; i < commandHistory.size(); i++) {
System.out.println((i + 1) + ". " + commandHistory.get(i));
}
}
public void clear() {
commandHistory.clear();
}
public int size() {
return commandHistory.size();
}
}

BIN
w9/ai询问.txt

Binary file not shown.
Loading…
Cancel
Save