You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
package hs.fulda.de.ci.exam.project;
|
|
|
|
import java.util.Date;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
|
|
public class Passenger {
|
|
private String name;
|
|
private String passportNumber;
|
|
private Date dateOfBirth;
|
|
|
|
public Passenger(String name, String passportNumber, Date dateOfBirth) {
|
|
this.name = name;
|
|
this.passportNumber = passportNumber;
|
|
this.dateOfBirth = dateOfBirth;
|
|
}
|
|
|
|
public void validateName() {
|
|
if(name.isBlank()) {
|
|
throw new RuntimeException(("Name cannot be null or empty"));
|
|
}
|
|
}
|
|
|
|
public void validatePassportNumber() {
|
|
Pattern pattern = Pattern.compile("^(?!^0+$)[a-zA-Z0-9]{3,20}$");
|
|
Matcher matcher = pattern.matcher(this.passportNumber);
|
|
if(passportNumber.isBlank()){
|
|
throw new RuntimeException("Passport number cannot be blank");
|
|
}
|
|
if(!matcher.matches()){
|
|
throw new RuntimeException("Passport number cannot be null or empty");
|
|
}
|
|
}
|
|
|
|
public void validateDate() {
|
|
if(dateOfBirth.equals(null)) {
|
|
throw new RuntimeException("Birthdate cannot be null");
|
|
}
|
|
}
|
|
}
|