9段階目(チェックをもう1つの項目にも広げ、コンストラクタと統一しよう)

This commit is contained in:
s-sakiyama
2026-09-15 14:44:43 +09:00
parent 968c5094a4
commit d88468306f
2 changed files with 16 additions and 3 deletions

View File

@@ -40,6 +40,8 @@ public class EmployeeData {
}
public void setIdEmployee(String idEmployee) {
if (!check(idEmployee, "社員ID"))
return;
this.idEmployee = idEmployee;
}
@@ -48,10 +50,8 @@ public class EmployeeData {
}
public void setNmEmployee(String nmEmployee) {
if (nmEmployee == null || nmEmployee.strip().length() == 0) {
System.out.println("社員名が空のため設定できませんでした");
if (!check(nmEmployee, "社員名"))
return;
}
this.nmEmployee = nmEmployee;
}
@@ -90,4 +90,12 @@ public class EmployeeData {
public static int getEmpCount() {
return empCount;
}
private boolean check(String str, String stringName) {
if (str == null || str.strip().length() == 0) {
System.out.println(stringName + "が空のため設定できませんでした");
return false;
}
return true;
}
}