|
20 | 20 | * 6) Переопределить метод toString с выводом всех полей (не забывайте alt+inset) |
21 | 21 | */ |
22 | 22 | public class SchoolBook extends Book { |
| 23 | + private String authorName; |
| 24 | + private String authorLastName; |
| 25 | + private LocalDate publishDate; |
23 | 26 |
|
| 27 | + public SchoolBook() { |
| 28 | + } |
| 29 | + |
| 30 | + public SchoolBook(String authorName, String authorLastName, LocalDate publishDate) { |
| 31 | + this.authorName = authorName; |
| 32 | + this.authorLastName = authorLastName; |
| 33 | + this.publishDate = publishDate; |
| 34 | + } |
| 35 | + |
| 36 | + public SchoolBook(int numberOfPages, String name, String authorName, String authorLastName, LocalDate publishDate) { |
| 37 | + super(numberOfPages, name); |
| 38 | + this.authorName = authorName; |
| 39 | + this.authorLastName = authorLastName; |
| 40 | + this.publishDate = publishDate; |
| 41 | + } |
| 42 | + |
| 43 | + public String getAuthorName() { |
| 44 | + return authorName; |
| 45 | + } |
| 46 | + |
| 47 | + public void setAuthorName(String authorName) { |
| 48 | + this.authorName = authorName; |
| 49 | + } |
| 50 | + |
| 51 | + public String getAuthorLastName() { |
| 52 | + return authorLastName; |
| 53 | + } |
| 54 | + |
| 55 | + public void setAuthorLastName(String authorLastName) { |
| 56 | + this.authorLastName = authorLastName; |
| 57 | + } |
| 58 | + |
| 59 | + public LocalDate getPublishDate() { |
| 60 | + return publishDate; |
| 61 | + } |
| 62 | + |
| 63 | + public void setPublishDate(LocalDate publishDate) { |
| 64 | + this.publishDate = publishDate; |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public boolean equals(Object o) { |
| 69 | + if (this == o) return true; |
| 70 | + if (!(o instanceof SchoolBook)) return false; |
| 71 | + if (!super.equals(o)) return false; |
| 72 | + SchoolBook that = (SchoolBook) o; |
| 73 | + return authorName.equals(that.authorName) && |
| 74 | + authorLastName.equals(that.authorLastName) && |
| 75 | + publishDate.equals(that.publishDate); |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public int hashCode() { |
| 80 | + return Objects.hash(super.hashCode(), authorName, authorLastName, publishDate); |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public String toString() { |
| 85 | + return "SchoolBook{" + |
| 86 | + "authorName='" + authorName + '\'' + |
| 87 | + ", authorLastName='" + authorLastName + '\'' + |
| 88 | + ", publishDate=" + publishDate + |
| 89 | + '}'; |
| 90 | + } |
24 | 91 | } |
0 commit comments