7段階目(IDが一致するか調べるメソッドを作ろう)
This commit is contained in:
@@ -35,6 +35,19 @@ public class EmployeeData {
|
|||||||
+ "\t" + this.password + "\t" + this.idDepartment;
|
+ "\t" + this.password + "\t" + this.idDepartment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isMatchId(String id) {
|
||||||
|
return getIdEmployee().equals(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMatchId(EmployeeData[] employees, String id) {
|
||||||
|
for (EmployeeData e : employees) {
|
||||||
|
if (e.isMatchId(id))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public String getIdEmployee() {
|
public String getIdEmployee() {
|
||||||
return idEmployee;
|
return idEmployee;
|
||||||
}
|
}
|
||||||
@@ -98,4 +111,5 @@ public class EmployeeData {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,24 @@ public class Main {
|
|||||||
EmployeeData emptyEmployee = new EmployeeData("", "", "", "", "", "");
|
EmployeeData emptyEmployee = new EmployeeData("", "", "", "", "", "");
|
||||||
System.out.println(emptyEmployee);
|
System.out.println(emptyEmployee);
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
//IDが一致するか
|
||||||
|
boolean matchIdBool = false;
|
||||||
|
System.out.println("10002 を検索します");
|
||||||
|
for (EmployeeData e : employees) {
|
||||||
|
matchIdBool = e.isMatchId("10002");
|
||||||
|
if (matchIdBool)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
System.out.println(matchIdBool);
|
||||||
|
|
||||||
|
System.out.println("99999 を検索します");
|
||||||
|
System.out.println(EmployeeData.isMatchId(employees, "99999"));
|
||||||
|
|
||||||
|
System.out.println("10003 を検索します");
|
||||||
|
System.out.println(EmployeeData.isMatchId(employees, "10003"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user