Compare commits
3 Commits
127b824ceb
...
ishikawa
| Author | SHA1 | Date | |
|---|---|---|---|
| 0b95cb8a6c | |||
| 05ed866c5c | |||
| 080f90503b |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1 @@
|
||||
/bin/
|
||||
/build/
|
||||
|
||||
7
src/main/java/BaseData.java
Normal file
7
src/main/java/BaseData.java
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
public abstract class BaseData {
|
||||
public abstract String toString();
|
||||
public abstract String toCSV();
|
||||
public abstract String getPrimaryKeyValue();
|
||||
|
||||
}
|
||||
133
src/main/java/CUI_20261014.java
Normal file
133
src/main/java/CUI_20261014.java
Normal file
@@ -0,0 +1,133 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class CUI_20261014 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
BaseData[] employees = new BaseData[5];
|
||||
|
||||
employees[0] = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ",
|
||||
"yamada@hoge.jp", "aaa", "10");
|
||||
|
||||
employees[1] = new EmployeeData();
|
||||
((EmployeeData)employees[1]).setIdEmployee("10001");
|
||||
((EmployeeData)employees[1]).setNmEmployee("高橋準");
|
||||
((EmployeeData)employees[1]).setKnEmployee("タカハシジュン");
|
||||
((EmployeeData)employees[1]).setMailAddress("jtaka@hoge.jp");
|
||||
((EmployeeData)employees[1]).setPassword("bbb");
|
||||
((EmployeeData)employees[1]).setIdDepartment("10");
|
||||
|
||||
employees[2] = new EmployeeData();
|
||||
((EmployeeData)employees[2]).setIdEmployee("10002");
|
||||
((EmployeeData)employees[2]).setNmEmployee("麻枝史明");
|
||||
((EmployeeData)employees[2]).setKnEmployee("マエダフミアキ");
|
||||
((EmployeeData)employees[2]).setMailAddress("fmak@hoge.jp");
|
||||
((EmployeeData)employees[2]).setPassword("ccc");
|
||||
((EmployeeData)employees[2]).setIdDepartment("11");
|
||||
|
||||
employees[3] = new EmployeeData();
|
||||
((EmployeeData)employees[3]).setIdEmployee("10003");
|
||||
((EmployeeData)employees[3]).setNmEmployee("丸戸章介");
|
||||
((EmployeeData)employees[3]).setKnEmployee("マルトショウスケ");
|
||||
((EmployeeData)employees[3]).setMailAddress("marusyo@hoge.jp");
|
||||
((EmployeeData)employees[3]).setPassword("ddd");
|
||||
((EmployeeData)employees[3]).setIdDepartment("12");
|
||||
|
||||
employees[4] = new EmployeeData();
|
||||
((EmployeeData)employees[4]).setIdEmployee("10004");
|
||||
((EmployeeData)employees[4]).setNmEmployee("三宅武");
|
||||
((EmployeeData)employees[4]).setKnEmployee("ミヤケタケシ");
|
||||
((EmployeeData)employees[4]).setMailAddress("miya@hoge.jp");
|
||||
((EmployeeData)employees[4]).setPassword("eee");
|
||||
((EmployeeData)employees[4]).setIdDepartment("13");
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
System.out.println(employees[i]);
|
||||
}
|
||||
|
||||
System.out.println("現在の社員データ件数:" + EmployeeData.getEmpCount() + "件");
|
||||
System.out.println();
|
||||
|
||||
System.out.println(employees[0].toCSV());
|
||||
System.out.println(employees[0].getPrimaryKeyValue());
|
||||
|
||||
BaseData[] allData = new BaseData[11];
|
||||
|
||||
for(int i = 0; i <= 4; i++) {
|
||||
allData[i] = employees[i];
|
||||
}
|
||||
|
||||
DepartmentData dept = new DepartmentData();
|
||||
dept.setIdDepartment("10");
|
||||
dept.setNmDepartment("役員");
|
||||
allData[5] = dept;
|
||||
|
||||
dept.setIdDepartment("11");
|
||||
dept.setNmDepartment("人事・総務部");
|
||||
allData[6] = dept;
|
||||
|
||||
dept.setIdDepartment("12");
|
||||
dept.setNmDepartment("経理部");
|
||||
allData[7] = dept;
|
||||
|
||||
dept.setIdDepartment("13");
|
||||
dept.setNmDepartment("システム開発事業部");
|
||||
allData[8] = dept;
|
||||
|
||||
dept.setIdDepartment("14");
|
||||
dept.setNmDepartment("教育事業部");
|
||||
allData[9] = dept;
|
||||
|
||||
dept.setIdDepartment("15");
|
||||
dept.setNmDepartment("営業企画部");
|
||||
allData[10] = dept;
|
||||
|
||||
for(int i = 0; i <= 10; i++) {
|
||||
System.out.println(allData[i]);
|
||||
}
|
||||
|
||||
//IDが10002を探す
|
||||
System.out.println("10002 を検索します");
|
||||
boolean b1 = false; //一致してるかを判定させる
|
||||
for(int i = 0; i < 5; i++) { //employees[0-4]まで繰り返す
|
||||
if(employees[i].getPrimaryKeyValue().equals("10002")) { //10002と一致するのがあれば
|
||||
b1 = true; //b1をtrueにして
|
||||
break; //繰り返しを抜ける
|
||||
}
|
||||
}
|
||||
System.out.println(b1); //trueかfalseかを出力
|
||||
|
||||
//IDが99999を探す
|
||||
System.out.println("99999 を検索します");
|
||||
boolean b2 = false;
|
||||
for(int i = 0; i < 5; i++) {
|
||||
if(employees[i].getPrimaryKeyValue().equals("99999")) {
|
||||
b2 = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
System.out.println(b2);
|
||||
|
||||
while(true) { //繰り返す
|
||||
System.out.println("検索したい社員IDを入力してください(終了する場合は0)");
|
||||
Scanner sc = new Scanner(System.in); //キーボード入力受け取る
|
||||
String str = sc.nextLine(); //入力されたものをstrにする
|
||||
if(str.equals("0")) { //0と入力されたら
|
||||
System.out.println("システムを終了します"); //終わる
|
||||
break; //ループ終了
|
||||
}
|
||||
|
||||
boolean b3 = false; //一致してるかを判定させる
|
||||
for(int i = 0; i < 5; i++) { //employees[0-4]まで繰り返す
|
||||
if(employees[i].getPrimaryKeyValue().equals(str)) { //strと一致していたら
|
||||
System.out.println(employees[i].toString()); //toStoringメソッドを呼び出して出力
|
||||
b3 = true; //b3をtrueにして
|
||||
break; //繰り返しを抜ける
|
||||
}
|
||||
}
|
||||
if(!b3) {
|
||||
System.out.println("該当する社員が見つかりませんでした");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
src/main/java/DepartmentData.java
Normal file
31
src/main/java/DepartmentData.java
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
public class DepartmentData extends BaseData{
|
||||
private String idDepartment;
|
||||
private String nmDepartment;
|
||||
|
||||
public String getIdDepartment() {
|
||||
return idDepartment;
|
||||
}
|
||||
public void setIdDepartment(String idDepartment) {
|
||||
this.idDepartment = idDepartment;
|
||||
}
|
||||
public String getNmDepartment() {
|
||||
return nmDepartment;
|
||||
}
|
||||
public void setNmDepartment(String nmDepartment) {
|
||||
this.nmDepartment = nmDepartment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getIdDepartment() + "\t" + this.getNmDepartment();
|
||||
}
|
||||
@Override
|
||||
public String toCSV() {
|
||||
return this.getIdDepartment() + "," + this.getNmDepartment();
|
||||
}
|
||||
@Override
|
||||
public String getPrimaryKeyValue() {
|
||||
return this.getIdDepartment();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
|
||||
public class EmployeeData {
|
||||
|
||||
static final String COMPANY_NAME = "Rhizome";
|
||||
private static int empCount = 0;
|
||||
public class EmployeeData extends BaseData{
|
||||
private String idEmployee;
|
||||
private String nmEmployee;
|
||||
private String knEmployee;
|
||||
@@ -10,34 +7,15 @@ public class EmployeeData {
|
||||
private String password;
|
||||
private String idDepartment;
|
||||
|
||||
public EmployeeData() {
|
||||
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);
|
||||
empCount++;
|
||||
}
|
||||
|
||||
//ゲッターとセッター
|
||||
public String getIdEmployee() {
|
||||
return idEmployee;
|
||||
}
|
||||
|
||||
public void setIdEmployee(String idEmployee) {
|
||||
if (idEmployee.strip().length()==0) {
|
||||
if(idEmployee == null || idEmployee.strip().isEmpty()) {
|
||||
System.out.println("社員IDが空のため設定できませんでした");
|
||||
System.exit(0);
|
||||
} else {
|
||||
}else {
|
||||
this.idEmployee = idEmployee;
|
||||
}
|
||||
}
|
||||
@@ -47,10 +25,9 @@ public class EmployeeData {
|
||||
}
|
||||
|
||||
public void setNmEmployee(String nmEmployee) {
|
||||
if (nmEmployee.strip().length()==0) {
|
||||
if(nmEmployee == null || nmEmployee.strip().isEmpty()) {
|
||||
System.out.println("社員名が空のため設定できませんでした");
|
||||
System.exit(0);
|
||||
} else {
|
||||
}else {
|
||||
this.nmEmployee = nmEmployee;
|
||||
}
|
||||
}
|
||||
@@ -87,24 +64,49 @@ public class EmployeeData {
|
||||
this.idDepartment = idDepartment;
|
||||
}
|
||||
|
||||
public static int getEmpCount() {
|
||||
private static int empCount = 0;
|
||||
//引数なしコンストラクタ
|
||||
public EmployeeData() {
|
||||
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);
|
||||
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 this.idEmployee.equals(id);
|
||||
}
|
||||
|
||||
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 String toCSV() {
|
||||
return (this.getIdEmployee() + "," + this.getNmEmployee() + "," + this.getKnEmployee() + "," +
|
||||
this.getMailAddress() + "," + this.getPassword() + "," + this.getIdDepartment());
|
||||
}
|
||||
|
||||
public boolean isMatchId(String id) {
|
||||
return id.equals(this.getIdEmployee()) ;
|
||||
public String getPrimaryKeyValue() {
|
||||
return this.idEmployee;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
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("該当する社員が見つかりませんでした");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user