Compare commits
4 Commits
e9aa2aa4e7
...
e28c819868
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e28c819868 | ||
|
|
48af3a3a99 | ||
|
|
542af2a5d4 | ||
|
|
e6753a16f4 |
14
em-oop/src/BasicCheck2.java
Normal file
14
em-oop/src/BasicCheck2.java
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
public class BasicCheck2 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
Student student = new Student();
|
||||
|
||||
student.studentId=1;
|
||||
student.name="鈴木一郎";
|
||||
|
||||
student.printProfile();
|
||||
}
|
||||
|
||||
}
|
||||
25
em-oop/src/Circle.java
Normal file
25
em-oop/src/Circle.java
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
public class Circle extends Shape {
|
||||
|
||||
//Shapeクラスを継承
|
||||
|
||||
//フィールド作成
|
||||
private double radius;
|
||||
|
||||
//コンストラクタ作成
|
||||
public Circle(double radius) {
|
||||
super("円");
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
//メソッド作成
|
||||
public double area() {
|
||||
return Math.PI * radius * radius;
|
||||
}
|
||||
|
||||
public void showInfo() {
|
||||
super.showInfo();
|
||||
System.out.println("(半径:" + this.radius + ")");
|
||||
}
|
||||
|
||||
}
|
||||
15
em-oop/src/Day3Check1.java
Normal file
15
em-oop/src/Day3Check1.java
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
public class Day3Check1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
//インスタンス作成
|
||||
Circle c = new Circle(2);
|
||||
|
||||
//メソッド呼び出し
|
||||
c.showInfo();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
22
em-oop/src/Shape.java
Normal file
22
em-oop/src/Shape.java
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
public class Shape {
|
||||
|
||||
//フィールド作成
|
||||
private String name;
|
||||
|
||||
//コンストラクタ作成
|
||||
public Shape(String name) {
|
||||
}
|
||||
|
||||
//メソッド作成
|
||||
double area() {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
//メソッド作成
|
||||
void showInfo() {
|
||||
//出力
|
||||
System.out.println(this.name + "の面積は" + this.area() + "です");
|
||||
}
|
||||
|
||||
}
|
||||
10
em-oop/src/Student.java
Normal file
10
em-oop/src/Student.java
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
public class Student {
|
||||
int studentId;
|
||||
String name;
|
||||
|
||||
public void printProfile() {
|
||||
System.out.println("学籍番号:" + this.studentId + " 名前:" + this.name);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user