Day2_8段階目

This commit is contained in:
m-shimizu
2026-09-24 09:59:31 +09:00
parent 41bf9831a8
commit 64bd81c717
2 changed files with 23 additions and 3 deletions

View File

@@ -8,9 +8,11 @@ public class EmployeeData {
private String password;
private String idDepartment;
private static int empCount = 0;
//引数なしコンストラクタ
public EmployeeData() {
empCount++;
}
//6つの引数をもつコンストラクタ
@@ -29,6 +31,12 @@ public class EmployeeData {
this.setPassword(password);
this.setIdDepartment(idDepartment);
empCount++;
}
public static int getEmpCount() {
return empCount;
}
public String getIdEmployee() {
@@ -44,6 +52,14 @@ public class EmployeeData {
}
public void setNmEmployee(String nmEmployee) {
//8段階目(空文字や空白だけの値が渡された場合は代入しない)
if (nmEmployee == null || nmEmployee.trim().isEmpty()) {
System.out.println("社員名が空のため設定できませんでした");
return;
}
this.nmEmployee = nmEmployee;
}

View File

@@ -14,7 +14,7 @@ public class Main {
Employees[4] = new EmployeeData();
Employees[0].setIdEmployee("10000");
Employees[0].setNmEmployee("山田龍也");
Employees[0].setNmEmployee("");
Employees[0].setKnEmployee("ヤマダタツヤ");
Employees[0].setMailAddress("yamada@hoge.jp");
Employees[0].setPassword("aaa");
@@ -57,6 +57,8 @@ public class Main {
}
System.out.println("現在の社員データ件数:" + EmployeeData.getEmpCount() + "件");
Scanner scanner = new Scanner(System.in);
while(true) {
@@ -77,6 +79,8 @@ public class Main {
found = true;
}
}
if(found == false) {