-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.java
More file actions
43 lines (33 loc) · 1.29 KB
/
Copy pathBook.java
File metadata and controls
43 lines (33 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.startjava.graduation;
import java.time.Year;
public class Book {
private static final int MIN_YEAR = 1800;
private String author;
private String title;
private Year publishedYear;
public Book(String author, String title, Year publicationYear) {
if (author == null || author.isBlank()) {
throw new IllegalArgumentException("Автор не может быть пустым");
}
if (title == null || title.isBlank()) {
throw new IllegalArgumentException("Название не может быть пустым");
}
if (publicationYear == null) {
throw new IllegalArgumentException("Год издания не может быть пустым");
}
if (publicationYear.isBefore(Year.of(MIN_YEAR)) || publicationYear.isAfter(Year.now())) {
throw new IllegalArgumentException(
"Год издания должен быть между " + MIN_YEAR + " и " + Year.now());
}
this.author = author;
this.title = title;
this.publishedYear = publicationYear;
}
public String getTitle() {
return title;
}
@Override
public String toString() {
return author + ", " + title + ", " + publishedYear;
}
}