3日目 段階4 小澤

This commit is contained in:
2026-09-18 14:33:17 +09:00
parent a1b84b16f1
commit 7ebf5dec70
3 changed files with 54 additions and 52 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 extends BaceData { public class EmployeeData extends BaseData {
private String idEmployee; private String idEmployee;
private String nmEmployee; private String nmEmployee;
private String knEmployee; private String knEmployee;
@@ -29,7 +29,7 @@ public class EmployeeData extends BaceData {
@Override @Override
public String getPrimaryKeyValue() { public String getPrimaryKeyValue() {
return getIdEmployee(); return idEmployee;
} }
@@ -50,22 +50,6 @@ public class EmployeeData extends BaceData {
public EmployeeData(String idEmployee, String nmEmployee, String knEmployee, String mailAddress, String password, public EmployeeData(String idEmployee, String nmEmployee, String knEmployee, String mailAddress, String password,
String idDepartment) { String idDepartment) {
nmEmployee = nmEmployee.strip();
int nmNum = nmEmployee.length();
idEmployee = idEmployee.strip();
int idNum = idEmployee.length();
if (nmNum == 0) {
System.out.println("社員名が空のため設定できませんでした");
}
if (idNum == 0) {
System.out.println("社員IDが空のため設定できませんでした");
}
if (nmNum > 0 && idNum > 0) {
this.setIdEmployee(idEmployee); this.setIdEmployee(idEmployee);
this.setNmEmployee(nmEmployee); this.setNmEmployee(nmEmployee);
this.setKnEmployee(knEmployee); this.setKnEmployee(knEmployee);
@@ -73,8 +57,6 @@ public class EmployeeData extends BaceData {
this.setPassword(password); this.setPassword(password);
this.setIdDepartment(idDepartment); this.setIdDepartment(idDepartment);
empCount++; empCount++;
}
} }
public String getIdEmployee() { public String getIdEmployee() {
@@ -82,16 +64,29 @@ public class EmployeeData extends BaceData {
} }
public void setIdEmployee(String idEmployee) { public void setIdEmployee(String idEmployee) {
idEmployee = idEmployee.strip();
int idNum = idEmployee.length();
this.idEmployee = idEmployee; if (idNum == 0) {
System.out.println("社員IDが空のため設定できませんでした");
} else {
this.idEmployee = idEmployee;
}
} }
public String getNmEmployee() { public String getNmEmployee() {
return nmEmployee; return nmEmployee;
} }
public void setNmEmployee(String nmEMployee) { public void setNmEmployee(String nmEmployee) {
this.nmEmployee = nmEMployee; nmEmployee = nmEmployee.strip();
int nmNum = nmEmployee.length();
if (nmNum == 0) {
System.out.println("社員名が空のため設定できませんでした");
} else {
this.nmEmployee = nmEmployee;
}
} }
public String getKnEmployee() { public String getKnEmployee() {

View File

@@ -1,5 +1,3 @@
import java.util.Scanner;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
EmployeeData[] employees = new EmployeeData[5]; EmployeeData[] employees = new EmployeeData[5];
@@ -37,34 +35,34 @@ public class Main {
employees[4].setPassword("eee"); employees[4].setPassword("eee");
employees[4].setIdDepartment("13"); employees[4].setIdDepartment("13");
// System.out.println(employees[1].toCSV()); System.out.println(employees[0].toCSV());
// System.out.println(employees[1].getPrimaryKeyValue()); System.out.println(employees[0].getPrimaryKeyValue());
Scanner sc = new Scanner(System.in); // Scanner sc = new Scanner(System.in);
//
//
for (int i = 0; i < employees.length; i++) { // for (int i = 0; i < employees.length; i++) {
System.out.println("検索したい社員IDを入力してください(終了する場合は0)"); // System.out.println("検索したい社員IDを入力してください(終了する場合は0)");
String id = sc.nextLine(); // String id = sc.nextLine();
boolean result = false; // boolean result = false;
//
if(id.equals("0")) { // if(id.equals("0")) {
System.out.println("システムを終了します"); // System.out.println("システムを終了します");
break; // break;
} // }
if (employees[i].isMatchId(id)) { // if (employees[i].isMatchId(id)) {
result = true; // result = true;
employees[i].showInfo(); // employees[i].showInfo();
//
} // }
//
//
if(result==false) { // if(result==false) {
System.out.println("該当する社員が見つかりませんでした"); // System.out.println("該当する社員が見つかりませんでした");
} // }
//
} // }
} // }
// System.out.println("99999を検索します"); // System.out.println("99999を検索します");
@@ -101,5 +99,6 @@ public class Main {
// System.out.println(employee.idDepartment); // System.out.println(employee.idDepartment);
} }
}