4段階目(BaseDataを作り、EmployeeDataに継承させよう)

This commit is contained in:
s-sakiyama
2026-09-16 13:31:36 +09:00
parent e8648e7d8b
commit 9c3605cf87
3 changed files with 26 additions and 6 deletions

8
em-oop/src/BaseData.java Normal file
View File

@@ -0,0 +1,8 @@
public abstract class BaseData {
public abstract String toString();
public abstract String toCSV();
public abstract String getPrimaryKeyValue();
}

View File

@@ -1,5 +1,5 @@
public class EmployeeData { public class EmployeeData extends BaseData {
private String idEmployee; private String idEmployee;
private String nmEmployee; private String nmEmployee;
private String knEmployee; private String knEmployee;
@@ -112,4 +112,15 @@ public class EmployeeData {
return true; return true;
} }
@Override
public String toCSV() {
return getIdEmployee() + "," + getNmEmployee() + "," + getKnEmployee() + ","
+ getMailAddress() + "," + getPassword() + "," + getIdDepartment();
}
@Override
public String getPrimaryKeyValue() {
return this.idEmployee;
}
} }

View File

@@ -4,11 +4,12 @@ public class Main {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("会社名:" + EmployeeData.COMPANY_NAME); System.out.println("会社名:" + EmployeeData.COMPANY_NAME);
// EmployeeData employee = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", EmployeeData employee = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ",
// "yamada@hoge.jp", "aaa", "10"); "yamada@hoge.jp", "aaa", "10");
// System.out.println(employee); System.out.println(employee.toCSV());
// System.out.println(employee.getPrimaryKeyValue());
// System.out.println();
System.out.println();
EmployeeData[] employees = new EmployeeData[5]; EmployeeData[] employees = new EmployeeData[5];
for (int i = 0; i < employees.length; i++) { for (int i = 0; i < employees.length; i++) {