/
Scaramoushe
/
HW5_Task2
Обзор
Документация
Войти
/
Scaramoushe
/
HW5_Task2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/Book.java
75 строк
2 KB
Titov Vladimir
Исправленная версия
09 июл 2026, 20:11
09 июл 2026, 20:11
7262e94
Код
Авторство
О чём код?
public class Book { private String title; // название книги; private int releaseYear; //год выпуска; private Author author; // автор; private int pages; // количество страниц. public Book(String title, int releaseYear, Author author, int pages) { if (title == null || author == null) throw new IllegalArgumentException(); this.title = title; this.releaseYear = releaseYear; this.author = author; this.pages = pages; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public int getReleaseYear() { return releaseYear; } public void setReleaseYear(int releaseYear) { this.releaseYear = releaseYear; } public Author getAuthor() { return author; } public void setAuthor(Author author) { this.author = author; } public int getPages() { return pages; } public void setPages(int pages) { this.pages = pages; } public boolean isBig() { return this.pages > 500; } public boolean matches(String word) { if (word == null) return false; if (this.title.contains(word) || this.author.getName().contains(word) || this.author.getSurname().contains(word)) return true; else return false; } public int estimatePrice() { int price = (int) Math.floor(this.pages * 3 * Math.sqrt(author.getRating())); return Math.max(price, 250); } @Override public String toString() { return "Book{" + "title='" + title + '\'' + ", releaseYear=" + releaseYear + ", author=" + author.getName() + " " + author.getSurname() + ", pages=" + pages + ", isBig=" + isBig() + ", estimatePrice=" + estimatePrice() + '}'; } }