From 8ea4f36ebc99cd5047f53259de49509f5220b088 Mon Sep 17 00:00:00 2001 From: Qsivcm26l Date: Wed, 10 May 2023 12:44:45 +0800 Subject: [PATCH] ADD file via upload --- src/Poetry.java | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/Poetry.java diff --git a/src/Poetry.java b/src/Poetry.java new file mode 100644 index 0000000..2f16ee3 --- /dev/null +++ b/src/Poetry.java @@ -0,0 +1,83 @@ +package test; + +import java.util.ArrayList; +import java.util.Objects; + +public class Poetry { + // 古诗id,自动递增填充 + private static Integer poetryCount = 0; + private String AId; + // 古诗名 + private String name; + //所属诗人(朝代-人名) + private Poet poet; + //古诗内容 + private ArrayList content; + //是否已经阅读过 + private Boolean learned = false; + + public Poetry(Poet poet,String name, ArrayList content){ + this.poet = poet; + this.name = name; + this.content = content; + poetryCount += 1; + this.AId = poetryCount.toString(); + } + + public Poetry(ArrayList content) { + this.content = content; + poetryCount += 1; + this.AId = poetryCount.toString(); + } + + public Poet getPoet() { + return poet; + } + + public String getName() { + return name; + } + + public ArrayList getContent() { + return content; + } + + public Boolean getLearned() { + return learned; + } + public String getAId(){ + return AId; + } + public void setLearned(Boolean learned){ + this.learned=learned; + } + + @Override + public String toString() { + StringBuffer contentString = new StringBuffer(); + for(String i: this.content){ + contentString.append(i + '\n'); + } + return this.name + '\n' + + "(" + this.poet.getDynasty() + ")" + this.poet.getName() + '\n' + + contentString + '\n'; + } + + public void showContents(){ + StringBuffer contentString = new StringBuffer(); + for(String i: this.content){ + contentString.append(i + '\n'); + } + System.out.println(contentString + "\n"); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Poetry poetry = (Poetry) o; + return Objects.equals(AId, poetry.AId) && Objects.equals(name, poetry.name) && Objects.equals(poet, poetry.poet) && Objects.equals(content, poetry.content) && Objects.equals(learned, poetry.learned); + } + +} +