Day2、4段階目完了
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
|
||||
public class Circle extends Sharpe {
|
||||
public class Circle extends Shape {
|
||||
//フィールド
|
||||
private double radius;
|
||||
//コンストラクタ
|
||||
|
||||
15
em-oop/src/Day3Check2.java
Normal file
15
em-oop/src/Day3Check2.java
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
public class Day3Check2 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
//インスタンス
|
||||
Rectangle width = new Rectangle(3);
|
||||
Rectangle height = new Rectangle(4);
|
||||
//メソッド呼び出し
|
||||
width.showInfo;
|
||||
height.showInfo;
|
||||
//戻り値出力
|
||||
Greeting greeting = new JapaneseGreeting();
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,82 @@
|
||||
|
||||
public class EmployeeData {
|
||||
//フィールド宣言
|
||||
String idEmployee;//社員ID
|
||||
String nmEmployee;//社員名
|
||||
String knEmployee;//社員カナ
|
||||
String mailAddress;//メールアドレス
|
||||
String password;//パスワード
|
||||
String idDepartment;//部署ID
|
||||
private String idEmployee;//社員ID
|
||||
private String nmEmployee;//社員名
|
||||
private String knEmployee;//社員カナ
|
||||
private String mailAddress;//メールアドレス
|
||||
private String password;//パスワード
|
||||
private String idDepartment;//部署ID
|
||||
|
||||
|
||||
public String getIdEmployee() {
|
||||
return idEmployee;
|
||||
}
|
||||
|
||||
|
||||
public void setIdEmployee(String idEmployee) {
|
||||
this.idEmployee = idEmployee;
|
||||
}
|
||||
|
||||
|
||||
public String getNmEmployee() {
|
||||
return nmEmployee;
|
||||
}
|
||||
|
||||
|
||||
public void setNmEmployee(String nmEmployee) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
//メソッド追加
|
||||
void showInfo() {
|
||||
System.out.println(this.idEmployee + "\t" + this.nmEmployee + "\t" + this.knEmployee + "\t" + this.mailAddress
|
||||
+ "\t" + this.password + "\t" + this.idDepartment);
|
||||
System.out.println(getIdEmployee());
|
||||
System.out.println(getNmEmployee());
|
||||
System.out.println(getKnEmployee());
|
||||
System.out.println(getMailAddress());
|
||||
System.out.println(getPassword());
|
||||
System.out.println(getIdDepartment());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
3
em-oop/src/Greeting.java
Normal file
3
em-oop/src/Greeting.java
Normal file
@@ -0,0 +1,3 @@
|
||||
public interface Greeting {
|
||||
String hello();
|
||||
}
|
||||
7
em-oop/src/JapaneseGreeting.java
Normal file
7
em-oop/src/JapaneseGreeting.java
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
public class JapaneseGreeting implements Greeting{
|
||||
@Override
|
||||
public String hello(){
|
||||
return "こんにちは";
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,55 @@ public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
//メソッド宣言
|
||||
EmployeeData employee = new EmployeeData();
|
||||
//インスタンス宣言
|
||||
//EmployeeData employee = new EmployeeData();
|
||||
//配列5件分
|
||||
EmployeeData[] employees = new EmployeeData[5];
|
||||
|
||||
//インスタンス代入
|
||||
employees[0] = 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] = new EmployeeData();
|
||||
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] = new EmployeeData();
|
||||
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] = new EmployeeData();
|
||||
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] = new EmployeeData();
|
||||
employees[4].setIdEmployee("10004");
|
||||
employees[4].setNmEmployee("三宅武");
|
||||
employees[4].setKnEmployee("ミヤケタケシ");
|
||||
employees[4].setMailAddress("miya@hoge.jp");
|
||||
employees[4].setPassword("eee");
|
||||
employees[4].setIdDepartment("13");
|
||||
//各フィールド代入
|
||||
employee.idEmployee = "10000";
|
||||
employee.nmEmployee = "山田龍也";
|
||||
employee.knEmployee = "ヤマダタツヤ";
|
||||
employee.mailAddress = "yamada@hoge.jp";
|
||||
employee.password = "aaa";
|
||||
employee.idDepartment = "10";
|
||||
//employee.idEmployee = "10000";
|
||||
//employee.nmEmployee = "山田龍也";
|
||||
//employee.knEmployee = "ヤマダタツヤ";
|
||||
//employee.mailAddress = "yamada@hoge.jp";
|
||||
//employee.password = "aaa";
|
||||
//employee.idDepartment = "10";
|
||||
|
||||
//各フィールド出力
|
||||
//System.out.println(employee.idEmployee);
|
||||
//System.out.println(employee.nmEmployee);
|
||||
@@ -19,7 +59,13 @@ public class Main {
|
||||
//System.out.println(employee.mailAddress);
|
||||
//System.out.println(employee.password);
|
||||
//System.out.println(employee.idDepartment);
|
||||
employee.showInfo();
|
||||
}
|
||||
|
||||
//5段階目記載の処理呼び出し
|
||||
//employee.showInfo();
|
||||
|
||||
//for文
|
||||
for (int i = 0; i < employees.length; i++) {
|
||||
employees[i].showInfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
20
em-oop/src/Rectangle.java
Normal file
20
em-oop/src/Rectangle.java
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
public class Rectangle extends Shape {
|
||||
//フィールド
|
||||
private double width;
|
||||
private double height;
|
||||
|
||||
//コンストラクタ
|
||||
public Rectangle(double width, double height) {
|
||||
super("四角形");
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
//抽象メソッドのオーバーライド
|
||||
@Override
|
||||
public double area() {
|
||||
return width * height;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
|
||||
public class Sharpe {
|
||||
public abstract class Shape {
|
||||
//フィールド宣言
|
||||
private String name;
|
||||
|
||||
//コンストラクタ
|
||||
public Sharpe(String name) {
|
||||
}
|
||||
//メソッド1
|
||||
double area() {
|
||||
return 0.0;
|
||||
public Shape(String name) {
|
||||
}
|
||||
|
||||
//メソッド1(抽象メソッド)
|
||||
public abstract double area();
|
||||
|
||||
//メソッド2
|
||||
void showInfo() {
|
||||
System.out.println(this.name + "の面積は" + this.area() + "です");
|
||||
|
||||
@@ -4,7 +4,7 @@ public class Student {
|
||||
int studentId;
|
||||
String name;
|
||||
//フィールド追加
|
||||
static int studentCount = 3;
|
||||
static int studentCount = 0;
|
||||
|
||||
//メソッド宣言
|
||||
void printProfile() {
|
||||
|
||||
Reference in New Issue
Block a user