7段階目(staticで社員データの件数を数えよう)

This commit is contained in:
s-sakiyama
2026-09-15 14:03:03 +09:00
parent f143cf7ec2
commit 3b6b23c883
2 changed files with 18 additions and 6 deletions

View File

@@ -6,10 +6,12 @@ public class EmployeeData {
private String mailAddress;
private String password;
private String idDepartment;
private static int empCount = 0;
static final String COMPANY_NAME = "Rhizome";
//コンストラクタ
public EmployeeData() {
empCount++;
}
//引数ありコンストラクタ
@@ -21,6 +23,9 @@ public class EmployeeData {
this.setMailAddress(mailAddress);
this.setPassword(password);
this.setIdDepartment(idDepartment);
empCount++;
}
@Override
@@ -78,4 +83,8 @@ public class EmployeeData {
this.idDepartment = idDepartment;
}
public static int getEmpCount() {
return empCount;
}
}

View File

@@ -1,17 +1,19 @@
public class Main {
public static void main(String[] args) {
EmployeeData employee = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ",
"yamada@hoge.jp", "aaa", "10");
System.out.println(employee);
System.out.println("会社名:" + EmployeeData.COMPANY_NAME);
// EmployeeData employee = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ",
// "yamada@hoge.jp", "aaa", "10");
// System.out.println(employee);
//
// System.out.println();
EmployeeData[] employees = new EmployeeData[5];
for (int i = 0; i < employees.length; i++) {
employees[i] = new EmployeeData();
}
System.out.println();
employees[0].setIdEmployee("10000");
employees[0].setNmEmployee("山田龍也");
employees[0].setKnEmployee("ヤマダタツヤ");
@@ -51,6 +53,7 @@ public class Main {
System.out.println(e);
;
}
System.out.println("現在の社員のデータ件数:" + EmployeeData.getEmpCount() + "件");
}