3 changed files with 74 additions and 0 deletions
@ -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); |
|||
} |
|||
} |
|||
@ -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(); |
|||
} |
|||
} |
|||
Binary file not shown.
Loading…
Reference in new issue