Day31段階目完了

This commit is contained in:
m-endo
2026-09-16 14:00:12 +09:00
parent 9c55517492
commit 909322f244
7 changed files with 80 additions and 9 deletions

1
em-oop/.gitignore vendored
View File

@@ -1 +1,2 @@
/bin/
/.metadata/

View File

@@ -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();
}
}

21
em-oop/src/Circle.java Normal file
View File

@@ -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 + "");
}
}

View File

@@ -0,0 +1,10 @@
public class Day3Check1 {
public static void main(String[] args) {
//インスタンス
Circle circle = new Circle(2.0);
circle.showInfo();
}
}

View File

@@ -10,6 +10,8 @@ public class Item {
this.setStock(this.getStock() - amount);
}
//ゲッター、セッター設定
public String getName() {
return name;
}

16
em-oop/src/Sharpe.java Normal file
View File

@@ -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() + "です");
}
}

View File

@@ -3,11 +3,23 @@ public class Student {
//フィールド宣言
int studentId;
String name;
//フィールド追加
static int studentCount = 0;
//メソッド宣言
void printProfile() {
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;
}
}