Day3_7段階目+8段階目
This commit is contained in:
@@ -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("ヤマダタツヤ");
|
||||
|
||||
Reference in New Issue
Block a user