Day31段階目完了
This commit is contained in:
1
em-oop/.gitignore
vendored
1
em-oop/.gitignore
vendored
@@ -1 +1,2 @@
|
||||
/bin/
|
||||
/.metadata/
|
||||
|
||||
@@ -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
21
em-oop/src/Circle.java
Normal 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 + "");
|
||||
}
|
||||
}
|
||||
10
em-oop/src/Day3Check1.java
Normal file
10
em-oop/src/Day3Check1.java
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
public class Day3Check1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
//インスタンス
|
||||
Circle circle = new Circle(2.0);
|
||||
circle.showInfo();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
16
em-oop/src/Sharpe.java
Normal 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() + "です");
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user