diff --git a/em-oop/.gitignore b/em-oop/.gitignore index ae3c172..ea03d78 100644 --- a/em-oop/.gitignore +++ b/em-oop/.gitignore @@ -1 +1,2 @@ /bin/ +/.metadata/ diff --git a/em-oop/src/BasicCheck2.java b/em-oop/src/BasicCheck2.java index d85b755..93e4718 100644 --- a/em-oop/src/BasicCheck2.java +++ b/em-oop/src/BasicCheck2.java @@ -4,9 +4,18 @@ public class BasicCheck2 { //変数宣言 Student student = new Student(); //代入 - student.studentId = 1; - student.name = "鈴木一郎"; - student.printProfile(); + //student.studentId = 1; + //student.name = "鈴木一郎"; + //student.printProfile(); + Student student1 = new Student(1,"鈴木一郎"); + Student student2 = new Student(2,"田中花子"); + Student student3 = new Student(3,"佐藤次郎"); + + student1.printProfile(); + student2.printProfile(); + student3.printProfile(); + + //Student.getStudentCount(); } } diff --git a/em-oop/src/Circle.java b/em-oop/src/Circle.java new file mode 100644 index 0000000..40fdf5a --- /dev/null +++ b/em-oop/src/Circle.java @@ -0,0 +1,21 @@ + +public class Circle extends Sharpe { + //フィールド + private double radius; + //コンストラクタ + public Circle(double radius) { + super("円"); + this.radius = radius; + } + //メソッド1 + @Override + public double area() { + return Math.PI * radius * radius; +} + //メソッド2 + @Override + public void showInfo() { + super.showInfo(); + System.out.println("半径:" + this.radius + ""); + } +} \ No newline at end of file diff --git a/em-oop/src/Day3Check1.java b/em-oop/src/Day3Check1.java new file mode 100644 index 0000000..d722262 --- /dev/null +++ b/em-oop/src/Day3Check1.java @@ -0,0 +1,10 @@ + +public class Day3Check1 { + + public static void main(String[] args) { + //インスタンス + Circle circle = new Circle(2.0); + circle.showInfo(); + } + +} diff --git a/em-oop/src/Item.java b/em-oop/src/Item.java index 4af6ff7..14b3f70 100644 --- a/em-oop/src/Item.java +++ b/em-oop/src/Item.java @@ -9,6 +9,8 @@ public class Item { void sell(int amount) { this.setStock(this.getStock() - amount); } + + //ゲッター、セッター設定 public String getName() { return name; diff --git a/em-oop/src/Sharpe.java b/em-oop/src/Sharpe.java new file mode 100644 index 0000000..bb15334 --- /dev/null +++ b/em-oop/src/Sharpe.java @@ -0,0 +1,16 @@ + +public class Sharpe { + //フィールド宣言 + private String name; + //コンストラクタ + public Sharpe(String name) { + } + //メソッド1 + double area() { + return 0.0; + } + //メソッド2 + void showInfo() { + System.out.println(this.name + "の面積は" + this.area() + "です"); + } +} diff --git a/em-oop/src/Student.java b/em-oop/src/Student.java index 0876ea7..f59081b 100644 --- a/em-oop/src/Student.java +++ b/em-oop/src/Student.java @@ -1,13 +1,25 @@ public class Student { //フィールド宣言 - int studentId; - String name; - + int studentId; + String name; + //フィールド追加 + static int studentCount = 0; + //メソッド宣言 void printProfile() { - System.out.println("学籍番号:" + this.studentId + " 名前:" + this.name); - + System.out.println("学籍番号:" + this.studentId + " 名前:" + this.name); } -} + //コントラクタ追加 + public Student(int studentId, String name) { + this.studentId = studentId; + this.name = name; + } + //コントラクタ追加 + public static int studentCount() { + return studentCount; + + } + +}