Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ecb68ed34 | |||
| 96dcc745d8 | |||
| 82628fc7f5 | |||
| 4b2cb5a18b | |||
| 2b4e19fae2 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
実行例(追加問題含め)/em_oop.jar
|
||||||
27
BasicCheck1.java
Normal file
27
BasicCheck1.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
|
public class BasicCheck1 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
//コンストラクタ
|
||||||
|
Book book1 = new Book();
|
||||||
|
|
||||||
|
//book1
|
||||||
|
System.out.println(book1.title);
|
||||||
|
System.out.println(book1.author);
|
||||||
|
System.out.println(book1.price);
|
||||||
|
|
||||||
|
//コンストラクタ
|
||||||
|
Book book2 = new Book(
|
||||||
|
"銀河鉄道の夜",
|
||||||
|
"宮沢賢治",
|
||||||
|
500);
|
||||||
|
|
||||||
|
//book2
|
||||||
|
System.out.println(book2.title);
|
||||||
|
System.out.println(book2.author);
|
||||||
|
System.out.println(book2.price);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
23
BasicCheck2.java
Normal file
23
BasicCheck2.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
|
public class BasicCheck2 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
Student student1 = new Student(1, "鈴木一郎");
|
||||||
|
Student student2 = new Student(2, "田中花子");
|
||||||
|
Student student3 = new Student(3, "佐藤次郎");
|
||||||
|
|
||||||
|
// 学生情報表示
|
||||||
|
student1.printProfile();
|
||||||
|
student2.printProfile();
|
||||||
|
student3.printProfile();
|
||||||
|
|
||||||
|
// 現在の学生数表示
|
||||||
|
System.out.println(
|
||||||
|
"現在の生徒数:"
|
||||||
|
+ Student.getStudentCount()
|
||||||
|
+ "人");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
public class BasicCheck3 {
|
public class BasicCheck3 {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
// Item型の配列を作成
|
||||||
Item[] items = new Item[3];
|
Item[] items = new Item[3];
|
||||||
|
|
||||||
|
//インスタンス生成
|
||||||
items[0] = new Item();
|
items[0] = new Item();
|
||||||
items[1] = new Item();
|
items[1] = new Item();
|
||||||
items[2] = new Item();
|
items[2] = new Item();
|
||||||
@@ -20,19 +24,14 @@ public class BasicCheck3 {
|
|||||||
items[2].setPrice(60);
|
items[2].setPrice(60);
|
||||||
items[2].setStock(100);
|
items[2].setStock(100);
|
||||||
|
|
||||||
|
//販売
|
||||||
for (int i = 0; i < items.length; i++) {
|
for (int i = 0; i < items.length; i++) {
|
||||||
items[i].sell(5);
|
items[i].sell(5);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//商品情報表示
|
||||||
for (int i = 0; i < items.length; i++) {
|
for (int i = 0; i < items.length; i++) {
|
||||||
System.out.println(items[i]);
|
System.out.println(items[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
28
Book.java
Normal file
28
Book.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
|
public class Book {
|
||||||
|
// タイトル
|
||||||
|
String title;
|
||||||
|
// 著者
|
||||||
|
String author;
|
||||||
|
// 価格
|
||||||
|
int price;
|
||||||
|
|
||||||
|
//コンストラクタ
|
||||||
|
public Book() {
|
||||||
|
|
||||||
|
this.title = "タイトル未設定";
|
||||||
|
this.author = "著者未設定";
|
||||||
|
this.price = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//コンストラクタ
|
||||||
|
public Book(String title, String author, int price) {
|
||||||
|
|
||||||
|
//フィールド代入
|
||||||
|
this.title = title;
|
||||||
|
this.author = author;
|
||||||
|
this.price = price;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,10 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
public abstract class BaseData {
|
|
||||||
|
|
||||||
public abstract String toString();
|
|
||||||
public abstract String toCSV();
|
|
||||||
public abstract String getPrimaryKeyValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
|
|
||||||
public class BasicCheck1 {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
|
||||||
Book book = new Book();
|
|
||||||
// book.title = "吾輩は猫である";
|
|
||||||
// book.author = "夏目漱石";
|
|
||||||
// book.price = 800;
|
|
||||||
|
|
||||||
// book.output();
|
|
||||||
|
|
||||||
Book book1 = new Book();
|
|
||||||
|
|
||||||
|
|
||||||
book1.output();
|
|
||||||
|
|
||||||
Book book2 = new Book();
|
|
||||||
book2.title = "銀河鉄道の夜";
|
|
||||||
book2.author = "宮沢賢治";
|
|
||||||
book2.price = 500;
|
|
||||||
|
|
||||||
book2.output();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
|
|
||||||
public class BasicCheck2 {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
|
||||||
Student student1 = new Student(1,"鈴木一郎");
|
|
||||||
Student student2 = new Student(2,"田中花子");
|
|
||||||
Student student3 = new Student(3,"佐藤次郎");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
student1.printProfile();
|
|
||||||
student2.printProfile();
|
|
||||||
student3.printProfile();
|
|
||||||
|
|
||||||
System.out.println("現在の生徒数:" + Student.getStudentCount() + "人");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
|
|
||||||
public class Book {
|
|
||||||
|
|
||||||
String title;
|
|
||||||
String author;
|
|
||||||
int price;
|
|
||||||
|
|
||||||
public Book() {
|
|
||||||
this.title = "タイトル未設定";
|
|
||||||
this.author = "著者未設定";
|
|
||||||
this.price = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
public Book(String title, String author, int price) {
|
|
||||||
this.title = title;
|
|
||||||
this.author = author;
|
|
||||||
this.price = price;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void output() {
|
|
||||||
System.out.println(this.title);
|
|
||||||
System.out.println(this.author);
|
|
||||||
System.out.println(this.price);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,147 +0,0 @@
|
|||||||
public class EmployeeData extends BaseData {
|
|
||||||
private String idEmployee;
|
|
||||||
private String nmEmployee;
|
|
||||||
private String knEmployee;
|
|
||||||
private String mailAddress;
|
|
||||||
private String password;
|
|
||||||
private String idDepartment;
|
|
||||||
|
|
||||||
private static int empCount = 0;
|
|
||||||
// 引数なしコンストラクタ
|
|
||||||
public EmployeeData() {
|
|
||||||
|
|
||||||
}
|
|
||||||
// 引数ありコンストラクタ
|
|
||||||
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 void output() {
|
|
||||||
System.out.println(this.idEmployee);
|
|
||||||
System.out.println(this.nmEmployee);
|
|
||||||
System.out.println(this.knEmployee);
|
|
||||||
System.out.println(this.mailAddress);
|
|
||||||
System.out.println(this.password);
|
|
||||||
System.out.println(this.idDepartment);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return getIdEmployee() + "\t"
|
|
||||||
+ getNmEmployee() + "\t"
|
|
||||||
+ getKnEmployee() + "\t"
|
|
||||||
+ getMailAddress() + "\t"
|
|
||||||
+ getPassword() + "\t"
|
|
||||||
+ getIdDepartment();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMatchId(String id) {
|
|
||||||
return id.equals(this.idEmployee);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getIdEmployee() {
|
|
||||||
return idEmployee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdEmployee(String idEmployee) {
|
|
||||||
|
|
||||||
if (idEmployee == null) {
|
|
||||||
System.out.println("社員IDが空のため設定できませんでした");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (idEmployee.trim().length() == 0) {
|
|
||||||
System.out.println("社員IDが空のため設定できませんでした");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.idEmployee = idEmployee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNmEmployee() {
|
|
||||||
return nmEmployee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNmEmployee(String nmEmployee) {
|
|
||||||
|
|
||||||
if (nmEmployee == null) {
|
|
||||||
System.out.println("社員名が空のため設定できませんでした");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nmEmployee.trim().length() == 0) {
|
|
||||||
System.out.println("社員名が空のため設定できませんでした");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toCSV() {
|
|
||||||
|
|
||||||
return getIdEmployee() + ","
|
|
||||||
+ getNmEmployee() + ","
|
|
||||||
+ getKnEmployee() + ","
|
|
||||||
+ getMailAddress() + ","
|
|
||||||
+ getPassword() + ","
|
|
||||||
+ getIdDepartment();
|
|
||||||
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String getPrimaryKeyValue() {
|
|
||||||
|
|
||||||
return getIdEmployee();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getEmpCount() {
|
|
||||||
return empCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,239 +0,0 @@
|
|||||||
import java.util.Scanner;
|
|
||||||
public class Main {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
|
||||||
|
|
||||||
EmployeeData employee = new EmployeeData();
|
|
||||||
|
|
||||||
employee.setIdEmployee("10000");
|
|
||||||
employee.setNmEmployee("山田龍也");
|
|
||||||
employee.setKnEmployee("ヤマダタツヤ");
|
|
||||||
employee.setMailAddress("yamada@hoge.jp");
|
|
||||||
employee.setPassword("aaa");
|
|
||||||
employee.setIdDepartment("10");
|
|
||||||
|
|
||||||
// employee.output();
|
|
||||||
// employee.showInfo();
|
|
||||||
System.out.println(employee.toCSV());
|
|
||||||
|
|
||||||
System.out.println(employee.getPrimaryKeyValue());
|
|
||||||
/* EmployeeData[] employees = new EmployeeData[5];
|
|
||||||
|
|
||||||
employees[0] = new EmployeeData();
|
|
||||||
employees[1] = new EmployeeData();
|
|
||||||
employees[2] = new EmployeeData();
|
|
||||||
employees[3] = new EmployeeData();
|
|
||||||
employees[4] = new EmployeeData();
|
|
||||||
|
|
||||||
employees[0].setIdEmployee("10000");
|
|
||||||
employees[0].setNmEmployee("山田龍也");
|
|
||||||
employees[0].setKnEmployee("ヤマダタツヤ");
|
|
||||||
employees[0].setMailAddress("yamada@hoge.jp");
|
|
||||||
employees[0].setPassword("aaa");
|
|
||||||
employees[0].setIdDepartment("10");
|
|
||||||
|
|
||||||
employees[1].setIdEmployee("10001");
|
|
||||||
employees[1].setNmEmployee("高橋準");
|
|
||||||
employees[1].setKnEmployee("タカハシジュン");
|
|
||||||
employees[1].setMailAddress("jtaka@hoge.jp");
|
|
||||||
employees[1].setPassword("bbb");
|
|
||||||
employees[1].setIdDepartment("10");
|
|
||||||
|
|
||||||
employees[2].setIdEmployee("10002");
|
|
||||||
employees[2].setNmEmployee("麻枝史明");
|
|
||||||
employees[2].setKnEmployee("ヤマダタツヤ");
|
|
||||||
employees[2].setMailAddress("fmak@hoge.jp");
|
|
||||||
employees[2].setPassword("ccc");
|
|
||||||
employees[2].setIdDepartment("11");
|
|
||||||
|
|
||||||
employees[3].setIdEmployee("10003");
|
|
||||||
employees[3].setNmEmployee("丸戸章介");
|
|
||||||
employees[3].setKnEmployee("マルトショウスケ");
|
|
||||||
employees[3].setMailAddress("marusyo@hoge.jp");
|
|
||||||
employees[3].setPassword("ddd");
|
|
||||||
employees[3].setIdDepartment("12");
|
|
||||||
|
|
||||||
employees[4].setIdEmployee("10004");
|
|
||||||
employees[4].setNmEmployee("三宅武");
|
|
||||||
employees[4].setKnEmployee("ミヤケタケシ");
|
|
||||||
employees[4].setMailAddress("miya@hoge.jp");
|
|
||||||
employees[4].setPassword ("eee");
|
|
||||||
employees[4].setIdDepartment("13");
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
BaseData employee0 = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
|
|
||||||
BaseData employee1 = new EmployeeData("10001", "高橋準", "タカハシジュン", "jtaka@hoge.jp", "bbb", "10");
|
|
||||||
BaseData employee2 = new EmployeeData("10002", "麻枝史明 ", "マエダフミアキ", "fmak@hoge.jp", "ccc", "11");
|
|
||||||
BaseData employee3 = new EmployeeData("10003", "丸戸章介", "マルトショウスケ", "marusyo@hoge.jp", "ddd", "12");
|
|
||||||
BaseData employee4 = new EmployeeData("10004", "三宅武", "ミヤケタケシ", "miya@hoge.jp", "eee", "13");
|
|
||||||
|
|
||||||
BaseData[] employees = {
|
|
||||||
employee0,
|
|
||||||
employee1,
|
|
||||||
employee2,
|
|
||||||
employee3,
|
|
||||||
employee4
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < employees.length; i++) {
|
|
||||||
System.out.println(employees[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("現在の社員データ件数:" + EmployeeData.getEmpCount() + "件");
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
for(int i= 0;i < employees.length; i++) {
|
|
||||||
employees[i].showInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("10002 を検索します");
|
|
||||||
System.out.println(employees[2].isMatchId("10002"));
|
|
||||||
|
|
||||||
System.out.println("99999 を検索します");
|
|
||||||
System.out.println(employees[2].isMatchId("99999"));
|
|
||||||
*/
|
|
||||||
|
|
||||||
// System.out.println("検索したい社員IDを入力してください");
|
|
||||||
// Scanner sc = new Scanner(System.in);
|
|
||||||
|
|
||||||
// String searchId = sc.nextLine();
|
|
||||||
// boolean found = false;
|
|
||||||
|
|
||||||
// for (int i = 0; i < employees.length; i++) {
|
|
||||||
|
|
||||||
// if (employees[i].isMatchId(searchId)) {
|
|
||||||
|
|
||||||
// employees[i].showInfo();
|
|
||||||
|
|
||||||
// found = true;
|
|
||||||
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (!found) {
|
|
||||||
// System.out.println("該当する社員が見つかりませんでした");
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
//5段階目
|
|
||||||
BaseData[] employees = new BaseData[5];
|
|
||||||
|
|
||||||
employees[0] = new EmployeeData(
|
|
||||||
"10000",
|
|
||||||
"山田龍也",
|
|
||||||
"ヤマダタツヤ",
|
|
||||||
"yamada@hoge.jp",
|
|
||||||
"aaa",
|
|
||||||
"10"
|
|
||||||
);
|
|
||||||
|
|
||||||
employees[1] = new EmployeeData(
|
|
||||||
"10001",
|
|
||||||
"高橋準",
|
|
||||||
"タカハシジュン",
|
|
||||||
"jtaka@hoge.jp",
|
|
||||||
"bbb",
|
|
||||||
"10"
|
|
||||||
);
|
|
||||||
|
|
||||||
employees[2] = new EmployeeData(
|
|
||||||
"10002",
|
|
||||||
"麻枝史明",
|
|
||||||
"ヤマダタツヤ",
|
|
||||||
"fmak@hoge.jp",
|
|
||||||
"ccc",
|
|
||||||
"11"
|
|
||||||
);
|
|
||||||
|
|
||||||
employees[3] = new EmployeeData(
|
|
||||||
"10003",
|
|
||||||
"丸戸章介",
|
|
||||||
"マルトショウスケ",
|
|
||||||
"marusyo@hoge.jp",
|
|
||||||
"ddd",
|
|
||||||
"12"
|
|
||||||
);
|
|
||||||
|
|
||||||
employees[4] = new EmployeeData(
|
|
||||||
"10004",
|
|
||||||
"三宅武",
|
|
||||||
"ミヤケタケシ",
|
|
||||||
"miya@hoge.jp",
|
|
||||||
"eee",
|
|
||||||
"13"
|
|
||||||
);
|
|
||||||
|
|
||||||
System.out.println("検索したい社員IDを入力してください");
|
|
||||||
Scanner sc = new Scanner(System.in);
|
|
||||||
|
|
||||||
String searchId = sc.nextLine();
|
|
||||||
boolean found = false;
|
|
||||||
|
|
||||||
for (int i = 0; i < employees.length; i++) {
|
|
||||||
|
|
||||||
if(employees[i].getPrimaryKeyValue().equals(searchId)) {
|
|
||||||
|
|
||||||
System.out.println(employees[i].toString());
|
|
||||||
|
|
||||||
found = true;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
System.out.println("該当する社員が見つかりませんでした");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6段階目
|
|
||||||
BaseData[] allData = new BaseData[11];
|
|
||||||
|
|
||||||
for (int i = 0; i < employees.length; i++) {
|
|
||||||
allData[i] = employees[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DepartmentData dept1 = new DepartmentData();
|
|
||||||
dept1.setIdDepartment("10");
|
|
||||||
dept1.setNmDepartment("役員");
|
|
||||||
allData[5] = dept1;
|
|
||||||
|
|
||||||
DepartmentData dept2 = new DepartmentData();
|
|
||||||
dept2.setIdDepartment("11");
|
|
||||||
dept2.setNmDepartment("人事・総務部");
|
|
||||||
allData[6] = dept2;
|
|
||||||
|
|
||||||
DepartmentData dept3 = new DepartmentData();
|
|
||||||
dept3.setIdDepartment("12");
|
|
||||||
dept3.setNmDepartment("経理部");
|
|
||||||
allData[7] = dept3;
|
|
||||||
|
|
||||||
DepartmentData dept4 = new DepartmentData();
|
|
||||||
dept4.setIdDepartment("13");
|
|
||||||
dept4.setNmDepartment("システム開発事業部");
|
|
||||||
allData[8] = dept4;
|
|
||||||
|
|
||||||
DepartmentData dept5 = new DepartmentData();
|
|
||||||
dept5.setIdDepartment("14");
|
|
||||||
dept5.setNmDepartment("教育事業部");
|
|
||||||
allData[9] = dept5;
|
|
||||||
|
|
||||||
DepartmentData dept6 = new DepartmentData();
|
|
||||||
dept6.setIdDepartment("15");
|
|
||||||
dept6.setNmDepartment("営業企画部");
|
|
||||||
allData[10] = dept6;
|
|
||||||
|
|
||||||
for (BaseData data : allData) {
|
|
||||||
System.out.println(data.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
|
|
||||||
public class Shape {
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public Shape(String name) {
|
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public double area() {
|
|
||||||
return 0.0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showInfo() {
|
|
||||||
System.out.println(this.name + "の面積は" + this.area() + "です");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
|
|
||||||
public class Student {
|
|
||||||
int studentId;
|
|
||||||
String name;
|
|
||||||
|
|
||||||
public void printProfile() {
|
|
||||||
System.out.println("学籍番号:" + this.studentId + " 名前:" + this.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Student(int studentId, String name) {
|
|
||||||
this.studentId = studentId;
|
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
studentCount++;
|
|
||||||
|
|
||||||
}
|
|
||||||
static int studentCount = 0;
|
|
||||||
|
|
||||||
public static int getStudentCount() {
|
|
||||||
return studentCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
6
DepartmentData.csv
Normal file
6
DepartmentData.csv
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
10,役員
|
||||||
|
11,人事・総務部
|
||||||
|
12,経理部
|
||||||
|
13,システム開発事業部
|
||||||
|
14,教育事業部
|
||||||
|
15,営業企画部
|
||||||
|
11
EmployeeData.csv
Normal file
11
EmployeeData.csv
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
10000,山田龍也,ヤマダタツヤ,yamada@hoge.jp,aaa,10
|
||||||
|
10001,高橋準,タカハシジュン,jtaka@hoge.jp,bbb,10
|
||||||
|
10002,麻枝史明,マエダフミアキ,fmak@hoge.jp,ccc,11
|
||||||
|
10003,丸戸章介,マルトショウスケ,marusyo@hoge.jp,ddd,12
|
||||||
|
10004,三宅武,ミヤケタケシ,miya@hoge.jp,eee,13
|
||||||
|
10005,丸井悠,マルイハルカ,haru@hoge.jp,fff,13
|
||||||
|
10006,涼元香織,スズモトカオリ,suzumoto@hoge.jp,ggg,13
|
||||||
|
10007,葉山稔,ハヤマミノル,mhayama@hoge.jp,hhh,14
|
||||||
|
10008,川上朱里,カワカミアカリ,kawakami@hoge.jp,iii,14
|
||||||
|
10009,杉井肇,スギイハジメ,sugi@hoge.jp,jjj,15
|
||||||
|
12345,石原,イシハラ,tesr,test,10
|
||||||
|
@@ -1,27 +1,118 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
public class EmployeeData {
|
public class EmployeeData {
|
||||||
String idEmployee;
|
//社員ID
|
||||||
String nmEmployee;
|
private String idEmployee;
|
||||||
String knEmployee;
|
//社員名
|
||||||
String mailAddress;
|
private String nmEmployee;
|
||||||
String password;
|
//社員名カナ
|
||||||
String idDepartment;
|
private String knEmployee;
|
||||||
/*
|
//メールアドレス
|
||||||
public void output() {
|
private String mailAddress;
|
||||||
System.out.println(this.idEmployee);
|
//パスワード
|
||||||
System.out.println(this.nmEmployee);
|
private String password;
|
||||||
System.out.println(this.knEmployee);
|
//部署ID
|
||||||
System.out.println(this.mailAddress);
|
private String idDepartment;
|
||||||
System.out.println(this.password);
|
//社員データ件数
|
||||||
System.out.println(this.idDepartment);
|
private static int empCount = 0;
|
||||||
|
//コンストラクタ
|
||||||
|
public EmployeeData() {
|
||||||
|
empCount++;
|
||||||
}
|
}
|
||||||
*/
|
//コンストラクタ
|
||||||
public void showInfo() {
|
public EmployeeData(
|
||||||
System.out.println(this.idEmployee + "\t" + this.nmEmployee + this.knEmployee +"\t" + this.mailAddress + "\t" + this.password + "\t" + this.idDepartment );
|
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 String getNmEmployee() {
|
||||||
|
return nmEmployee;
|
||||||
|
}
|
||||||
|
public String getKnEmployee() {
|
||||||
|
return knEmployee;
|
||||||
|
}
|
||||||
|
public String getMailAddress() {
|
||||||
|
return mailAddress;
|
||||||
|
}
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
public String getIdDepartment() {
|
||||||
|
return idDepartment;
|
||||||
|
}
|
||||||
|
//セッター
|
||||||
|
public void setIdEmployee(String idEmployee) {
|
||||||
|
//nullチェック
|
||||||
|
if (idEmployee == null) {
|
||||||
|
System.out.println("社員IDが空のため設定できませんでした");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//空文字チェック
|
||||||
|
if (idEmployee.trim().isEmpty()) {
|
||||||
|
System.out.println( "社員IDが空のため設定できませんでした");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.idEmployee = idEmployee;
|
||||||
|
}
|
||||||
|
public void setNmEmployee(String nmEmployee) {
|
||||||
|
//nullチェック
|
||||||
|
if (nmEmployee == null) {
|
||||||
|
System.out.println("社員名が空のため設定できませんでした");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//空文字チェック
|
||||||
|
if (nmEmployee.trim().isEmpty()) {
|
||||||
|
System.out.println("社員名が空のため設定できませんでした");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.nmEmployee = nmEmployee;
|
||||||
|
}
|
||||||
|
public void setKnEmployee(String knEmployee) {
|
||||||
|
this.knEmployee = knEmployee;
|
||||||
|
}
|
||||||
|
public void setMailAddress(String mailAddress) {
|
||||||
|
this.mailAddress = mailAddress;
|
||||||
|
}
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
public void setIdDepartment(String idDepartment) {
|
||||||
|
this.idDepartment = idDepartment;
|
||||||
|
}
|
||||||
|
//toString
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
|
return getIdEmployee() + "\t"
|
||||||
|
+ getNmEmployee() + "\t"
|
||||||
|
+ getKnEmployee() + "\t"
|
||||||
|
+ getMailAddress() + "\t"
|
||||||
|
+ getPassword() + "\t"
|
||||||
|
+ getIdDepartment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ID一致判定
|
||||||
public boolean isMatchId(String id) {
|
public boolean isMatchId(String id) {
|
||||||
return id.equals(this.idEmployee);
|
return getIdEmployee().equals(id);
|
||||||
|
}
|
||||||
|
//件数取得
|
||||||
|
public static int getEmpCount() {
|
||||||
|
return empCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,49 +1,52 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
public class Item {
|
public class Item {
|
||||||
|
|
||||||
|
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
|
||||||
private String name;
|
private String name;
|
||||||
private int price;
|
private int price;
|
||||||
private int stock;
|
private int stock;
|
||||||
|
|
||||||
|
//商品
|
||||||
|
public void sell(int amount) {
|
||||||
|
//在庫減らし
|
||||||
|
this.setStock(this.getStock() - amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
//商品名ゲッター
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
//商品名セッター
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
//価格ゲッター
|
||||||
public int getPrice() {
|
public int getPrice() {
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
|
//価格セッター
|
||||||
public void setPrice(int price) {
|
public void setPrice(int price) {
|
||||||
this.price = price;
|
this.price = price;
|
||||||
}
|
}
|
||||||
|
//在庫数ゲッター
|
||||||
public int getStock() {
|
public int getStock() {
|
||||||
return stock;
|
return stock;
|
||||||
}
|
}
|
||||||
|
//在庫数セッター
|
||||||
public void setStock(int stock) {
|
public void setStock(int stock) {
|
||||||
this.stock = stock;
|
this.stock = stock;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sell(int amount) {
|
|
||||||
//this.stock = this.stock - amount;
|
|
||||||
this.setStock(this.getStock() - amount);
|
|
||||||
|
|
||||||
}
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getName() + " " + getPrice() + "円 (残り" + getStock() + "個)";
|
|
||||||
}
|
return getName()
|
||||||
/*
|
+ " "
|
||||||
public int totalPrice(){
|
+ getPrice()
|
||||||
return this.price * this.stock
|
+ "円 (残り"
|
||||||
|
+ getStock()
|
||||||
|
+ "個)";
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
112
Main.java
112
Main.java
@@ -1,78 +1,80 @@
|
|||||||
|
package misson1014;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
/*
|
//配列を作成
|
||||||
EmployeeData employee = new EmployeeData();
|
|
||||||
employee.idEmployee = "10000";
|
|
||||||
employee.nmEmployee = "山田龍也";
|
|
||||||
employee.knEmployee = "ヤマダタツヤ";
|
|
||||||
employee.mailAddress = "yamada@hoge.jp";
|
|
||||||
employee.password = "aaa";
|
|
||||||
employee.idDepartment = "10";
|
|
||||||
*/
|
|
||||||
// employee.output();
|
|
||||||
// employee.showInfo();
|
|
||||||
|
|
||||||
EmployeeData[] employees = new EmployeeData[5];
|
EmployeeData[] employees = new EmployeeData[5];
|
||||||
|
|
||||||
|
//インスタンス生成
|
||||||
employees[0] = new EmployeeData();
|
employees[0] = new EmployeeData();
|
||||||
employees[1] = new EmployeeData();
|
employees[1] = new EmployeeData();
|
||||||
employees[2] = new EmployeeData();
|
employees[2] = new EmployeeData();
|
||||||
employees[3] = new EmployeeData();
|
employees[3] = new EmployeeData();
|
||||||
employees[4] = new EmployeeData();
|
employees[4] = new EmployeeData();
|
||||||
|
|
||||||
employees[0].idEmployee = "10000";
|
employees[0].setIdEmployee("10000");
|
||||||
employees[0].nmEmployee = "山田龍也";
|
employees[0].setNmEmployee("山田龍也");
|
||||||
employees[0].knEmployee = "ヤマダタツヤ";
|
employees[0].setKnEmployee("ヤマダタツヤ");
|
||||||
employees[0].mailAddress = "yamada@hoge.jp";
|
employees[0].setMailAddress("yamada@hoge.jp");
|
||||||
employees[0].password = "aaa";
|
employees[0].setPassword("aaa");
|
||||||
employees[0].idDepartment = "10";
|
employees[0].setIdDepartment("10");
|
||||||
|
|
||||||
employees[1].idEmployee = "10001";
|
employees[1].setIdEmployee("10001");
|
||||||
employees[1].nmEmployee = "高橋準";
|
employees[1].setNmEmployee("高橋準");
|
||||||
employees[1].knEmployee = "タカハシジュン";
|
employees[1].setKnEmployee("タカハシジュン");
|
||||||
employees[1].mailAddress = "jtaka@hoge.jp";
|
employees[1].setMailAddress("jtaka@hoge.jp");
|
||||||
employees[1].password = "bbb";
|
employees[1].setPassword("bbb");
|
||||||
employees[1].idDepartment = "10";
|
employees[1].setIdDepartment("10");
|
||||||
|
|
||||||
employees[2].idEmployee = "10002";
|
employees[2].setIdEmployee("10002");
|
||||||
employees[2].nmEmployee = "麻枝史明";
|
employees[2].setNmEmployee("麻枝史明");
|
||||||
employees[2].knEmployee = "ヤマダタツヤ";
|
employees[2].setKnEmployee("マエダフミアキ");
|
||||||
employees[2].mailAddress = "fmak@hoge.jp";
|
employees[2].setMailAddress("fmak@hoge.jp");
|
||||||
employees[2].password = "ccc";
|
employees[2].setPassword("ccc");
|
||||||
employees[2].idDepartment = "11";
|
employees[2].setIdDepartment("11");
|
||||||
|
|
||||||
employees[3].idEmployee = "10003";
|
employees[3].setIdEmployee("10003");
|
||||||
employees[3].nmEmployee = "丸戸章介";
|
employees[3].setNmEmployee("丸戸章介");
|
||||||
employees[3].knEmployee = "マルトショウスケ";
|
employees[3].setKnEmployee("マルトショウスケ");
|
||||||
employees[3].mailAddress = "marusyo@hoge.jp";
|
employees[3].setMailAddress("marusyo@hoge.jp");
|
||||||
employees[3].password = "ddd";
|
employees[3].setPassword("ddd");
|
||||||
employees[3].idDepartment = "12";
|
employees[3].setIdDepartment("12");
|
||||||
|
|
||||||
employees[4].idEmployee = "10004";
|
employees[4].setIdEmployee("10004");
|
||||||
employees[4].nmEmployee = "三宅武";
|
employees[4].setNmEmployee("三宅武");
|
||||||
employees[4].knEmployee = "ミヤケタケシ";
|
employees[4].setKnEmployee("ミヤケタケシ");
|
||||||
employees[4].mailAddress = "miya@hoge.jp";
|
employees[4].setMailAddress("miya@hoge.jp");
|
||||||
employees[4].password = "eee";
|
employees[4].setPassword("eee");
|
||||||
employees[4].idDepartment = "13";
|
employees[4].setIdDepartment("13");
|
||||||
|
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
//0が入力されるまでループ
|
||||||
|
while (true) {
|
||||||
|
//ID入力
|
||||||
|
System.out.println("検索したい社員IDを入力してください(終了する場合は0)");
|
||||||
|
String search = scanner.nextLine();
|
||||||
|
if (search.equals("0")) { System.out.println("システムを終了します");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//見つかったかどうか
|
||||||
|
boolean found = false;
|
||||||
|
//検索処理
|
||||||
for (int i = 0; i < employees.length; i++) {
|
for (int i = 0; i < employees.length; i++) {
|
||||||
employees[i].showInfo();
|
if (employees[i].isMatchId(search)) {
|
||||||
|
System.out.println(employees[i]);
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
/*
|
}
|
||||||
System.out.println("10002 を検索します");
|
// 見つからなかった場合
|
||||||
System.out.println(employees[2].isMatchId("10002"));
|
if (!found) {System.out.println("該当する社員が見つかりませんでした");
|
||||||
|
}
|
||||||
System.out.println("99999 を検索します");
|
}
|
||||||
System.out.println(employees[2].isMatchId("99999"));
|
scanner.close();
|
||||||
*/
|
|
||||||
System.out.println("検索したい社員IDを入力してください");
|
|
||||||
Scanner sc = new Scanner(System.in);
|
|
||||||
String str = sc.nextLine();
|
|
||||||
System.out.println("");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
91
Main1.java
Normal file
91
Main1.java
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
|
public class Main1 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
//8段階目まで
|
||||||
|
|
||||||
|
/*
|
||||||
|
EmployeeData[] employees = new EmployeeData[5];
|
||||||
|
|
||||||
|
employees[0] = new EmployeeData();
|
||||||
|
employees[1] = new EmployeeData();
|
||||||
|
employees[2] = new EmployeeData();
|
||||||
|
employees[3] = new EmployeeData();
|
||||||
|
employees[4] = new EmployeeData();
|
||||||
|
|
||||||
|
employees[0].setIdEmployee("10000");
|
||||||
|
|
||||||
|
8段階用
|
||||||
|
employees[0].setNmEmployee("");
|
||||||
|
|
||||||
|
employees[0].setKnEmployee("ヤマダタツヤ");
|
||||||
|
employees[0].setMailAddress("yamada@hoge.jp");
|
||||||
|
employees[0].setPassword("aaa");
|
||||||
|
employees[0].setIdDepartment("10");
|
||||||
|
|
||||||
|
employees[1].setIdEmployee("10001");
|
||||||
|
employees[1].setNmEmployee("高橋準");
|
||||||
|
employees[1].setKnEmployee("タカハシジュン");
|
||||||
|
employees[1].setMailAddress("jtaka@hoge.jp");
|
||||||
|
employees[1].setPassword("bbb");
|
||||||
|
employees[1].setIdDepartment("10");
|
||||||
|
|
||||||
|
employees[2].setIdEmployee("10002");
|
||||||
|
employees[2].setNmEmployee("麻枝史明");
|
||||||
|
employees[2].setKnEmployee("マエダフミアキ");
|
||||||
|
employees[2].setMailAddress("fmak@hoge.jp");
|
||||||
|
employees[2].setPassword("ccc");
|
||||||
|
employees[2].setIdDepartment("11");
|
||||||
|
|
||||||
|
employees[3].setIdEmployee("10003");
|
||||||
|
employees[3].setNmEmployee("丸戸章介");
|
||||||
|
employees[3].setKnEmployee("マルトショウスケ");
|
||||||
|
employees[3].setMailAddress("marusyo@hoge.jp");
|
||||||
|
employees[3].setPassword("ddd");
|
||||||
|
employees[3].setIdDepartment("12");
|
||||||
|
|
||||||
|
employees[4].setIdEmployee("10004");
|
||||||
|
employees[4].setNmEmployee("三宅武");
|
||||||
|
employees[4].setKnEmployee("ミヤケタケシ");
|
||||||
|
employees[4].setMailAddress("miya@hoge.jp");
|
||||||
|
employees[4].setPassword("eee");
|
||||||
|
employees[4].setIdDepartment("13");
|
||||||
|
|
||||||
|
for (int i = 0; i < employees.length; i++) {
|
||||||
|
|
||||||
|
System.out.println(employees[i]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
"現在の社員データ件数:"
|
||||||
|
+ EmployeeData.getEmpCount()
|
||||||
|
+ "件");
|
||||||
|
*/
|
||||||
|
|
||||||
|
//ここから9段階↓
|
||||||
|
EmployeeData employee1 =
|
||||||
|
new EmployeeData(
|
||||||
|
"10000",
|
||||||
|
"",
|
||||||
|
"ヤマダタツヤ",
|
||||||
|
"yamada@hoge.jp",
|
||||||
|
"aaa",
|
||||||
|
"10"
|
||||||
|
);
|
||||||
|
|
||||||
|
EmployeeData employee2 =
|
||||||
|
new EmployeeData(
|
||||||
|
"",
|
||||||
|
"山田龍也",
|
||||||
|
"ヤマダタツヤ",
|
||||||
|
"yamada@hoge.jp",
|
||||||
|
"aaa",
|
||||||
|
"10"
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
31
Student.java
Normal file
31
Student.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
|
public class Student {
|
||||||
|
int studentId;
|
||||||
|
String name;
|
||||||
|
//staticフィールド
|
||||||
|
static int studentCount = 0;
|
||||||
|
|
||||||
|
//コンストラクタ
|
||||||
|
public Student(int studentId, String name) {
|
||||||
|
//フィールド代入
|
||||||
|
this.studentId = studentId;
|
||||||
|
this.name = name;
|
||||||
|
studentCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//学生情報
|
||||||
|
void printProfile() {
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
"学籍番号:" + this.studentId
|
||||||
|
+ " 名前:" + this.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
//現在の学生数用staticメソッド
|
||||||
|
public static int getStudentCount() {
|
||||||
|
return studentCount;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<projectDescription>
|
<projectDescription>
|
||||||
<name>CUI_EM_OOP</name>
|
<name>misson1014</name>
|
||||||
<comment></comment>
|
<comment></comment>
|
||||||
<projects>
|
<projects>
|
||||||
</projects>
|
</projects>
|
||||||
BIN
misson1014/bin/misson1014/BaseData.class
Normal file
BIN
misson1014/bin/misson1014/BaseData.class
Normal file
Binary file not shown.
BIN
misson1014/bin/misson1014/BasicCheck1.class
Normal file
BIN
misson1014/bin/misson1014/BasicCheck1.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
misson1014/bin/misson1014/Book.class
Normal file
BIN
misson1014/bin/misson1014/Book.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
misson1014/bin/misson1014/Day3Check1.class
Normal file
BIN
misson1014/bin/misson1014/Day3Check1.class
Normal file
Binary file not shown.
BIN
misson1014/bin/misson1014/DepartmentData.class
Normal file
BIN
misson1014/bin/misson1014/DepartmentData.class
Normal file
Binary file not shown.
BIN
misson1014/bin/misson1014/EmployeeData.class
Normal file
BIN
misson1014/bin/misson1014/EmployeeData.class
Normal file
Binary file not shown.
BIN
misson1014/bin/misson1014/Item.class
Normal file
BIN
misson1014/bin/misson1014/Item.class
Normal file
Binary file not shown.
BIN
misson1014/bin/misson1014/Main.class
Normal file
BIN
misson1014/bin/misson1014/Main.class
Normal file
Binary file not shown.
BIN
misson1014/bin/misson1014/Main1.class
Normal file
BIN
misson1014/bin/misson1014/Main1.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
misson1014/bin/misson1014/Student.class
Normal file
BIN
misson1014/bin/misson1014/Student.class
Normal file
Binary file not shown.
10
misson1014/src/misson1014/BaseData.java
Normal file
10
misson1014/src/misson1014/BaseData.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
|
public abstract class BaseData {
|
||||||
|
|
||||||
|
public abstract String toString();
|
||||||
|
|
||||||
|
public abstract String toCSV();
|
||||||
|
|
||||||
|
public abstract String getPrimaryKeyValue();
|
||||||
|
}
|
||||||
27
misson1014/src/misson1014/BasicCheck1.java
Normal file
27
misson1014/src/misson1014/BasicCheck1.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
|
public class BasicCheck1 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
//コンストラクタ
|
||||||
|
Book book1 = new Book();
|
||||||
|
|
||||||
|
//book1
|
||||||
|
System.out.println(book1.title);
|
||||||
|
System.out.println(book1.author);
|
||||||
|
System.out.println(book1.price);
|
||||||
|
|
||||||
|
//コンストラクタ
|
||||||
|
Book book2 = new Book(
|
||||||
|
"銀河鉄道の夜",
|
||||||
|
"宮沢賢治",
|
||||||
|
500);
|
||||||
|
|
||||||
|
//book2
|
||||||
|
System.out.println(book2.title);
|
||||||
|
System.out.println(book2.author);
|
||||||
|
System.out.println(book2.price);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
23
misson1014/src/misson1014/BasicCheck2.java
Normal file
23
misson1014/src/misson1014/BasicCheck2.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
|
public class BasicCheck2 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
Student student1 = new Student(1, "鈴木一郎");
|
||||||
|
Student student2 = new Student(2, "田中花子");
|
||||||
|
Student student3 = new Student(3, "佐藤次郎");
|
||||||
|
|
||||||
|
// 学生情報表示
|
||||||
|
student1.printProfile();
|
||||||
|
student2.printProfile();
|
||||||
|
student3.printProfile();
|
||||||
|
|
||||||
|
// 現在の学生数表示
|
||||||
|
System.out.println(
|
||||||
|
"現在の生徒数:"
|
||||||
|
+ Student.getStudentCount()
|
||||||
|
+ "人");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
37
misson1014/src/misson1014/BasicCheck3.java
Normal file
37
misson1014/src/misson1014/BasicCheck3.java
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
|
public class BasicCheck3 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
// Item型の配列を作成
|
||||||
|
Item[] items = new Item[3];
|
||||||
|
|
||||||
|
//インスタンス生成
|
||||||
|
items[0] = new Item();
|
||||||
|
items[1] = new Item();
|
||||||
|
items[2] = new Item();
|
||||||
|
|
||||||
|
items[0].setName("ノート");
|
||||||
|
items[0].setPrice(120);
|
||||||
|
items[0].setStock(50);
|
||||||
|
|
||||||
|
items[1].setName("消しゴム");
|
||||||
|
items[1].setPrice(80);
|
||||||
|
items[1].setStock(30);
|
||||||
|
|
||||||
|
items[2].setName("鉛筆");
|
||||||
|
items[2].setPrice(60);
|
||||||
|
items[2].setStock(100);
|
||||||
|
|
||||||
|
//販売
|
||||||
|
for (int i = 0; i < items.length; i++) {
|
||||||
|
items[i].sell(5);
|
||||||
|
}
|
||||||
|
//商品情報表示
|
||||||
|
for (int i = 0; i < items.length; i++) {
|
||||||
|
System.out.println(items[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
28
misson1014/src/misson1014/Book.java
Normal file
28
misson1014/src/misson1014/Book.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
|
public class Book {
|
||||||
|
// タイトル
|
||||||
|
String title;
|
||||||
|
// 著者
|
||||||
|
String author;
|
||||||
|
// 価格
|
||||||
|
int price;
|
||||||
|
|
||||||
|
//コンストラクタ
|
||||||
|
public Book() {
|
||||||
|
|
||||||
|
this.title = "タイトル未設定";
|
||||||
|
this.author = "著者未設定";
|
||||||
|
this.price = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//コンストラクタ
|
||||||
|
public Book(String title, String author, int price) {
|
||||||
|
|
||||||
|
//フィールド代入
|
||||||
|
this.title = title;
|
||||||
|
this.author = author;
|
||||||
|
this.price = price;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
public class Circle extends Shape {
|
public class Circle extends Shape {
|
||||||
|
|
||||||
@@ -6,15 +7,15 @@ public class Circle extends Shape{
|
|||||||
public Circle(double radius) {
|
public Circle(double radius) {
|
||||||
|
|
||||||
super("円");
|
super("円");
|
||||||
|
|
||||||
this.radius = radius;
|
this.radius = radius;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double area() {
|
public double area() {
|
||||||
return Math.PI * radius * radius;
|
return Math.PI * this.radius * this.radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showInfo() {
|
public void showInfo() {
|
||||||
super.showInfo();
|
super.showInfo();
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
public class Day3Check1 {
|
public class Day3Check1 {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
Circle circle = new Circle(2);
|
Circle circle = new Circle(2);
|
||||||
|
|
||||||
circle.showInfo();
|
circle.showInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
38
misson1014/src/misson1014/DepartmentData.java
Normal file
38
misson1014/src/misson1014/DepartmentData.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
|
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 getIdDepartment() + "\t" + getNmDepartment();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toCSV() {
|
||||||
|
return getIdDepartment() + "," + getNmDepartment();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPrimaryKeyValue() {
|
||||||
|
return getIdDepartment();
|
||||||
|
}
|
||||||
|
}
|
||||||
147
misson1014/src/misson1014/EmployeeData.java
Normal file
147
misson1014/src/misson1014/EmployeeData.java
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
|
public class EmployeeData extends BaseData {
|
||||||
|
//社員ID
|
||||||
|
private String idEmployee;
|
||||||
|
//社員名
|
||||||
|
private String nmEmployee;
|
||||||
|
//社員名カナ
|
||||||
|
private String knEmployee;
|
||||||
|
//メールアドレス
|
||||||
|
private String mailAddress;
|
||||||
|
//パスワード
|
||||||
|
private String password;
|
||||||
|
//部署ID
|
||||||
|
private String idDepartment;
|
||||||
|
//社員データ件数
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//ゲッター
|
||||||
|
public String getIdEmployee() {
|
||||||
|
return idEmployee;
|
||||||
|
}
|
||||||
|
public String getNmEmployee() {
|
||||||
|
return nmEmployee;
|
||||||
|
}
|
||||||
|
public String getKnEmployee() {
|
||||||
|
return knEmployee;
|
||||||
|
}
|
||||||
|
public String getMailAddress() {
|
||||||
|
return mailAddress;
|
||||||
|
}
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
public String getIdDepartment() {
|
||||||
|
return idDepartment;
|
||||||
|
}
|
||||||
|
//セッター
|
||||||
|
public void setIdEmployee(String idEmployee) {
|
||||||
|
|
||||||
|
if (idEmployee == null) {
|
||||||
|
System.out.println("社員IDが空のため設定できませんでした");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (idEmployee.trim().isEmpty()) {
|
||||||
|
System.out.println("社員IDが空のため設定できませんでした");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.idEmployee = idEmployee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNmEmployee(String nmEmployee) {
|
||||||
|
|
||||||
|
if (nmEmployee == null) {
|
||||||
|
System.out.println("社員名が空のため設定できませんでした");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nmEmployee.trim().isEmpty()) {
|
||||||
|
System.out.println("社員名が空のため設定できませんでした");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.nmEmployee = nmEmployee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKnEmployee(String knEmployee) {
|
||||||
|
this.knEmployee = knEmployee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMailAddress(String mailAddress) {
|
||||||
|
this.mailAddress = mailAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdDepartment(String idDepartment) {
|
||||||
|
this.idDepartment = idDepartment;
|
||||||
|
}
|
||||||
|
|
||||||
|
//toString
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
|
return getIdEmployee() + "\t"
|
||||||
|
+ getNmEmployee() + "\t"
|
||||||
|
+ getKnEmployee() + "\t"
|
||||||
|
+ getMailAddress() + "\t"
|
||||||
|
+ getPassword() + "\t"
|
||||||
|
+ getIdDepartment();
|
||||||
|
}
|
||||||
|
|
||||||
|
//CSV形式へ変換
|
||||||
|
@Override
|
||||||
|
public String toCSV() {
|
||||||
|
|
||||||
|
return getIdEmployee() + ","
|
||||||
|
+ getNmEmployee() + ","
|
||||||
|
+ getKnEmployee() + ","
|
||||||
|
+ getMailAddress() + ","
|
||||||
|
+ getPassword() + ","
|
||||||
|
+ getIdDepartment();
|
||||||
|
}
|
||||||
|
|
||||||
|
//キー取得
|
||||||
|
@Override
|
||||||
|
public String getPrimaryKeyValue() {
|
||||||
|
|
||||||
|
return getIdEmployee();
|
||||||
|
}
|
||||||
|
|
||||||
|
//ID一致判定
|
||||||
|
public boolean isMatchId(String id) {
|
||||||
|
return getIdEmployee().equals(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
//件数取得
|
||||||
|
public static int getEmpCount() {
|
||||||
|
return empCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
52
misson1014/src/misson1014/Item.java
Normal file
52
misson1014/src/misson1014/Item.java
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
|
public class Item {
|
||||||
|
private String name;
|
||||||
|
private int price;
|
||||||
|
private int stock;
|
||||||
|
|
||||||
|
//商品
|
||||||
|
public void sell(int amount) {
|
||||||
|
//在庫減らし
|
||||||
|
this.setStock(this.getStock() - amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
//商品名ゲッター
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
//商品名セッター
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
//価格ゲッター
|
||||||
|
public int getPrice() {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
//価格セッター
|
||||||
|
public void setPrice(int price) {
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
//在庫数ゲッター
|
||||||
|
public int getStock() {
|
||||||
|
return stock;
|
||||||
|
}
|
||||||
|
//在庫数セッター
|
||||||
|
public void setStock(int stock) {
|
||||||
|
this.stock = stock;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
|
return getName()
|
||||||
|
+ " "
|
||||||
|
+ getPrice()
|
||||||
|
+ "円 (残り"
|
||||||
|
+ getStock()
|
||||||
|
+ "個)";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
241
misson1014/src/misson1014/Main.java
Normal file
241
misson1014/src/misson1014/Main.java
Normal file
@@ -0,0 +1,241 @@
|
|||||||
|
package misson1014;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
//社員データ格納用配列作成
|
||||||
|
//EmployeeDataをBaseDataとして管理する
|
||||||
|
//(ポリモーフィズム)
|
||||||
|
BaseData[] employees = new BaseData[5];
|
||||||
|
|
||||||
|
//社員データ用インスタンス
|
||||||
|
employees[0] = new EmployeeData();
|
||||||
|
employees[1] = new EmployeeData();
|
||||||
|
employees[2] = new EmployeeData();
|
||||||
|
employees[3] = new EmployeeData();
|
||||||
|
employees[4] = new EmployeeData();
|
||||||
|
employees[0] = new EmployeeData();
|
||||||
|
employees[1] = new EmployeeData();
|
||||||
|
employees[2] = new EmployeeData();
|
||||||
|
employees[3] = new EmployeeData();
|
||||||
|
employees[4] = new EmployeeData();
|
||||||
|
|
||||||
|
//社員情報設定
|
||||||
|
//BaseData型なのでEmployeeDataへ
|
||||||
|
//キャストしてセッターを利用する
|
||||||
|
((EmployeeData) employees[0]).setIdEmployee("10000");
|
||||||
|
((EmployeeData) employees[0]).setNmEmployee("山田龍也");
|
||||||
|
((EmployeeData) employees[0]).setKnEmployee("ヤマダタツヤ");
|
||||||
|
((EmployeeData) employees[0]).setMailAddress("yamada@hoge.jp");
|
||||||
|
((EmployeeData) employees[0]).setPassword("aaa");
|
||||||
|
((EmployeeData) employees[0]).setIdDepartment("10");
|
||||||
|
|
||||||
|
((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");
|
||||||
|
|
||||||
|
((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");
|
||||||
|
|
||||||
|
((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");
|
||||||
|
|
||||||
|
((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");
|
||||||
|
|
||||||
|
//6段階目
|
||||||
|
//EmployeeDataとDepartmentDataを同じBaseData配列で管理する
|
||||||
|
//全データ格納用
|
||||||
|
BaseData[] allData = new BaseData[11];
|
||||||
|
|
||||||
|
//社員データをallDataへ格納
|
||||||
|
for (int i = 0; i < employees.length; i++) {
|
||||||
|
allData[i] = employees[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
//部署データ作成
|
||||||
|
//先にDepartmentData型で生成
|
||||||
|
//値を設定後にallDataへ格納する
|
||||||
|
DepartmentData dept;
|
||||||
|
|
||||||
|
dept = new DepartmentData();
|
||||||
|
dept.setIdDepartment("10");
|
||||||
|
dept.setNmDepartment("役員");
|
||||||
|
allData[5] = dept;
|
||||||
|
|
||||||
|
dept = new DepartmentData();
|
||||||
|
dept.setIdDepartment("11");
|
||||||
|
dept.setNmDepartment("人事・総務部");
|
||||||
|
allData[6] = dept;
|
||||||
|
|
||||||
|
dept = new DepartmentData();
|
||||||
|
dept.setIdDepartment("12");
|
||||||
|
dept.setNmDepartment("経理部");
|
||||||
|
allData[7] = dept;
|
||||||
|
|
||||||
|
dept = new DepartmentData();
|
||||||
|
dept.setIdDepartment("13");
|
||||||
|
dept.setNmDepartment("システム開発事業部");
|
||||||
|
allData[8] = dept;
|
||||||
|
|
||||||
|
dept = new DepartmentData();
|
||||||
|
dept.setIdDepartment("14");
|
||||||
|
dept.setNmDepartment("教育事業部");
|
||||||
|
allData[9] = dept;
|
||||||
|
|
||||||
|
dept = new DepartmentData();
|
||||||
|
dept.setIdDepartment("15");
|
||||||
|
dept.setNmDepartment("営業企画部");
|
||||||
|
allData[10] = dept;
|
||||||
|
|
||||||
|
//BaseData配列を全件表示
|
||||||
|
//EmployeeDataとDepartmentDataでオーバーライドされたtoString()が実行
|
||||||
|
for (int i = 0; i < allData.length; i++) {
|
||||||
|
System.out.println(allData[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//7段階目
|
||||||
|
//instanceofを使って型を判定
|
||||||
|
//EmployeeData件数とDepartmentData件数を集計
|
||||||
|
int employeeCount = 0;
|
||||||
|
int departmentCount = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < allData.length; i++) {
|
||||||
|
|
||||||
|
if (allData[i] instanceof EmployeeData) {
|
||||||
|
employeeCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allData[i] instanceof DepartmentData) {
|
||||||
|
departmentCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//集計結果表示
|
||||||
|
System.out.println("社員データ:" + employeeCount + "件");
|
||||||
|
System.out.println("部署データ:" + departmentCount + "件");
|
||||||
|
|
||||||
|
|
||||||
|
//8段階目
|
||||||
|
//EmployeeDataへキャストしてメールアドレスを取得する
|
||||||
|
for (int i = 0; i < allData.length; i++) {
|
||||||
|
|
||||||
|
if (allData[i] instanceof EmployeeData) {
|
||||||
|
|
||||||
|
EmployeeData employee = (EmployeeData) allData[i];
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
employee.getMailAddress()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
//9段階目
|
||||||
|
//入力した部署名に所属する社員を検索
|
||||||
|
//部署名から部署IDを取得
|
||||||
|
//部署IDと一致する社員を検索
|
||||||
|
//社員名とメールアドレスを表示
|
||||||
|
|
||||||
|
System.out.println("検索したい部署名を入力してください");
|
||||||
|
String departmentName = scanner.nextLine();
|
||||||
|
|
||||||
|
//該当部署の部署ID
|
||||||
|
String targetDepartmentId = null;
|
||||||
|
|
||||||
|
//部署見つかったか
|
||||||
|
boolean departmentFound = false;
|
||||||
|
|
||||||
|
//部署検索
|
||||||
|
for (int i = 0; i < allData.length; i++) {
|
||||||
|
|
||||||
|
if (allData[i] instanceof DepartmentData) {
|
||||||
|
DepartmentData department =(DepartmentData) allData[i];
|
||||||
|
if (department.getNmDepartment().equals(departmentName)) {
|
||||||
|
targetDepartmentId = department.getIdDepartment();
|
||||||
|
departmentFound = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//部署が存在した場合
|
||||||
|
if (departmentFound) {
|
||||||
|
|
||||||
|
System.out.println("所属社員一覧");
|
||||||
|
for (int i = 0; i < allData.length; i++) {
|
||||||
|
if (allData[i] instanceof EmployeeData) {
|
||||||
|
EmployeeData employee =(EmployeeData) allData[i];
|
||||||
|
if (employee.getIdDepartment().equals(targetDepartmentId)) {
|
||||||
|
System.out.println(employee.getNmEmployee()
|
||||||
|
+ "\t"
|
||||||
|
+ employee.getMailAddress()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
"該当する部署が見つかりませんでした");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//三日目4段階目用
|
||||||
|
//System.out.println(employees[0].toCSV());
|
||||||
|
//System.out.println(employees[0].getPrimaryKeyValue());
|
||||||
|
|
||||||
|
//検索機能
|
||||||
|
//ループ
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
System.out.println("検索したい社員IDを入力してください(終了する場合は0)");
|
||||||
|
|
||||||
|
String search = scanner.nextLine();
|
||||||
|
|
||||||
|
if (search.equals("0")) {
|
||||||
|
System.out.println("システムを終了します");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean found = false;
|
||||||
|
|
||||||
|
//ID検索と比較
|
||||||
|
for (int i = 0; i < employees.length; i++) {
|
||||||
|
if (employees[i].getPrimaryKeyValue().equals(search)) {
|
||||||
|
System.out.println(employees[i]);
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//該当なし
|
||||||
|
if (!found) {
|
||||||
|
System.out.println("該当する社員が見つかりませんでした");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scanner.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
125
misson1014/src/misson1014/Main1.java
Normal file
125
misson1014/src/misson1014/Main1.java
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
|
public class Main1 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
//8段階目まで
|
||||||
|
|
||||||
|
/*
|
||||||
|
EmployeeData[] employees = new EmployeeData[5];
|
||||||
|
|
||||||
|
employees[0] = new EmployeeData();
|
||||||
|
employees[1] = new EmployeeData();
|
||||||
|
employees[2] = new EmployeeData();
|
||||||
|
employees[3] = new EmployeeData();
|
||||||
|
employees[4] = new EmployeeData();
|
||||||
|
|
||||||
|
employees[0].setIdEmployee("10000");
|
||||||
|
|
||||||
|
8段階用
|
||||||
|
employees[0].setNmEmployee("");
|
||||||
|
|
||||||
|
employees[0].setKnEmployee("ヤマダタツヤ");
|
||||||
|
employees[0].setMailAddress("yamada@hoge.jp");
|
||||||
|
employees[0].setPassword("aaa");
|
||||||
|
employees[0].setIdDepartment("10");
|
||||||
|
|
||||||
|
employees[1].setIdEmployee("10001");
|
||||||
|
employees[1].setNmEmployee("高橋準");
|
||||||
|
employees[1].setKnEmployee("タカハシジュン");
|
||||||
|
employees[1].setMailAddress("jtaka@hoge.jp");
|
||||||
|
employees[1].setPassword("bbb");
|
||||||
|
employees[1].setIdDepartment("10");
|
||||||
|
|
||||||
|
employees[2].setIdEmployee("10002");
|
||||||
|
employees[2].setNmEmployee("麻枝史明");
|
||||||
|
employees[2].setKnEmployee("マエダフミアキ");
|
||||||
|
employees[2].setMailAddress("fmak@hoge.jp");
|
||||||
|
employees[2].setPassword("ccc");
|
||||||
|
employees[2].setIdDepartment("11");
|
||||||
|
|
||||||
|
employees[3].setIdEmployee("10003");
|
||||||
|
employees[3].setNmEmployee("丸戸章介");
|
||||||
|
employees[3].setKnEmployee("マルトショウスケ");
|
||||||
|
employees[3].setMailAddress("marusyo@hoge.jp");
|
||||||
|
employees[3].setPassword("ddd");
|
||||||
|
employees[3].setIdDepartment("12");
|
||||||
|
|
||||||
|
employees[4].setIdEmployee("10004");
|
||||||
|
employees[4].setNmEmployee("三宅武");
|
||||||
|
employees[4].setKnEmployee("ミヤケタケシ");
|
||||||
|
employees[4].setMailAddress("miya@hoge.jp");
|
||||||
|
employees[4].setPassword("eee");
|
||||||
|
employees[4].setIdDepartment("13");
|
||||||
|
|
||||||
|
for (int i = 0; i < employees.length; i++) {
|
||||||
|
|
||||||
|
System.out.println(employees[i]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
"現在の社員データ件数:"
|
||||||
|
+ EmployeeData.getEmpCount()
|
||||||
|
+ "件");
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*ここから9段階↓
|
||||||
|
EmployeeData employee1 =
|
||||||
|
new EmployeeData(
|
||||||
|
"10000",
|
||||||
|
"",
|
||||||
|
"ヤマダタツヤ",
|
||||||
|
"yamada@hoge.jp",
|
||||||
|
"aaa",
|
||||||
|
"10"
|
||||||
|
);
|
||||||
|
|
||||||
|
EmployeeData employee2 =
|
||||||
|
new EmployeeData(
|
||||||
|
"",
|
||||||
|
"山田龍也",
|
||||||
|
"ヤマダタツヤ",
|
||||||
|
"yamada@hoge.jp",
|
||||||
|
"aaa",
|
||||||
|
"10"
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
|
//三日目5段階
|
||||||
|
BaseData employee1 = new EmployeeData(
|
||||||
|
"10000",
|
||||||
|
"",
|
||||||
|
"ヤマダタツヤ",
|
||||||
|
"yamada@hoge.jp",
|
||||||
|
"aaa",
|
||||||
|
"10"
|
||||||
|
);
|
||||||
|
|
||||||
|
BaseData employee2 = new EmployeeData(
|
||||||
|
"",
|
||||||
|
"山田龍也",
|
||||||
|
"ヤマダタツヤ",
|
||||||
|
"yamada@hoge.jp",
|
||||||
|
"aaa",
|
||||||
|
"10"
|
||||||
|
);
|
||||||
|
|
||||||
|
System.out.println(employee1);
|
||||||
|
|
||||||
|
System.out.println(employee1.toCSV());
|
||||||
|
|
||||||
|
System.out.println(employee1.getPrimaryKeyValue());
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
employee1.getPrimaryKeyValue().equals("10000")
|
||||||
|
);
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
employee2.getPrimaryKeyValue().equals("10000")
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
17
misson1014/src/misson1014/Shape.java
Normal file
17
misson1014/src/misson1014/Shape.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
|
public class Shape {
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public Shape(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double area() {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showInfo() {
|
||||||
|
System.out.println(this.name + "の面積は" + this.area() + "です");
|
||||||
|
}
|
||||||
|
}
|
||||||
31
misson1014/src/misson1014/Student.java
Normal file
31
misson1014/src/misson1014/Student.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package misson1014;
|
||||||
|
|
||||||
|
public class Student {
|
||||||
|
int studentId;
|
||||||
|
String name;
|
||||||
|
//staticフィールド
|
||||||
|
static int studentCount = 0;
|
||||||
|
|
||||||
|
//コンストラクタ
|
||||||
|
public Student(int studentId, String name) {
|
||||||
|
//フィールド代入
|
||||||
|
this.studentId = studentId;
|
||||||
|
this.name = name;
|
||||||
|
studentCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//学生情報
|
||||||
|
void printProfile() {
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
"学籍番号:" + this.studentId
|
||||||
|
+ " 名前:" + this.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
//現在の学生数用staticメソッド
|
||||||
|
public static int getStudentCount() {
|
||||||
|
return studentCount;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
10
実行例_20261020/.classpath
Normal file
10
実行例_20261020/.classpath
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?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">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
17
実行例_20261020/.project
Normal file
17
実行例_20261020/.project
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>実行例_20261020</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
2
実行例_20261020/.settings/org.eclipse.core.resources.prefs
Normal file
2
実行例_20261020/.settings/org.eclipse.core.resources.prefs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding/<project>=UTF-8
|
||||||
11
実行例_20261020/.settings/org.eclipse.jdt.core.prefs
Normal file
11
実行例_20261020/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=21
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=21
|
||||||
Binary file not shown.
BIN
実行例_20261020/bin/EmployeeData.class
Normal file
BIN
実行例_20261020/bin/EmployeeData.class
Normal file
Binary file not shown.
BIN
実行例_20261020/bin/Main.class
Normal file
BIN
実行例_20261020/bin/Main.class
Normal file
Binary file not shown.
10
実行例_20261020/src/BaseData.java
Normal file
10
実行例_20261020/src/BaseData.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
|
||||||
|
public abstract class BaseData {
|
||||||
|
|
||||||
|
public abstract String toString();
|
||||||
|
|
||||||
|
public abstract String toCSV();
|
||||||
|
|
||||||
|
public abstract String getPrimaryKeyValue();
|
||||||
|
}
|
||||||
@@ -1,18 +1,22 @@
|
|||||||
|
|
||||||
|
|
||||||
public class DepartmentData extends BaseData {
|
public class DepartmentData extends BaseData {
|
||||||
|
|
||||||
private String idDepartment;
|
private String idDepartment;
|
||||||
private String nmDepartment;
|
private String nmDepartment;
|
||||||
|
|
||||||
|
|
||||||
public String getIdDepartment() {
|
public String getIdDepartment() {
|
||||||
return idDepartment;
|
return idDepartment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIdDepartment(String idDepartment) {
|
public void setIdDepartment(String idDepartment) {
|
||||||
this.idDepartment = idDepartment;
|
this.idDepartment = idDepartment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNmDepartment() {
|
public String getNmDepartment() {
|
||||||
return nmDepartment;
|
return nmDepartment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNmDepartment(String nmDepartment) {
|
public void setNmDepartment(String nmDepartment) {
|
||||||
this.nmDepartment = nmDepartment;
|
this.nmDepartment = nmDepartment;
|
||||||
}
|
}
|
||||||
@@ -20,21 +24,15 @@ public class DepartmentData extends BaseData{
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getIdDepartment() + "\t" + getNmDepartment();
|
return getIdDepartment() + "\t" + getNmDepartment();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toCSV() {
|
public String toCSV() {
|
||||||
return getIdDepartment() + "," + getNmDepartment();
|
return getIdDepartment() + "," + getNmDepartment();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getPrimaryKeyValue() {
|
public String getPrimaryKeyValue() {
|
||||||
return getIdDepartment();
|
return getIdDepartment();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
147
実行例_20261020/src/EmployeeData.java
Normal file
147
実行例_20261020/src/EmployeeData.java
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
|
||||||
|
|
||||||
|
public class EmployeeData extends BaseData {
|
||||||
|
//社員ID
|
||||||
|
private String idEmployee;
|
||||||
|
//社員名
|
||||||
|
private String nmEmployee;
|
||||||
|
//社員名カナ
|
||||||
|
private String knEmployee;
|
||||||
|
//メールアドレス
|
||||||
|
private String mailAddress;
|
||||||
|
//パスワード
|
||||||
|
private String password;
|
||||||
|
//部署ID
|
||||||
|
private String idDepartment;
|
||||||
|
//社員データ件数
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//ゲッター
|
||||||
|
public String getIdEmployee() {
|
||||||
|
return idEmployee;
|
||||||
|
}
|
||||||
|
public String getNmEmployee() {
|
||||||
|
return nmEmployee;
|
||||||
|
}
|
||||||
|
public String getKnEmployee() {
|
||||||
|
return knEmployee;
|
||||||
|
}
|
||||||
|
public String getMailAddress() {
|
||||||
|
return mailAddress;
|
||||||
|
}
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
public String getIdDepartment() {
|
||||||
|
return idDepartment;
|
||||||
|
}
|
||||||
|
//セッター
|
||||||
|
public void setIdEmployee(String idEmployee) {
|
||||||
|
|
||||||
|
if (idEmployee == null) {
|
||||||
|
System.out.println("社員IDが空のため設定できませんでした");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (idEmployee.trim().isEmpty()) {
|
||||||
|
System.out.println("社員IDが空のため設定できませんでした");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.idEmployee = idEmployee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNmEmployee(String nmEmployee) {
|
||||||
|
|
||||||
|
if (nmEmployee == null) {
|
||||||
|
System.out.println("社員名が空のため設定できませんでした");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nmEmployee.trim().isEmpty()) {
|
||||||
|
System.out.println("社員名が空のため設定できませんでした");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.nmEmployee = nmEmployee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKnEmployee(String knEmployee) {
|
||||||
|
this.knEmployee = knEmployee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMailAddress(String mailAddress) {
|
||||||
|
this.mailAddress = mailAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdDepartment(String idDepartment) {
|
||||||
|
this.idDepartment = idDepartment;
|
||||||
|
}
|
||||||
|
|
||||||
|
//toString
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
|
return getIdEmployee() + "\t"
|
||||||
|
+ getNmEmployee() + "\t"
|
||||||
|
+ getKnEmployee() + "\t"
|
||||||
|
+ getMailAddress() + "\t"
|
||||||
|
+ getPassword() + "\t"
|
||||||
|
+ getIdDepartment();
|
||||||
|
}
|
||||||
|
|
||||||
|
//CSV形式へ変換
|
||||||
|
@Override
|
||||||
|
public String toCSV() {
|
||||||
|
|
||||||
|
return getIdEmployee() + ","
|
||||||
|
+ getNmEmployee() + ","
|
||||||
|
+ getKnEmployee() + ","
|
||||||
|
+ getMailAddress() + ","
|
||||||
|
+ getPassword() + ","
|
||||||
|
+ getIdDepartment();
|
||||||
|
}
|
||||||
|
|
||||||
|
//キー取得
|
||||||
|
@Override
|
||||||
|
public String getPrimaryKeyValue() {
|
||||||
|
|
||||||
|
return getIdEmployee();
|
||||||
|
}
|
||||||
|
|
||||||
|
//ID一致判定
|
||||||
|
public boolean isMatchId(String id) {
|
||||||
|
return getIdEmployee().equals(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
//件数取得
|
||||||
|
public static int getEmpCount() {
|
||||||
|
return empCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
214
実行例_20261020/src/Main.java
Normal file
214
実行例_20261020/src/Main.java
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
//社員データ格納用配列
|
||||||
|
//CSVから読み込んだ社員データを格納する
|
||||||
|
EmployeeData[] employees = new EmployeeData[100];
|
||||||
|
|
||||||
|
//読み込んだ件数管理用
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
// EmployeeData.csv読込
|
||||||
|
try {
|
||||||
|
|
||||||
|
BufferedReader br =
|
||||||
|
new BufferedReader(new FileReader("C:\\Users\\石原 叶大\\Documents\\em-oop\\EmployeeData.csv"));
|
||||||
|
|
||||||
|
String line;
|
||||||
|
|
||||||
|
|
||||||
|
// CSVを1行ずつ読込
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
|
||||||
|
//カンマ区切りで分割
|
||||||
|
String[] data = line.split(",");
|
||||||
|
|
||||||
|
// EmployeeData生成
|
||||||
|
EmployeeData employee = new EmployeeData();
|
||||||
|
|
||||||
|
|
||||||
|
//CSVの値をEmployeeDataへ設定
|
||||||
|
employee.setIdEmployee(data[0]);
|
||||||
|
employee.setNmEmployee(data[1]);
|
||||||
|
employee.setKnEmployee(data[2]);
|
||||||
|
employee.setMailAddress(data[3]);
|
||||||
|
employee.setPassword(data[4]);
|
||||||
|
employee.setIdDepartment(data[5]);
|
||||||
|
|
||||||
|
|
||||||
|
//配列へ格納
|
||||||
|
employees[count] = employee;
|
||||||
|
|
||||||
|
//件数加算
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//ファイルクローズ
|
||||||
|
br.close();
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
|
||||||
|
//CSV読込失敗
|
||||||
|
System.out.println("CSVの読み込みに失敗しました");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//システム開始
|
||||||
|
System.out.println("システムを開始します");
|
||||||
|
|
||||||
|
//ループ
|
||||||
|
//0が入力されるまで繰り返す
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
//メニュー表示
|
||||||
|
System.out.println("1:検索 2:登録 3:更新 4:削除 0:終了");
|
||||||
|
|
||||||
|
//メニュー入力
|
||||||
|
String menu = scanner.nextLine();
|
||||||
|
|
||||||
|
//システム終了
|
||||||
|
if (menu.equals("0")) {
|
||||||
|
System.out.println("システムを終了します");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//検索機能
|
||||||
|
else if (menu.equals("1")) {
|
||||||
|
|
||||||
|
//検索メニュー表示
|
||||||
|
System.out.println("1:全検索 2:条件検索 それ以外:戻る");
|
||||||
|
|
||||||
|
String searchMenu = scanner.nextLine();
|
||||||
|
|
||||||
|
//全検索
|
||||||
|
if (searchMenu.equals("1")) {
|
||||||
|
|
||||||
|
// 読み込んだ全社員を表示
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
|
||||||
|
System.out.println(employees[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//社員ID検索
|
||||||
|
else if (searchMenu.equals("2")) {
|
||||||
|
|
||||||
|
//ID入力
|
||||||
|
System.out.println("IDを入力してください");
|
||||||
|
|
||||||
|
String id = scanner.nextLine();
|
||||||
|
|
||||||
|
//検索判定
|
||||||
|
boolean found = false;
|
||||||
|
|
||||||
|
//配列検索
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
|
||||||
|
//社員ID比較
|
||||||
|
if (employees[i].getPrimaryKeyValue().equals(id)) {
|
||||||
|
|
||||||
|
//一致データ表示
|
||||||
|
System.out.println(employees[i]);
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//見つからなかった場合
|
||||||
|
if (!found) {System.out.println("該当する社員が見つかりませんでした");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//社員登録機能
|
||||||
|
else if (menu.equals("2")) {
|
||||||
|
|
||||||
|
//新しい社員データ生成
|
||||||
|
EmployeeData employee = new EmployeeData();
|
||||||
|
|
||||||
|
//社員ID入力
|
||||||
|
System.out.println("社員IDを入力してください");
|
||||||
|
employee.setIdEmployee(scanner.nextLine());
|
||||||
|
|
||||||
|
//社員名入力
|
||||||
|
System.out.println("社員名を入力してください");
|
||||||
|
|
||||||
|
employee.setNmEmployee(scanner.nextLine());
|
||||||
|
|
||||||
|
//フリガナ入力
|
||||||
|
System.out.println("フリガナを入力してください");
|
||||||
|
employee.setKnEmployee(scanner.nextLine());
|
||||||
|
|
||||||
|
//メールアドレス入力
|
||||||
|
System.out.println("メールアドレスを入力してください");
|
||||||
|
employee.setMailAddress(scanner.nextLine());
|
||||||
|
|
||||||
|
//パスワード入力
|
||||||
|
System.out.println("パスワードを入力してください");
|
||||||
|
|
||||||
|
employee.setPassword(scanner.nextLine());
|
||||||
|
|
||||||
|
//部署ID入力
|
||||||
|
System.out.println("部署IDを入力してください");
|
||||||
|
employee.setIdDepartment(scanner.nextLine());
|
||||||
|
|
||||||
|
//配列へ追加
|
||||||
|
employees[count] = employee;
|
||||||
|
|
||||||
|
//CSVへ追記
|
||||||
|
try {
|
||||||
|
PrintWriter pw =
|
||||||
|
new PrintWriter(new FileWriter("C:\\Users\\石原 叶大\\Documents\\em-oop\\EmployeeData.csv",true));
|
||||||
|
|
||||||
|
//CSVに1行追加
|
||||||
|
pw.println(employee.toCSV());
|
||||||
|
pw.close();
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("CSVへの保存に失敗しました");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 件数加算
|
||||||
|
count++;
|
||||||
|
|
||||||
|
System.out.println("登録が完了しました");
|
||||||
|
}
|
||||||
|
|
||||||
|
//更新機能
|
||||||
|
//未実装あとから使う
|
||||||
|
else if (menu.equals("3")) {
|
||||||
|
System.out.println("更新機能は未実装です");
|
||||||
|
}
|
||||||
|
|
||||||
|
//削除機能
|
||||||
|
//未実装あとから使う
|
||||||
|
else if (menu.equals("4")) {
|
||||||
|
System.out.println("削除機能は未実装です");
|
||||||
|
}
|
||||||
|
|
||||||
|
//入力ミス
|
||||||
|
else {
|
||||||
|
System.out.println("正しく入力してください");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scanner.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user