/
SofiMut
/
People
Обзор
Документация
Войти
/
SofiMut
/
People
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main/java/PersonBuilder.java
51 строка
1 KB
Sofia Stepanova
first_commit
23 ноя 2025, 11:56
23 ноя 2025, 11:56
eb171d1
Код
Авторство
О чём код?
public class PersonBuilder { private String name; private String surname; private int age; private String city; public Person build() throws IllegalStateException { Person person; if (name == null || surname == null) throw new IllegalStateException("The first or last name is not specified"); if (age > 0) { person = new Person(name, surname); } else { person = new Person(name, surname, age); person.setCity(city); } return person; } public PersonBuilder setName(String name) throws IllegalArgumentException { if (name == null || name.isEmpty()) { throw new IllegalArgumentException("Name not specified"); } else { this.name = name; } return this; } public PersonBuilder setSurname(String surname) throws IllegalArgumentException { if (surname == null || surname.isEmpty()) { throw new IllegalArgumentException("Surname not specified"); } else { this.surname = surname; return this; } } public PersonBuilder setAge(int age) throws IllegalArgumentException { if (age < 0) { throw new IllegalArgumentException("The age should be positive"); } this.age = age; return this; } public PersonBuilder setAddress(String city) { this.city = city; return this; } }