From 5a8c7eb2fd62608b0b2cf2816b729d4eabfb4877 Mon Sep 17 00:00:00 2001 From: m-shimizu <26-m-e-stella-tecnica@it-college.jp> Date: Thu, 24 Sep 2026 15:17:33 +0900 Subject: [PATCH] =?UTF-8?q?Day3=5F7=E6=AE=B5=E9=9A=8E=E7=9B=AE=EF=BC=8B?= =?UTF-8?q?=EF=BC=98=E6=AE=B5=E9=9A=8E=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- em-oop/src/Main.java | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/em-oop/src/Main.java b/em-oop/src/Main.java index 15c9136..7622493 100644 --- a/em-oop/src/Main.java +++ b/em-oop/src/Main.java @@ -63,7 +63,7 @@ public class Main { "13" ); - // + //社員+部署をまとめる配列 BaseData[] allData = new BaseData[11]; // @@ -71,6 +71,7 @@ public class Main { allData[i] = Employees[i]; } + //部署データ6件 DepartmentData dept1 = new DepartmentData(); dept1.setIdDepartment("10"); dept1.setNmDepartment("役員"); @@ -107,10 +108,37 @@ public class Main { allData[10] = dept6; + //全データ表示 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 + "件"); + + //全社員のメールアドレスを表示 + for(int i = 0; i < allData.length; i++) { + if(allData[i] instanceof EmployeeData) { + EmployeeData employeeData = (EmployeeData) allData[i]; + + System.out.println(employeeData.getMailAddress()); + } + } + // Employees[0].setIdEmployee("10000"); // Employees[0].setNmEmployee("山田龍也"); // Employees[0].setKnEmployee("ヤマダタツヤ");