2日目_段階8

This commit is contained in:
2026-09-24 12:34:11 +09:00
parent b13acdba05
commit 8efaa1341f
2 changed files with 59 additions and 44 deletions

View File

@@ -1,5 +1,5 @@
public class EmployeeData {
public class EmployeeData {
// public static void main(String args[]) {
private String idEmployee;
@@ -8,52 +8,68 @@ public class EmployeeData {
private String mailAddress;
private String password;
private String idDepartment;
//staticをつけたフィールドはクラス変数:全てのインスタンスで共有される変数
public static int empCount = 0;
// boolean isMatchID = isMatchId(idEmployee);//IdEmployeeが一致するか判断
public static int empCount = 0;
// boolean isMatchID = isMatchId(idEmployee);//IdEmployeeが一致するか判断
//idEmployee「ID」を取得するgetter
public String getIdEmployee() {
return idEmployee;
}
//idEmployee「ID」を設定するsetter
public void setIdEmployee(String idEmployee) {
this.idEmployee = idEmployee;
}
//nmEmployee「名前」を取得するgetter
public String getNmEmployee() {
return nmEmployee;
}
//nmEmployee「名前」を設定するsetter
public void setNmEmployee(String nmEmployee) {
this.nmEmployee = nmEmployee;
}
this.nmEmployee = nmEmployee.trim();
if (nmEmployee == null || nmEmployee.trim().isEmpty()) {
System.out.println("社員名が空のため設定できませんでした");
return;
}
this.nmEmployee = nmEmployee;
// this.nmEmployee = nmEmployee.trim(); //前後の空白削除
// this.nmEmployee = null;
// if(nmEmployee != null && nmEmployee.isEmpty()) {
// System.out.println("社員名が空のため設定できませんでした");
}
//getKnEmployee「カタカナの名前」を取得するgetter
public String getKnEmployee() {
return knEmployee;
}
//getKnEmployee「カタカナの名前」を設定するsetter
public void setKnEmployee(String knEmployee) {
this.knEmployee = knEmployee;
}
//メールアドレスを取得するgetter
public String getMailAddress() {
return mailAddress;
}
//メールアドレスを設定するsetter
public void setMailAddress(String mailAddress) {
this.mailAddress = mailAddress;
}
//パスワードを取得するgetter
public String getPassword() {
return password;
}
//パスワードを取得するsetter
public void setPassword(String password) {
this.password = password;
@@ -63,19 +79,17 @@ public class EmployeeData {
public String getIdDepartment() {
return idDepartment;
}
//IdDepartmentを取得するsetter
public void setIdDepartment(String idDepartment) {
this.idDepartment = idDepartment;
}
//メソッド名:isMatchId 引数:String id 戻り値:boolean ID一致ならtrue,違えばfalse
public boolean isMatchId(String id) {
return this.idEmployee.equals(id);
}
}
public EmployeeData(String idEmployee, String nmEmployee,
String knEmployee, String mailAddress, String password, String idDepartment) {
@@ -85,18 +99,17 @@ public class EmployeeData {
this.mailAddress = mailAddress;
this.password = password;
this.idDepartment = idDepartment;
empCount++;
empCount++;
}
// public boolean isMatchId(String id) {
//// if(idEmployee equals )
// {
//
// }
//
// }
// public boolean isMatchId(String id) {
//// if(idEmployee equals )
// {
//
// }
//
// }
// public String Employee(String idEmployee) {
// this.idEmployee= idEmployee;
// }
@@ -105,23 +118,22 @@ public class EmployeeData {
empCount++;
// TODO 自動生成されたコンストラクター・スタブ
}
public static int getEmpCount() { //empCountの値を返せるようにする
return empCount;
}
// void showinfo() { //showinfo->toStringにメソッド名変更 + アクセス修飾子publicつける
// // this.idEmployee = idEmployee;
// System.out.println(this.idEmployee + "\t" + this.nmEmployee + "\t" + this.knEmployee + "\t" + this.mailAddress
// + "\t" + this.password + "\t" + this.idDepartment);
//
// }
@Override
public String toString() {
return (this.idEmployee +"\t" + this.nmEmployee + "\t" + this.knEmployee + "\t" + this.mailAddress
+ "\t" + this.password + "\t" + this.idDepartment);
}
// void showinfo() { //showinfo->toStringにメソッド名変更 + アクセス修飾子publicつける
// // this.idEmployee = idEmployee;
// System.out.println(this.idEmployee + "\t" + this.nmEmployee + "\t" + this.knEmployee + "\t" + this.mailAddress
// + "\t" + this.password + "\t" + this.idDepartment);
//
// }
@Override
public String toString() {
return (this.idEmployee + "\t" + this.nmEmployee + "\t" + this.knEmployee + "\t" + this.mailAddress
+ "\t" + this.password + "\t" + this.idDepartment);
}
}

View File

@@ -15,9 +15,8 @@ public class Main {
// employees[0] = new EmployeeData();
employees[0] = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
// employees[0].setIdEmployee("1000"); //private 後 に使用する!!
// employees[0].setNmEmployee("山田龍也");
employees[0].setNmEmployee(""); //段階 8 確認用
// employees[0].setKnEmployee("ヤマダタツヤ");
// employees[0].setMailAddress("yamada@hoge.jp");
// employees[0].setPassword("aaa");
@@ -84,7 +83,7 @@ public class Main {
// employees[3].idDepartment = "12";
// //
// employees[4] = new EmployeeData();
employees[4] = new EmployeeData("10004", "三宅武", "ミヤケタケシ", "miya@hoge.jp", "eee", "13");
employees[4] = new EmployeeData("10004", "aa", "ミヤケタケシ", "miya@hoge.jp", "eee", "13");
// employees[4].setIdEmployee("10004");
// employees[4].setNmEmployee("三宅武");
@@ -99,6 +98,8 @@ public class Main {
// employees[4].mailAddress = "miya@hoge.jp";
// employees[4].password = "eee";
// employees[4].idDepartment = "13";
//employees[5]= new EmployeeData("10005", , "タカヤマアカネ", "takayamaa@hoge.jp", "taka", "14");
// Scanner scanner = new Scanner(System.in); //8段階目!スキャナー作成
// while (true) { //while(true)- 9段階目課題
@@ -129,12 +130,14 @@ public class Main {
// }
// //Scannerを閉じる
// scanner.close();
System.out.println(employees[0]);
System.out.println(employees[1]);
System.out.println(employees[2]);
System.out.println(employees[3]);
System.out.println(employees[4]);
// System.out.println(employees[5]);
//5人分のインスタンスをすべて生成し終えた後にクラス名から呼び出し、件数表示
System.out.println("現在の社員データ件数:" + EmployeeData.empCount +"件");
// employees[0].showinfo();