Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 04ef2b8b1f | |||
| b17babd071 | |||
| 24aa555e45 | |||
| d656d3c5a8 | |||
| 7e61a24d20 | |||
| 9223c5810c |
@@ -1,7 +1,9 @@
|
|||||||
|
|
||||||
public abstract class BaseData {
|
public abstract class BaseData{
|
||||||
public abstract String toString();
|
public abstract String toString();
|
||||||
public abstract String toCSV();
|
public abstract String toCSV();
|
||||||
public abstract String getPrimaryKeyValue();
|
public abstract String getPrimaryKeyValue();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
28
src/main/java/BasicCheck1.java
Normal file
28
src/main/java/BasicCheck1.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
public class BasicCheck1 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
Book book = new Book();
|
||||||
|
Book book1 = new Book();
|
||||||
|
|
||||||
|
book.title = "吾輩は猫である";
|
||||||
|
book.author = "夏目漱石";
|
||||||
|
book.price = 800;
|
||||||
|
|
||||||
|
System.out.println(book1.title);
|
||||||
|
System.out.println(book1.author);
|
||||||
|
System.out.println(book1.price);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(book.title);
|
||||||
|
System.out.println(book.author);
|
||||||
|
System.out.println(book.price);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
19
src/main/java/BasicCheck2.java
Normal file
19
src/main/java/BasicCheck2.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
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("現在の生徒数: " + student1.getStudentCount() + "人");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
36
src/main/java/BasicCheck3.java
Normal file
36
src/main/java/BasicCheck3.java
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
|
||||||
|
public class BasicCheck3 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
Item[] items = new Item[3];
|
||||||
|
|
||||||
|
items[0] = new Item();
|
||||||
|
items[0].setName("ノート");
|
||||||
|
items[0].setPrice(120);
|
||||||
|
items[0].setStock(50);
|
||||||
|
|
||||||
|
|
||||||
|
items[1] = new Item();
|
||||||
|
items[1].setName("消しゴム");
|
||||||
|
items[1].setPrice(80);
|
||||||
|
items[1].setStock(30);
|
||||||
|
|
||||||
|
|
||||||
|
items[2] = new Item();
|
||||||
|
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]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
18
src/main/java/Book.java
Normal file
18
src/main/java/Book.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
public class Book {
|
||||||
|
String title;
|
||||||
|
String author;
|
||||||
|
int price;
|
||||||
|
|
||||||
|
public Book() {
|
||||||
|
title = "タイトル未設定";
|
||||||
|
author = "著者未設定";
|
||||||
|
price = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Book(String title,String author,int price) {
|
||||||
|
this.title = title;
|
||||||
|
this.author = author;
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class CUI_20261014 {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// TODO 自動生成されたメソッド・スタブ
|
|
||||||
BaseData[] employees = new BaseData[5];
|
|
||||||
|
|
||||||
employees[0] = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ",
|
|
||||||
"yamada@hoge.jp", "aaa", "10");
|
|
||||||
|
|
||||||
employees[1] = new EmployeeData();
|
|
||||||
((EmployeeData)employees[1]).setIdEmployee("10001");
|
|
||||||
((EmployeeData)employees[1]).setNmEmployee("高橋準");
|
|
||||||
((EmployeeData)employees[1]).setKnEmployee("タカハシジュン");
|
|
||||||
((EmployeeData)employees[1]).setMailAddress("jtaka@hoge.jp");
|
|
||||||
((EmployeeData)employees[1]).setPassword("bbb");
|
|
||||||
((EmployeeData)employees[1]).setIdDepartment("10");
|
|
||||||
|
|
||||||
employees[2] = new EmployeeData();
|
|
||||||
((EmployeeData)employees[2]).setIdEmployee("10002");
|
|
||||||
((EmployeeData)employees[2]).setNmEmployee("麻枝史明");
|
|
||||||
((EmployeeData)employees[2]).setKnEmployee("マエダフミアキ");
|
|
||||||
((EmployeeData)employees[2]).setMailAddress("fmak@hoge.jp");
|
|
||||||
((EmployeeData)employees[2]).setPassword("ccc");
|
|
||||||
((EmployeeData)employees[2]).setIdDepartment("11");
|
|
||||||
|
|
||||||
employees[3] = new EmployeeData();
|
|
||||||
((EmployeeData)employees[3]).setIdEmployee("10003");
|
|
||||||
((EmployeeData)employees[3]).setNmEmployee("丸戸章介");
|
|
||||||
((EmployeeData)employees[3]).setKnEmployee("マルトショウスケ");
|
|
||||||
((EmployeeData)employees[3]).setMailAddress("marusyo@hoge.jp");
|
|
||||||
((EmployeeData)employees[3]).setPassword("ddd");
|
|
||||||
((EmployeeData)employees[3]).setIdDepartment("12");
|
|
||||||
|
|
||||||
employees[4] = new EmployeeData();
|
|
||||||
((EmployeeData)employees[4]).setIdEmployee("10004");
|
|
||||||
((EmployeeData)employees[4]).setNmEmployee("三宅武");
|
|
||||||
((EmployeeData)employees[4]).setKnEmployee("ミヤケタケシ");
|
|
||||||
((EmployeeData)employees[4]).setMailAddress("miya@hoge.jp");
|
|
||||||
((EmployeeData)employees[4]).setPassword("eee");
|
|
||||||
((EmployeeData)employees[4]).setIdDepartment("13");
|
|
||||||
|
|
||||||
for(int i = 0; i < 5; i++) {
|
|
||||||
System.out.println(employees[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("現在の社員データ件数:" + EmployeeData.getEmpCount() + "件");
|
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
System.out.println(employees[0].toCSV());
|
|
||||||
System.out.println(employees[0].getPrimaryKeyValue());
|
|
||||||
|
|
||||||
BaseData[] allData = new BaseData[11];
|
|
||||||
|
|
||||||
for(int i = 0; i <= 4; i++) {
|
|
||||||
allData[i] = employees[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
DepartmentData dept = new DepartmentData();
|
|
||||||
dept.setIdDepartment("10");
|
|
||||||
dept.setNmDepartment("役員");
|
|
||||||
allData[5] = dept;
|
|
||||||
|
|
||||||
dept.setIdDepartment("11");
|
|
||||||
dept.setNmDepartment("人事・総務部");
|
|
||||||
allData[6] = dept;
|
|
||||||
|
|
||||||
dept.setIdDepartment("12");
|
|
||||||
dept.setNmDepartment("経理部");
|
|
||||||
allData[7] = dept;
|
|
||||||
|
|
||||||
dept.setIdDepartment("13");
|
|
||||||
dept.setNmDepartment("システム開発事業部");
|
|
||||||
allData[8] = dept;
|
|
||||||
|
|
||||||
dept.setIdDepartment("14");
|
|
||||||
dept.setNmDepartment("教育事業部");
|
|
||||||
allData[9] = dept;
|
|
||||||
|
|
||||||
dept.setIdDepartment("15");
|
|
||||||
dept.setNmDepartment("営業企画部");
|
|
||||||
allData[10] = dept;
|
|
||||||
|
|
||||||
for(int i = 0; i <= 10; i++) {
|
|
||||||
System.out.println(allData[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//IDが10002を探す
|
|
||||||
System.out.println("10002 を検索します");
|
|
||||||
boolean b1 = false; //一致してるかを判定させる
|
|
||||||
for(int i = 0; i < 5; i++) { //employees[0-4]まで繰り返す
|
|
||||||
if(employees[i].getPrimaryKeyValue().equals("10002")) { //10002と一致するのがあれば
|
|
||||||
b1 = true; //b1をtrueにして
|
|
||||||
break; //繰り返しを抜ける
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println(b1); //trueかfalseかを出力
|
|
||||||
|
|
||||||
//IDが99999を探す
|
|
||||||
System.out.println("99999 を検索します");
|
|
||||||
boolean b2 = false;
|
|
||||||
for(int i = 0; i < 5; i++) {
|
|
||||||
if(employees[i].getPrimaryKeyValue().equals("99999")) {
|
|
||||||
b2 = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println(b2);
|
|
||||||
|
|
||||||
while(true) { //繰り返す
|
|
||||||
System.out.println("検索したい社員IDを入力してください(終了する場合は0)");
|
|
||||||
Scanner sc = new Scanner(System.in); //キーボード入力受け取る
|
|
||||||
String str = sc.nextLine(); //入力されたものをstrにする
|
|
||||||
if(str.equals("0")) { //0と入力されたら
|
|
||||||
System.out.println("システムを終了します"); //終わる
|
|
||||||
break; //ループ終了
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean b3 = false; //一致してるかを判定させる
|
|
||||||
for(int i = 0; i < 5; i++) { //employees[0-4]まで繰り返す
|
|
||||||
if(employees[i].getPrimaryKeyValue().equals(str)) { //strと一致していたら
|
|
||||||
System.out.println(employees[i].toString()); //toStoringメソッドを呼び出して出力
|
|
||||||
b3 = true; //b3をtrueにして
|
|
||||||
break; //繰り返しを抜ける
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!b3) {
|
|
||||||
System.out.println("該当する社員が見つかりませんでした");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
|
|
||||||
public class DepartmentData extends BaseData{
|
|
||||||
private String idDepartment;
|
|
||||||
private String nmDepartment;
|
|
||||||
|
|
||||||
public String getIdDepartment() {
|
|
||||||
return idDepartment;
|
|
||||||
}
|
|
||||||
public void setIdDepartment(String idDepartment) {
|
|
||||||
this.idDepartment = idDepartment;
|
|
||||||
}
|
|
||||||
public String getNmDepartment() {
|
|
||||||
return nmDepartment;
|
|
||||||
}
|
|
||||||
public void setNmDepartment(String nmDepartment) {
|
|
||||||
this.nmDepartment = nmDepartment;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return this.getIdDepartment() + "\t" + this.getNmDepartment();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toCSV() {
|
|
||||||
return this.getIdDepartment() + "," + this.getNmDepartment();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String getPrimaryKeyValue() {
|
|
||||||
return this.getIdDepartment();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,112 +1,142 @@
|
|||||||
|
public class EmployeeData extends BaseData {
|
||||||
|
|
||||||
public class EmployeeData extends BaseData{
|
private String idEmployee;
|
||||||
private String idEmployee;
|
private String nmEmployee;
|
||||||
private String nmEmployee;
|
private String knEmployee;
|
||||||
private String knEmployee;
|
private String mailAddress;
|
||||||
private String mailAddress;
|
private String password;
|
||||||
private String password;
|
private String idDepartment;
|
||||||
private String idDepartment;
|
|
||||||
|
|
||||||
//ゲッターとセッター
|
|
||||||
public String getIdEmployee() {
|
|
||||||
return idEmployee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdEmployee(String idEmployee) {
|
|
||||||
if(idEmployee == null || idEmployee.strip().isEmpty()) {
|
private static int empCount = 0;
|
||||||
System.out.println("社員IDが空のため設定できませんでした");
|
|
||||||
}else {
|
|
||||||
this.idEmployee = idEmployee;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String getIdEmployee() {
|
||||||
|
return idEmployee;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public String getNmEmployee() {
|
public void setIdEmployee(String idEmployee) {
|
||||||
return nmEmployee;
|
if (idEmployee == null || idEmployee == " " ||idEmployee == " " || idEmployee.isEmpty()) {
|
||||||
}
|
System.out.println("社員IDが空のため設定できませんでした");
|
||||||
|
return;
|
||||||
public void setNmEmployee(String nmEmployee) {
|
}
|
||||||
if(nmEmployee == null || nmEmployee.strip().isEmpty()) {
|
this.idEmployee = idEmployee;
|
||||||
System.out.println("社員名が空のため設定できませんでした");
|
|
||||||
}else {
|
|
||||||
this.nmEmployee = nmEmployee;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public String getKnEmployee() {
|
public String getNmEmployee() {
|
||||||
return knEmployee;
|
return nmEmployee;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKnEmployee(String knEmployee) {
|
|
||||||
this.knEmployee = knEmployee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMailAddress() {
|
public void setNmEmployee(String nmEmployee) {
|
||||||
return mailAddress;
|
if (nmEmployee == null || nmEmployee == " " || nmEmployee == " " || nmEmployee.isEmpty()){
|
||||||
}
|
System.out.println("社員名が空のため設定できませんでした");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.nmEmployee = nmEmployee;
|
||||||
|
}
|
||||||
|
|
||||||
public void setMailAddress(String mailAddress) {
|
public String getKnEmployee() {
|
||||||
this.mailAddress = mailAddress;
|
return knEmployee;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
public void setKnEmployee(String knEmployee) {
|
||||||
return password;
|
this.knEmployee = knEmployee;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPassword(String password) {
|
public String getMailAddress() {
|
||||||
this.password = password;
|
return mailAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIdDepartment() {
|
public void setMailAddress(String mailAddress) {
|
||||||
return idDepartment;
|
this.mailAddress = mailAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIdDepartment(String idDepartment) {
|
public String getPassword() {
|
||||||
this.idDepartment = idDepartment;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int empCount = 0;
|
public void setPassword(String password) {
|
||||||
//引数なしコンストラクタ
|
this.password = password;
|
||||||
public EmployeeData() {
|
}
|
||||||
empCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//引数をもつコンストラクタ
|
|
||||||
public EmployeeData(String idEmployee, String nmEmployee,
|
|
||||||
String knEmployee, String mailAddress,
|
|
||||||
String password, String idDepartment) {
|
|
||||||
this.setIdEmployee(idEmployee);
|
|
||||||
this.setNmEmployee(nmEmployee);
|
|
||||||
this.setKnEmployee(knEmployee);
|
|
||||||
this.setMailAddress(mailAddress);
|
|
||||||
this.setPassword(password);
|
|
||||||
this.setIdDepartment(idDepartment);
|
|
||||||
empCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//メソッド
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return(this.getIdEmployee() + "\t" + this.getNmEmployee() + "\t" + this.getKnEmployee() + "\t" +
|
|
||||||
this.getMailAddress() + "\t" + this.getPassword() + "\t" + this.getIdDepartment());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMatchId(String id) {
|
|
||||||
return this.idEmployee.equals(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getEmpCount() {
|
|
||||||
return empCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public String getIdDepartment() {
|
||||||
public String toCSV() {
|
|
||||||
return (this.getIdEmployee() + "," + this.getNmEmployee() + "," + this.getKnEmployee() + "," +
|
|
||||||
this.getMailAddress() + "," + this.getPassword() + "," + this.getIdDepartment());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPrimaryKeyValue() {
|
return idDepartment;
|
||||||
return this.idEmployee;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setIdDepartment(String idDepartment) {
|
||||||
|
this.idDepartment = idDepartment;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isMatchId(String id) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (this.idEmployee != null && this.idEmployee.equals(id)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showInfo() {
|
||||||
|
System.out.println(this.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return(getIdEmployee() + "\t" + getNmEmployee() + "\t" + getKnEmployee() + "\t" + getMailAddress() + "\t" +getPassword() + "\t" +getIdDepartment()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int getEmpCount() {
|
||||||
|
return empCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toCSV() {
|
||||||
|
return getIdEmployee() + "," + getNmEmployee() + "," + getKnEmployee() + "," + getMailAddress() + "," + getPassword() + "," + getIdDepartment();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPrimaryKeyValue(){
|
||||||
|
return this.idEmployee;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
56
src/main/java/Item.java
Normal file
56
src/main/java/Item.java
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
|
||||||
|
class Item {
|
||||||
|
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private int price;
|
||||||
|
private int stock;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void sell(int amount) {
|
||||||
|
this.setStock(this.getStock() - amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getName() + " " + getPrice() + "円 (残り" + getStock() + "個)";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
73
src/main/java/Main.java
Normal file
73
src/main/java/Main.java
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO 自動生成されたメソッド・スタブ
|
||||||
|
BaseData[] employees = new BaseData[5];
|
||||||
|
|
||||||
|
|
||||||
|
employees[0] = new EmployeeData("10000", "山田龍也", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
|
||||||
|
employees[1] = new EmployeeData("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");
|
||||||
|
|
||||||
|
for (int i = 0; i < employees.length; i++) {
|
||||||
|
|
||||||
|
//System.out.println(employees[i]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("現在のデータ件数:"+EmployeeData.getEmpCount()+"件");
|
||||||
|
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Scannerを使って、
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
//「検索したい社員IDを入力してください」と表示し
|
||||||
|
System.out.println("検索したい社員IDを入力してください(終了する場合は0)");
|
||||||
|
//キーボード入力を受け取る
|
||||||
|
String idEmployee = scanner.next();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if ("0".equals(idEmployee)) {
|
||||||
|
System.out.println("システムを終了します");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//employees配列をfor文で1件ずつ確認し
|
||||||
|
for(int i = 0; i < employees.length; i++) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (((EmployeeData) employees[i]).isMatchId(idEmployee)) {
|
||||||
|
//一致する社員が見つかったら、その社員のshowInfoメソッドを呼び出す
|
||||||
|
((EmployeeData) employees[i]).showInfo();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//
|
||||||
|
System.out.println("検索したいIDが見つかりませんでした");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//System.out.println(employees[0].toCSV());
|
||||||
|
//System.out.println(employees[0].getPrimaryKeyValue());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
30
src/main/java/Student.java
Normal file
30
src/main/java/Student.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
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++;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public int getStudentCount() {
|
||||||
|
return studentCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int studentCount = 0;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user