9段階目(チェックをもう1つの項目にも広げ、コンストラクタと統一しよう)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,11 @@ public class Main {
|
||||
emp.setNmEmployee(" ");
|
||||
System.out.println(emp);
|
||||
|
||||
System.out.println();
|
||||
|
||||
EmployeeData emptyEmployee = new EmployeeData("", "", "", "", "", "");
|
||||
System.out.println(emptyEmployee);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user