Загрузка данных
public class Painter {
private String name;
private String years;
private String styles;
private String country;
private String wiki;
private int paintings;
// Конструктор по умолчанию
public Painter() {
name = "Неизвестно";
years = "0-0";
styles = "Неизвестно";
country = "Неизвестно";
wiki = "";
paintings = 0;
}
// Конструктор с параметрами
public Painter(String name, String years, String styles,
String country, String wiki, int paintings) {
this.name = name;
this.years = years;
this.styles = styles;
this.country = country;
this.wiki = wiki;
this.paintings = paintings;
}
// Конструктор копирования
public Painter(Painter other) {
this.name = other.name;
this.years = other.years;
this.styles = other.styles;
this.country = other.country;
this.wiki = other.wiki;
this.paintings = other.paintings;
}
// Геттеры
public String getName() {
return name;
}
public String getYears() {
return years;
}
public String getStyles() {
return styles;
}
public String getCountry() {
return country;
}
public String getWiki() {
return wiki;
}
public int getPaintings() {
return paintings;
}
// Сеттеры
public void setName(String name) {
this.name = name;
}
public void setYears(String years) {
this.years = years;
}
public void setStyles(String styles) {
this.styles = styles;
}
public void setCountry(String country) {
this.country = country;
}
public void setWiki(String wiki) {
this.wiki = wiki;
}
public void setPaintings(int paintings) {
this.paintings = paintings;
}
// Краткая информация
@Override
public String toString() {
return name + " (" + years + "), страна: " + country
+ ", стили: " + styles
+ ", картин: " + paintings;
}
// Рассказ о художнике
public String getStory() {
return name + " — художник из страны " + country
+ ". Годы жизни: " + years
+ ". Стили живописи: " + styles
+ ". Количество картин: " + paintings
+ ". Страница Википедии: " + wiki;
}
// Количество прожитых лет
public int getLivedYears() {
try {
String[] parts = years.split("-");
if (parts.length != 2) {
return -1;
}
int birth = Integer.parseInt(parts[0].trim());
int death = Integer.parseInt(parts[1].trim());
if (birth <= 0 || death < birth) {
return -1;
}
return death - birth;
} catch (NumberFormatException e) {
return -1;
}
}
// Проверка наличия общего стиля
public boolean hasSameStyle(Painter other) {
if (other == null) {
return false;
}
String[] first = styles.split(",");
String[] second = other.styles.split(",");
for (String s1 : first) {
for (String s2 : second) {
if (s1.trim().equalsIgnoreCase(s2.trim())) {
return true;
}
}
}
return false;
}
}