diff --git a/em-oop/src/Main.java b/em-oop/src/Main.java index 7622493..dff8f79 100644 --- a/em-oop/src/Main.java +++ b/em-oop/src/Main.java @@ -108,34 +108,62 @@ public class Main { allData[10] = dept6; + //6段階目 //全データ表示 - for (int i = 0; i < allData.length; i++) { - System.out.println(allData[i]); - } +// for (int i = 0; i < allData.length; i++) { +// System.out.println(allData[i]); +// } - //7段階目:instanceofで型を確認しよう - int employeeCount = 0; - int departmentCount = 0; - - for(int i = 0; i < allData.length; i++) { - if(allData[i] instanceof EmployeeData) { - employeeCount++; - } - - if(allData[i] instanceof DepartmentData) { - departmentCount++; - } - } - - System.out.println("社員データ" + employeeCount + "件"); - System.out.println("部署データ" + departmentCount + "件"); + //7段階目:instanceofで件数を数える +// int employeeCount = 0; +// int departmentCount = 0; +// +// for(int i = 0; i < allData.length; i++) { +// if(allData[i] instanceof EmployeeData) { +// employeeCount++; +// } +// +// if(allData[i] instanceof DepartmentData) { +// departmentCount++; +// } +// } +// +// System.out.println("社員データ" + employeeCount + "件"); +// System.out.println("部署データ" + departmentCount + "件"); + //8段階目 //全社員のメールアドレスを表示 - for(int i = 0; i < allData.length; i++) { +// for(int i = 0; i < allData.length; i++) { +// if(allData[i] instanceof EmployeeData) { +// EmployeeData employeeData = (EmployeeData) allData[i]; +// +// System.out.println(employeeData.getMailAddress()); +// } +// } + + //部署名から社員を検索 + String targetDepartmentId = null; + + for(int i = 0; i < allData.length;i++) { + if(allData[i] instanceof DepartmentData) { + DepartmentData departmentData = (DepartmentData) allData[i]; + + if(departmentData.getNmDepartment().equals("システム開発事業部")) { + + targetDepartmentId = departmentData.getIdDepartment(); + + } + } + } + + for (int i = 0; i < allData.length; i++) { if(allData[i] instanceof EmployeeData) { EmployeeData employeeData = (EmployeeData) allData[i]; - System.out.println(employeeData.getMailAddress()); + if(employeeData.getIdDepartment().equals(targetDepartmentId)) { + + System.out.println(employeeData.getNmEmployee() + "\t" + employeeData.getMailAddress()); + } } }