8 Commits

13 changed files with 644 additions and 3 deletions

6
.classpath Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>

2
.gitignore vendored Normal file
View File

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

23
.project Normal file
View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>em-oop</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=21

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="21"/>
</faceted-project>

6
file/DepartmentData.csv Normal file
View File

@@ -0,0 +1,6 @@
10,役員
11,人事・総務部
12,経理部
13,システム開発事業部
14,教育事業部
15,営業企画部
1 10 役員
2 11 人事・総務部
3 12 経理部
4 13 システム開発事業部
5 14 教育事業部
6 15 営業企画部

6
file/EmployeeData.csv Normal file
View File

@@ -0,0 +1,6 @@
10000,山田龍也,ヤマダタツヤ,yamada@hoge.jp,aaa,10
10001,高橋準,タカハシジュン,jtaka@hoge.jp,bbb,10
10002,麻枝史明,マエダフミアキ,fmak@hoge.jp,ccc,11
1,1,1,1,1,1
3,2,2,2,2,2
4,4,4,4,4,4
1 10000 山田龍也 ヤマダタツヤ yamada@hoge.jp aaa 10
2 10001 高橋準 タカハシジュン jtaka@hoge.jp bbb 10
3 10002 麻枝史明 マエダフミアキ fmak@hoge.jp ccc 11
4 1 1 1 1 1 1
5 3 2 2 2 2 2
6 4 4 4 4 4 4

View File

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

View File

@@ -0,0 +1,49 @@
public class DepartmentData extends BaseData {
private String idDepartment;
private String nmDepartment;
public DepartmentData() {
}
public DepartmentData(String idDepartment,String nmDepartment) {
this.setIdDepartment(idDepartment);
this.setNmDepartment(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();
}
}

View File

@@ -0,0 +1,123 @@
public class EmployeeData extends BaseData {
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;
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) {
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()) ;
// }
@Override
public String toCSV() {
return this.getIdEmployee()+","
+this.getNmEmployee()+","
+this.getKnEmployee()+","
+this.getMailAddress()+","
+this.getPassword()+","
+this.getIdDepartment();
}
@Override
public String getPrimaryKeyValue() {
return this.getIdEmployee();
}
}

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

@@ -0,0 +1,127 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
//====================設定====================
BaseData[] employees = new BaseData[5];
BaseData employee1 = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
employees[1-1] = employee1;
BaseData employee2 = new EmployeeData("10001", "高橋準", "タカハシジュン", "jtaka@hoge.jp", "bbb", "10");
employees[2-1] = employee2;
BaseData employee3 = new EmployeeData("10002", "麻枝史明", "マエダフミアキ", "fmak@hoge.jp", "ccc", "11");
employees[3-1] = employee3;
BaseData employee4 = new EmployeeData("10003", "丸戸章介", "マルトショウスケ", "marusyo@hoge.jp", "ddd", "12");
employees[4-1] = employee4;
BaseData employee5 = new EmployeeData("10004", "三宅武", "ミヤケタケシ", "miya@hoge.jp", "eee", "13");
employees[5-1] = employee5;
BaseData[] allData = new BaseData[11];
allData[0] = employees[0];
allData[1] = employees[1];
allData[2] = employees[2];
allData[3] = employees[3];
allData[4] = employees[4];
DepartmentData department1 = new DepartmentData();
department1.setIdDepartment("10");
department1.setNmDepartment("役員");
allData[5] = department1;
DepartmentData department2 = new DepartmentData();
department2.setIdDepartment("11");
department2.setNmDepartment("人事");
allData[6] = department2;
DepartmentData department3 = new DepartmentData();
department3.setIdDepartment("12");
department3.setNmDepartment("経理部");
allData[7] = department3;
DepartmentData department4 = new DepartmentData();
department4.setIdDepartment("13");
department4.setNmDepartment("システム開発事業部");
allData[8] = department4;
DepartmentData department5 = new DepartmentData();
department5.setIdDepartment("14");
department5.setNmDepartment("教育事業部");
allData[9] = department5;
DepartmentData department6 = new DepartmentData();
department6.setIdDepartment("15");
department6.setNmDepartment("営業企画部");
allData[10] = department6;
// 段階7+8
int nEmployeeData = 0;
int nDepartmentData = 0;
for ( BaseData data : allData ) {
// System.out.println(data);
if ( data instanceof EmployeeData ) {
System.out.println(((EmployeeData)data).getMailAddress());
nEmployeeData++;
continue;
}
if ( data instanceof DepartmentData ) {
nDepartmentData++;
continue;
}
}
System.out.println("社員データ:"+nEmployeeData+"件");
System.out.println("部署データ:"+nDepartmentData+"件");
// 段階9
String ID = "";
for ( BaseData data : allData ) {
if ( data instanceof DepartmentData ) {
if ( ((DepartmentData)data).getNmDepartment().equals("システム開発事業部") ) {
ID = data.getPrimaryKeyValue();
}
}
}
for ( BaseData data : allData ) {
if ( data instanceof EmployeeData ) {
if ( ((EmployeeData)data).getIdDepartment().equals(ID) ) {
System.out.println(((EmployeeData)data).getNmEmployee()+" "+((EmployeeData)data).getMailAddress());
}
}
}
//====================表示====================
System.out.println(EmployeeData.COMPANY_NAME);
for ( BaseData 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 ( BaseData employee : employees ) {
if ( employee.getPrimaryKeyValue().equals(id) ) {
matchId = true;
System.out.println(employee);;
}
}
if ( matchId==false ) {
System.out.println("該当する社員が見つかりませんでした");
}
}
}
}

280
src/main/java/MainNew.java Normal file
View File

@@ -0,0 +1,280 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
public class MainNew {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Scanner sc = new Scanner(System.in);
while (true) {
// csvファイルからデータを読み込む
ArrayList<BaseData> allData = readCSV();
// 会社情報表示
//System.out.println(EmployeeData.COMPANY_NAME);
//====================管理機能====================
System.out.println("1:検索 2:登録 3:更新 4:削除 0:終了");
// 操作項目入力
String index = sc.nextLine();
// 入力1=検索
if (index.equals("1")) {
System.out.println("1:全検索 2:条件検索 それ以外:戻る");
String indexSearch = sc.nextLine();
if (indexSearch.equals("1")) {
// 全検索
displayEmployee(allData);
continue;
} else if (indexSearch.equals("2")) {
// 条件検索
searchEmployee(allData,sc);
continue;
} else {
continue;
}
}
// 入力2=登録
if (index.equals("2")) {
registerEmployee(allData,sc);
}
// 入力3=更新
if (index.equals("3")) {
updateEmployee(allData,sc);
}
// 入力4=削除
if (index.equals("4")) {
removeEmployee(allData,sc);
}
// 入力0=終了
if ( index.equals("0") ) {
System.out.println("システムを終了します");
break;
}
}
}
// csvファイルから情報を読み込む
public static ArrayList<BaseData> readCSV() {
ArrayList<BaseData> allData = new ArrayList<BaseData>();
try {
// 社員情報を読み込む
File empFile = new File("/Users/鈴木 皓介/Documents/em-oop/file/EmployeeData.csv");
String empline = "";
BufferedReader empbr = new BufferedReader(new InputStreamReader(new FileInputStream(empFile),"UTF-8"));
while ((empline=empbr.readLine())!=null) {
String[] data = empline.split(",",0);
BaseData employee = new EmployeeData(data[0],data[1],data[2],data[3],data[4],data[5]);
allData.add(employee);
}
// 部署情報を読み込む
File depFile = new File("/Users/鈴木 皓介/Documents/em-oop/file/DepartmentData.csv");
String depline = "";
BufferedReader depbr = new BufferedReader(new InputStreamReader(new FileInputStream(depFile),"UTF-8"));
while ((depline=depbr.readLine())!=null) {
String[] data = depline.split(",",0);
BaseData department = new DepartmentData(data[0],data[1]);
allData.add(department);
}
} catch (IOException err) {
System.exit(0);
}
return allData;
}
// csvファイルに社員データを書き込む
public static void writeEmployee(ArrayList<BaseData> allData) {
try {
// 社員情報を書き込む
File empFile = new File("/Users/鈴木 皓介/Documents/em-oop/file/EmployeeData.csv");
FileWriter empfr = new FileWriter(empFile);
for ( BaseData data : allData ) {
if ( data instanceof EmployeeData ) {
empfr.append(data.toCSV()+"\n");
}
}
empfr.close();
} catch (IOException err) {
System.exit(0);
}
}
// 全検索(社員情報表示)
public static void displayEmployee(ArrayList<BaseData> allData) {
for ( BaseData data : allData ) {
if ( data instanceof EmployeeData ) {
System.out.println(data);
}
}
System.out.println();
}
// 社員ID照合
public static boolean matchIdEmployee(ArrayList<BaseData> allData,String id) {
boolean isMatched = false;
for ( BaseData data : allData ) {
if ( data instanceof EmployeeData ) {
if ( data.getPrimaryKeyValue().equals(id) ) {
isMatched = true;
break;
}
}
}
return isMatched;
}
// ID照合→該当BaseData配列インデックス取得
public static int getIndexArray(ArrayList<BaseData> allData,String id) {
int index = 0;
for ( BaseData data : allData ) {
if ( data instanceof EmployeeData ) {
if ( data.getPrimaryKeyValue().equals(id) ) {
break;
}
}
index++;
}
return index;
}
// 条件検索
public static void searchEmployee(ArrayList<BaseData> allData,Scanner sc) {
System.out.println("検索したい社員IDを入力してください");
String id = sc.nextLine();
boolean isMatched = matchIdEmployee(allData,id);
if (isMatched==false) {
System.out.println("入力されたIDに該当する社員が見つかりませんでした");
}
if (isMatched==true) {
System.out.println(allData.get(getIndexArray(allData,id)));
}
System.out.println();
}
// 登録
public static void registerEmployee(ArrayList<BaseData> allData,Scanner sc) {
System.out.println("登録したい社員IDを入力してください");
String id = sc.nextLine();
boolean isMatched = matchIdEmployee(allData,id);
if (isMatched==false) {
String[] newdata = new String[6];
newdata[0] = id;
System.out.println("社員名を入力してください");
newdata[1] = sc.nextLine();
System.out.println("フリガナを入力してください");
newdata[2] = sc.nextLine();
System.out.println("メールアドレスを入力してください");
newdata[3] = sc.nextLine();
System.out.println("パスワードを入力してください");
newdata[4] = sc.nextLine();
System.out.println("部署IDを入力してください");
newdata[5] = sc.nextLine();
System.out.println("登録が完了しました");
allData.add(new EmployeeData(newdata[0],newdata[1],newdata[2],newdata[3],newdata[4],newdata[5]));
writeEmployee(allData);
}
if (isMatched==true) {
System.out.println("入力されたIDは既に登録されています");
}
}
// 更新
public static void updateEmployee(ArrayList<BaseData> allData,Scanner sc) {
System.out.println("更新したい社員IDを入力してください");
String id = sc.nextLine();
boolean isMatched = matchIdEmployee(allData,id);
if (isMatched==false) {
System.out.println("入力されたIDに該当する社員が見つかりませんでした");
}
if (isMatched==true) {
BaseData data = allData.get(getIndexArray(allData,id));
System.out.println("社員名を入力してください");
((EmployeeData)data).setNmEmployee(sc.nextLine());
System.out.println("フリガナを入力してください");
((EmployeeData)data).setKnEmployee(sc.nextLine());
System.out.println("メールアドレスを入力してください");
((EmployeeData)data).setMailAddress(sc.nextLine());
System.out.println("パスワードを入力してください");
((EmployeeData)data).setPassword(sc.nextLine());
System.out.println("部署IDを入力してください");
((EmployeeData)data).setIdDepartment(sc.nextLine());
System.out.println("更新が完了しました");
writeEmployee(allData);
}
}
// 消去
public static void removeEmployee(ArrayList<BaseData> allData,Scanner sc) {
System.out.println("削除したい社員IDを入力してください");
String id = sc.nextLine();
boolean isMatched = matchIdEmployee(allData,id);
if (isMatched==false) {
System.out.println("入力されたIDに該当する社員が見つかりませんでした");
}
if (isMatched==true) {
System.out.println("指定されたIDに該当する社員の情報を削除しますか? Y/y");
System.out.println("Y/y以外:キャンセル");
String flag = sc.nextLine();
if (flag.equals("Y")||flag.equals("y")) {
allData.remove(getIndexArray(allData,id));
System.out.println("削除が完了しました");
writeEmployee(allData);
}
}
}
}

View File

@@ -1,10 +1,8 @@
10000,山田龍也,ヤマダタツヤ,yamada@hoge.jp,aaa,10
10001,高橋準,タカハシジュン,jtaka@hoge.jp,bbb,10 10001,高橋準,タカハシジュン,jtaka@hoge.jp,bbb,10
10002,麻枝史明,マエダフミアキ,fmak@hoge.jp,ccc,11 10002,麻枝史明,マエダフミアキ,fmak@hoge.jp,ccc,11
10003,丸戸章介,マルトショウスケ,marusyo@hoge.jp,ddd,12
10004,三宅武,ミヤケタケシ,miya@hoge.jp,eee,13
10005,丸井悠,マルイハルカ,haru@hoge.jp,fff,13 10005,丸井悠,マルイハルカ,haru@hoge.jp,fff,13
10006,涼元香織,スズモトカオリ,suzumoto@hoge.jp,ggg,13 10006,涼元香織,スズモトカオリ,suzumoto@hoge.jp,ggg,13
10007,葉山稔,ハヤマミノル,mhayama@hoge.jp,hhh,14 10007,葉山稔,ハヤマミノル,mhayama@hoge.jp,hhh,14
10008,川上朱里,カワカミアカリ,kawakami@hoge.jp,iii,14 10008,川上朱里,カワカミアカリ,kawakami@hoge.jp,iii,14
10009,杉井肇,スギイハジメ,sugi@hoge.jp,jjj,15 10009,杉井肇,スギイハジメ,sugi@hoge.jp,jjj,15
2,2,2,2,2,2
1 10000 10001 山田龍也 高橋準 ヤマダタツヤ タカハシジュン yamada@hoge.jp jtaka@hoge.jp aaa bbb 10
10000 山田龍也 ヤマダタツヤ yamada@hoge.jp aaa 10
1 10001 10001 高橋準 高橋準 タカハシジュン タカハシジュン jtaka@hoge.jp jtaka@hoge.jp bbb bbb 10
2 10002 10002 麻枝史明 麻枝史明 マエダフミアキ マエダフミアキ fmak@hoge.jp fmak@hoge.jp ccc ccc 11
10003 丸戸章介 マルトショウスケ marusyo@hoge.jp ddd 12
10004 三宅武 ミヤケタケシ miya@hoge.jp eee 13
3 10005 10005 丸井悠 丸井悠 マルイハルカ マルイハルカ haru@hoge.jp haru@hoge.jp fff fff 13
4 10006 10006 涼元香織 涼元香織 スズモトカオリ スズモトカオリ suzumoto@hoge.jp suzumoto@hoge.jp ggg ggg 13
5 10007 10007 葉山稔 葉山稔 ハヤマミノル ハヤマミノル mhayama@hoge.jp mhayama@hoge.jp hhh hhh 14
6 10008 10008 川上朱里 川上朱里 カワカミアカリ カワカミアカリ kawakami@hoge.jp kawakami@hoge.jp iii iii 14
7 10009 10009 杉井肇 杉井肇 スギイハジメ スギイハジメ sugi@hoge.jp sugi@hoge.jp jjj jjj 15
8 2 2 2 2 2 2