diff --git a/em-oop/src/EmployeeData.java b/em-oop/src/EmployeeData.java index d69c545..a4486e2 100644 --- a/em-oop/src/EmployeeData.java +++ b/em-oop/src/EmployeeData.java @@ -49,6 +49,11 @@ public class EmployeeData extends BaseData { public void setNmEmployee(String nmEmployee) { this.nmEmployee = nmEmployee; + + if (nmEmployee == null || nmEmployee.strip().isEmpty()) { + System.out.println("社員名が空のため設定できませんでした"); + return; + } } public String getKnEmployee() { @@ -100,13 +105,13 @@ public class EmployeeData extends BaseData { public String getPrimaryKeyValue() { return getIdEmployee(); } - + public boolean isMatchId(String id) { if (id == null || this.idEmployee == null) { return false; } return this.idEmployee.equals(id); - + } } \ No newline at end of file diff --git a/em-oop/src/Main.java b/em-oop/src/Main.java index 0739c03..36e2dd3 100644 --- a/em-oop/src/Main.java +++ b/em-oop/src/Main.java @@ -6,7 +6,7 @@ public class Main { // System.out.println("検索したい社員IDを入力してください(終了する場合は0)"); // String input = scanner.nextLine(); - // BaseData[] employees = new BaseData[5]; + BaseData[] employees = new BaseData[5]; // BaseData employee = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10"); BaseData[] allData = new BaseData[11]; // @@ -23,28 +23,28 @@ public class Main { allData[9] = new DepartmentData("14", "教育事業部"); allData[10] = new DepartmentData("15", "営業企画部"); - String targetDeptId = ""; - - for (int i = 0; i < allData.length; i++) { - - if (allData[i] instanceof DepartmentData) { - DepartmentData dept = (DepartmentData) allData[i]; - - if (dept.getNmDepartment().equals("システム開発事業部")) { - targetDeptId = dept.getIdDepartment(); - break; - } - } - } - - for (int i = 0; i < allData.length; i++) { - if (allData[i] instanceof EmployeeData) { - EmployeeData emp = (EmployeeData) allData[i]; - if (emp.getIdDepartment().equals(targetDeptId)) { - System.out.println(emp.getNmEmployee() + "\t" + emp.getMailAddress()); - } - } - } + // String targetDeptId = ""; + // + // for (int i = 0; i < allData.length; i++) { + // + // if (allData[i] instanceof DepartmentData) { + // DepartmentData dept = (DepartmentData) allData[i]; + // + // if (dept.getNmDepartment().equals("システム開発事業部")) { + // targetDeptId = dept.getIdDepartment(); + // break; + // } + // } + // } + // + // for (int i = 0; i < allData.length; i++) { + // if (allData[i] instanceof EmployeeData) { + // EmployeeData emp = (EmployeeData) allData[i]; + // if (emp.getIdDepartment().equals(targetDeptId)) { + // System.out.println(emp.getNmEmployee() + "\t" + emp.getMailAddress()); + // } + // } + // } // int count = 0; // int countt = 0; @@ -71,9 +71,16 @@ public class Main { // employees[4] = new EmployeeData("10004", "三宅武", "ミタケタケシ", "miya@hoge.jp", "eee", "13"); // // - // + // for (int i = 0; i < employees.length; i++) { + // System.out.println(allData[i]); + // } // System.out.println("現在の社員データ件数:" + EmployeeData.getEmpCount() + "件"); + if (allData[0] instanceof EmployeeData) { + EmployeeData sampleEmp = (EmployeeData) allData[0]; + sampleEmp.setNmEmployee(""); + } + // String serchId1 = "10002"; // System.out.println(serchId1 + "を検索します"); // boolean bo = false;