6 Commits

Author SHA1 Message Date
127b824ceb completed Lv9 2026-10-15 16:52:00 +09:00
3f20a2a872 completed Lv9 2026-10-14 15:45:45 +09:00
19563fbbbb no message 2026-10-14 15:45:17 +09:00
0ab032f2e3 no message 2026-10-14 15:42:03 +09:00
91dac26b86 revert 548e172d7d 2026-10-14 06:23:44 +00:00
548e172d7d completed Lv9 2026-10-14 15:18:52 +09:00
5 changed files with 187 additions and 182 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
/bin/
/build/

View File

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

View File

@@ -1,165 +1,110 @@
public class EmployeeData extends BaseDate {
//フィールドの宣言
//社員ID
public class EmployeeData {
static final String COMPANY_NAME = "Rhizome";
private static int empCount = 0;
private String idEmployee;
//社員名
private String nmEmployee;
//社員名カナ
private String knEmployee;
//メールアドレス
private String mailAddress;
//パスワード
private String password;
//部署ID
private String idDepartment;
public static int empCount;
//ゲッターとセッター
public String getIdEmployee() {
return idEmployee;
}
public void setIdEmployee(String idEmployee) {
this.idEmployee = idEmployee;
}
public String getNmEmployee() {
return nmEmployee;
}
public void setNmEmployee(String nmEmployee) {
if(nmEmployee == null) {
System.out.println("社員名が空のため設定できませんでした");
} else {
this.nmEmployee = nmEmployee;
}
//文字列前後の空白を取り除く
String trimmednmEmployee = nmEmployee.trim();
//文字列の長さを調べる
int count = trimmednmEmployee.length();
if(count == 0) {
System.out.println("社員名が空のため設定できませんでした");
}else {
this.nmEmployee = nmEmployee;
}
}
public String getKnEmployee() {
return knEmployee;
}
public void setKnEmployee(String knEmployee) {
this.knEmployee = knEmployee;
}
public String getMailAddress() {
return mailAddress;
}
public void setMailAddress(String mailAddress) {
this.mailAddress = mailAddress;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getIdDepartment() {
return idDepartment;
}
public void setIdDepartment(String idDepartment) {
if(idDepartment == null) {
System.out.println("社員IDが空のため設定できませんでした");
} else {
this.idDepartment = idDepartment;
}
//文字列前後の空白を取り除く
String trimmednmEmployee = nmEmployee.trim();
//文字列の長さを調べる
int count = trimmednmEmployee.length();
if(count == 0) {
System.out.println("社員IDがのため設定できませんでした");
}else {
this.idDepartment = idDepartment;
}
}
public static int getEmpCount() {
return empCount;
}
public static void setEmpCount(int empCount) {
EmployeeData.empCount = empCount ++;
}
//コンストラクタの作成
public EmployeeData() {
empCount++;
}
public EmployeeData(String idEmployee, String nmEmployee, String knEmployee, String mailAddress, String password, String idDepartment, int empCount) {
public EmployeeData(String idEmployee,
String nmEmployee,
String knEmployee,
String mailAddress,
String password,
String idDepartment) {
this.setIdEmployee(idEmployee);
this.setNmEmployee(nmEmployee);
this.setKnEmployee(knEmployee);
this.setMailAddress(mailAddress);
this.setPassword(password);
this.setIdDepartment(idDepartment);
this.setEmpCount(empCount);
empCount++;
}
}
//メソッドの作成
@Override public String toString() {
return (getIdEmployee() +"\t"+ getNmEmployee() +"\t"+ getKnEmployee() +"\t"+ getMailAddress() +"\t"+ getPassword() +"\t"+ getIdDepartment());
}
static int EmpCount() {
return getEmpCount();
}
@Override public String toCSV(){
return (getIdEmployee() +","+ getNmEmployee() +","+ getKnEmployee() +","+ getMailAddress() +","+ getPassword() +","+ getIdDepartment());
}
@Override public String getPrimaryKeyValue() {
public String getIdEmployee() {
return idEmployee;
}
}
public void setIdEmployee(String idEmployee) {
if (idEmployee.strip().length()==0) {
System.out.println("社員IDが空のため設定できませんでした");
System.exit(0);
} else {
this.idEmployee = idEmployee;
}
}
public String getNmEmployee() {
return nmEmployee;
}
public void setNmEmployee(String nmEmployee) {
if (nmEmployee.strip().length()==0) {
System.out.println("社員名が空のため設定できませんでした");
System.exit(0);
} else {
this.nmEmployee = nmEmployee;
}
}
public String getKnEmployee() {
return knEmployee;
}
public void setKnEmployee(String knEmployee) {
this.knEmployee = knEmployee;
}
public String getMailAddress() {
return mailAddress;
}
public void setMailAddress(String mailAddress) {
this.mailAddress = mailAddress;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getIdDepartment() {
return idDepartment;
}
public void setIdDepartment(String idDepartment) {
this.idDepartment = idDepartment;
}
public static int getEmpCount() {
return empCount;
}
@Override
public String toString() {
return this.getIdEmployee()+"\t"
+this.getNmEmployee()+"\t"
+this.getKnEmployee()+"\t"
+this.getMailAddress()+"\t"
+this.getPassword()+"\t"
+this.getIdDepartment();
}
public boolean isMatchId(String id) {
return id.equals(this.getIdEmployee()) ;
}
}

98
src/main/java/Main.java Normal file
View File

@@ -0,0 +1,98 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
//====================設定====================
EmployeeData[] employees = new EmployeeData[5];
// EmployeeData employee0 = new EmployeeData();
// employee0.setIdEmployee(""); // 社員IDが空文字のとき
// employee0.setNmEmployee(""); // 社員名が空文字のとき
EmployeeData employee1 = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
// EmployeeData employee1 = new EmployeeData();
// employee1.setIdEmployee("10000");
// employee1.setNmEmployee("山田龍也");
// employee1.setKnEmployee("ヤマダタツヤ");
// employee1.setMailAddress("yamada@hoge.jp");
// employee1.setPassword("aaa");
// employee1.setIdDepartment("10");
employees[1-1] = employee1;
EmployeeData employee2 = new EmployeeData();
employee2.setIdEmployee("10001");
employee2.setNmEmployee("高橋準");
employee2.setKnEmployee("タカハシジュン");
employee2.setMailAddress("jtaka@hoge.jp");
employee2.setPassword("bbb");
employee2.setIdDepartment("10");
employees[2-1] = employee2;
EmployeeData employee3 = new EmployeeData();
employee3.setIdEmployee("10002");
employee3.setNmEmployee("麻枝史明");
employee3.setKnEmployee("マエダフミアキ");
employee3.setMailAddress("fmak@hoge.jp");
employee3.setPassword("ccc");
employee3.setIdDepartment("11");
employees[3-1] = employee3;
EmployeeData employee4 = new EmployeeData();
employee4.setIdEmployee("10003");
employee4.setNmEmployee("丸戸章介");
employee4.setKnEmployee("マルトショウスケ");
employee4.setMailAddress("marusyo@hoge.jp");
employee4.setPassword("ddd");
employee4.setIdDepartment("12");
employees[4-1] = employee4;
EmployeeData employee5 = new EmployeeData();
employee5.setIdEmployee("10004");
employee5.setNmEmployee("三宅武");
employee5.setKnEmployee("ミヤケタケシ");
employee5.setMailAddress("miya@hoge.jp");
employee5.setPassword("eee");
employee5.setIdDepartment("13");
employees[5-1] = employee5;
//====================表示====================
System.out.println(EmployeeData.COMPANY_NAME);
for ( EmployeeData employee : employees ) {
System.out.println(employee);
}
System.out.println("現在の社員データ件数:"+EmployeeData.getEmpCount()+"件");
//====================検索====================
while (true) {
System.out.println("検索したい社員IDを入力してください(終了する場合は0)");
Scanner sc = new Scanner(System.in);
String id = sc.nextLine();
if ( id.equals("0") ) {
System.out.println("システムを終了します");
break;
}
boolean matchId = false;
for ( EmployeeData employee : employees ) {
if ( employee.isMatchId(id) ) {
matchId = true;
System.out.println(employee);;
}
}
if ( matchId==false ) {
System.out.println("該当する社員が見つかりませんでした");
}
}
}
}

View File

@@ -1,32 +0,0 @@
public class em_oop_20261014 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
//インスタンスの生成
EmployeeData[] employees = new EmployeeData[5];
employees[0] = new EmployeeData("10000", "山田達也", "ヤマダタツヤ","yamada@hoge.jp" ,"aaa", "10",0);
employees[1] = new EmployeeData("10001","高橋準","タカハシジュン","jtaka@hoge.jp","bbb","10",1);
employees[2] = new EmployeeData("10002","麻枝史明","マエダフミアキ","fmak@hoge.jp","ccc","11",2);
employees[3] = new EmployeeData("10003","丸戸章介","マルトショウスケ","marusyo@hoge.jp","ddd","12",3);
employees[4] = new EmployeeData("10004","三宅武","ミヤケタケシ","miya@hoge.jp","eee","13",4);
//呼び出し
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.length);
//employees.toCSV();
//employees.getPrimaryKeyValue();
}
}