[POO] created validations
This commit is contained in:
parent
98ff46a5db
commit
2e59a60b42
|
@ -17,9 +17,10 @@ public class Person {
|
|||
return this.name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
if (name == null || name.isEmpty()) {
|
||||
if (name == null || name.isEmpty())
|
||||
throw new IllegalArgumentException("Name cannot be null or empty");
|
||||
}
|
||||
if (!name.matches("^[a-zA-Z ]+$"))
|
||||
throw new IllegalArgumentException("Name must only contain letters and spaces");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
@ -27,6 +28,8 @@ public class Person {
|
|||
return this.cc;
|
||||
}
|
||||
public void setCc(int cc) {
|
||||
if (String.valueOf(cc).length() != 8)
|
||||
throw new IllegalArgumentException("CC must have 8 digits");
|
||||
this.cc = cc;
|
||||
}
|
||||
|
||||
|
@ -34,9 +37,8 @@ public class Person {
|
|||
return this.birthDate;
|
||||
}
|
||||
public void setBirthDate(DateYMD birthDate) {
|
||||
if (birthDate == null) {
|
||||
if (birthDate == null)
|
||||
throw new IllegalArgumentException("Birth date cannot be null");
|
||||
}
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,10 @@ public class Professor extends Person {
|
|||
return this.category;
|
||||
}
|
||||
public void setCategory(String category) {
|
||||
if (category == null || category.isEmpty()) {
|
||||
if (category == null || category.isEmpty())
|
||||
throw new IllegalArgumentException("Category cannot be null or empty");
|
||||
}
|
||||
if (!(category.equals("Auxiliar") || category.equals("Associado") || category.equals("Catedrático")))
|
||||
throw new IllegalArgumentException("Invalid category");
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
|
@ -26,9 +27,10 @@ public class Professor extends Person {
|
|||
return this.department;
|
||||
}
|
||||
public void setDepartment(String department) {
|
||||
if (department == null || department.isEmpty()) {
|
||||
if (department == null || department.isEmpty())
|
||||
throw new IllegalArgumentException("Department cannot be null or empty");
|
||||
}
|
||||
if (!department.matches("^[a-zA-Z ]+$"))
|
||||
throw new IllegalArgumentException("Invalid department");
|
||||
this.department = department;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ public class DateYMD {
|
|||
return year % 100 == 0 ? year % 400 == 0 : year % 4 == 0;
|
||||
}
|
||||
|
||||
static boolean validDate(int day, int month, int year) {
|
||||
public static boolean validDate(int day, int month, int year) {
|
||||
return day >= 1 && day <= monthDays(month, year);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue