Day3 Stept2

This commit is contained in:
2026-09-16 13:33:37 +09:00
parent a9e99590ca
commit 67baf3374c
5 changed files with 61 additions and 5 deletions

View File

@@ -0,0 +1,15 @@
package day3Keisho;
public class Day3Check2 {
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
Rectangle rect = new Rectangle(3.0, 4.0);
rect.showInfo();
Greeting greeting = new JapaneseGreeting();
System.out.println(greeting.hello());
}
}

View File

@@ -0,0 +1,6 @@
package day3Keisho;
public interface Greeting {
String hello();
}

View File

@@ -0,0 +1,11 @@
package day3Keisho;
public class JapaneseGreeting implements Greeting {
@Override
public String hello() {
return "こんにちは";
}
}

View File

@@ -0,0 +1,21 @@
package day3Keisho;
public class Rectangle extends Shape {
private double width;
private double height;
public Rectangle(double width,double height) {
super("四角形");
this.height=height;
this.width=width;
}
@Override
public double area() {
// TODO 自動生成されたメソッド・スタブ
//super.showInfo();
return width*height;
}
}

View File

@@ -1,16 +1,19 @@
package day3Keisho; package day3Keisho;
public class Shape { //public class Shape { //stept 1
public abstract class Shape{ //stept 2
private String name; private String name;
public Shape(String name) { public Shape(String name) {
this.name = name; this.name = name;
} }
public double area() { public abstract double area(); //stept 2
return 0.0; // public double area() { //stept 1
// return 0.0;
} //
// }
public void showInfo() { public void showInfo() {
System.out.println(this.name + "の面積は" + this.area() + "です"); System.out.println(this.name + "の面積は" + this.area() + "です");