From 60e3eeb77f2f804ced11cbb1e99fb5874da7be52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=88=B4=E6=9C=A8=E3=80=80=E7=9A=93=E4=BB=8B?= <26-k-suzuki-avnz@it-college.co.jp> Date: Tue, 20 Oct 2026 16:37:13 +0900 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E4=BA=86=E6=B8=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Question14-Interface/.classpath | 6 +++++ Question14-Interface/.gitignore | 1 + Question14-Interface/.project | 23 +++++++++++++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 ++++++++ ....eclipse.wst.common.project.facet.core.xml | 4 ++++ Question14-Interface/src/main/java/Book.java | 7 ++++++ Question14-Interface/src/main/java/Car.java | 7 ++++++ .../src/main/java/ProgrammingBook.java | 20 ++++++++++++++++ .../src/main/java/Question14_1.java | 17 ++++++++++++++ .../src/main/java/Question14_2.java | 14 +++++++++++ .../src/main/java/SportCar.java | 16 +++++++++++++ Question15-Polymorphism/.classpath | 6 +++++ Question15-Polymorphism/.gitignore | 1 + Question15-Polymorphism/.project | 23 +++++++++++++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 ++++++++ ....eclipse.wst.common.project.facet.core.xml | 4 ++++ .../src/main/java/Car.java | 20 ++++++++++++++++ .../src/main/java/Question15_1.java | 14 +++++++++++ .../src/main/java/Question15_2.java | 20 ++++++++++++++++ .../src/main/java/Question15_3.java | 12 ++++++++++ .../src/main/java/SportCar.java | 13 +++++++++++ .../src/main/java/Truck.java | 8 +++++++ 22 files changed, 254 insertions(+) create mode 100644 Question14-Interface/.classpath create mode 100644 Question14-Interface/.gitignore create mode 100644 Question14-Interface/.project create mode 100644 Question14-Interface/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question14-Interface/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question14-Interface/src/main/java/Book.java create mode 100644 Question14-Interface/src/main/java/Car.java create mode 100644 Question14-Interface/src/main/java/ProgrammingBook.java create mode 100644 Question14-Interface/src/main/java/Question14_1.java create mode 100644 Question14-Interface/src/main/java/Question14_2.java create mode 100644 Question14-Interface/src/main/java/SportCar.java create mode 100644 Question15-Polymorphism/.classpath create mode 100644 Question15-Polymorphism/.gitignore create mode 100644 Question15-Polymorphism/.project create mode 100644 Question15-Polymorphism/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question15-Polymorphism/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question15-Polymorphism/src/main/java/Car.java create mode 100644 Question15-Polymorphism/src/main/java/Question15_1.java create mode 100644 Question15-Polymorphism/src/main/java/Question15_2.java create mode 100644 Question15-Polymorphism/src/main/java/Question15_3.java create mode 100644 Question15-Polymorphism/src/main/java/SportCar.java create mode 100644 Question15-Polymorphism/src/main/java/Truck.java diff --git a/Question14-Interface/.classpath b/Question14-Interface/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question14-Interface/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question14-Interface/.gitignore b/Question14-Interface/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question14-Interface/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question14-Interface/.project b/Question14-Interface/.project new file mode 100644 index 0000000..e86df9d --- /dev/null +++ b/Question14-Interface/.project @@ -0,0 +1,23 @@ + + + Question14-Interface + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + + diff --git a/Question14-Interface/.settings/org.eclipse.jdt.core.prefs b/Question14-Interface/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question14-Interface/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 +org.eclipse.jdt.core.compiler.compliance=21 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=21 diff --git a/Question14-Interface/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question14-Interface/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question14-Interface/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question14-Interface/src/main/java/Book.java b/Question14-Interface/src/main/java/Book.java new file mode 100644 index 0000000..b0b8914 --- /dev/null +++ b/Question14-Interface/src/main/java/Book.java @@ -0,0 +1,7 @@ + +public interface Book { + + String getTitle(); + String[] getChapters(); + +} diff --git a/Question14-Interface/src/main/java/Car.java b/Question14-Interface/src/main/java/Car.java new file mode 100644 index 0000000..00f8a23 --- /dev/null +++ b/Question14-Interface/src/main/java/Car.java @@ -0,0 +1,7 @@ + +public interface Car { + + void Charge(int gasoline); + void Run(int velocity); + +} diff --git a/Question14-Interface/src/main/java/ProgrammingBook.java b/Question14-Interface/src/main/java/ProgrammingBook.java new file mode 100644 index 0000000..43b5d28 --- /dev/null +++ b/Question14-Interface/src/main/java/ProgrammingBook.java @@ -0,0 +1,20 @@ + +public class ProgrammingBook implements Book { + + String title; + String[] chapters; + + public ProgrammingBook(String title,String[] chapters) { + this.title = title; + this.chapters = chapters; + } + + public String getTitle() { + return this.title; + } + + public String[] getChapters() { + return this.chapters; + } + +} diff --git a/Question14-Interface/src/main/java/Question14_1.java b/Question14-Interface/src/main/java/Question14_1.java new file mode 100644 index 0000000..e2c2f0d --- /dev/null +++ b/Question14-Interface/src/main/java/Question14_1.java @@ -0,0 +1,17 @@ + +public class Question14_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + + String title = "プログラミング基礎入門"; + String[] chapters = {"式と変数","制御構文","メソッド","オブジェクト指向","継承"}; + ProgrammingBook pb = new ProgrammingBook(title,chapters); + + System.out.println(pb.getTitle()); + for (String s:pb.getChapters()) { + System.out.print(s+" "); + } + } + +} diff --git a/Question14-Interface/src/main/java/Question14_2.java b/Question14-Interface/src/main/java/Question14_2.java new file mode 100644 index 0000000..7234b75 --- /dev/null +++ b/Question14-Interface/src/main/java/Question14_2.java @@ -0,0 +1,14 @@ + +public class Question14_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + + SportCar sc = new SportCar(); + sc.Charge(100); + sc.Run(100); + sc.Run(301); + + } + +} diff --git a/Question14-Interface/src/main/java/SportCar.java b/Question14-Interface/src/main/java/SportCar.java new file mode 100644 index 0000000..d7565fe --- /dev/null +++ b/Question14-Interface/src/main/java/SportCar.java @@ -0,0 +1,16 @@ + +public class SportCar implements Car { + + public void Charge(int gasoline) { + System.out.println("ハイオクを"+gasoline+"リットル補充した"); + } + + public void Run(int velocity) { + if (velocity>300) { + System.out.println("速度オーバーです"); + } else { + System.out.println("スポーツカーは時速"+velocity+"キロで走った"); + } + } + +} diff --git a/Question15-Polymorphism/.classpath b/Question15-Polymorphism/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question15-Polymorphism/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question15-Polymorphism/.gitignore b/Question15-Polymorphism/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question15-Polymorphism/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question15-Polymorphism/.project b/Question15-Polymorphism/.project new file mode 100644 index 0000000..a05b1e2 --- /dev/null +++ b/Question15-Polymorphism/.project @@ -0,0 +1,23 @@ + + + Question15-Polymorphism + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + + diff --git a/Question15-Polymorphism/.settings/org.eclipse.jdt.core.prefs b/Question15-Polymorphism/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question15-Polymorphism/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 +org.eclipse.jdt.core.compiler.compliance=21 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=21 diff --git a/Question15-Polymorphism/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question15-Polymorphism/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question15-Polymorphism/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question15-Polymorphism/src/main/java/Car.java b/Question15-Polymorphism/src/main/java/Car.java new file mode 100644 index 0000000..d931b8b --- /dev/null +++ b/Question15-Polymorphism/src/main/java/Car.java @@ -0,0 +1,20 @@ + +public class Car { + + String name; + int velocity; + + public Car() { + + } + + public Car(String name,int velocity) { + this.name = name; + this.velocity = velocity; + } + + public void run() { + System.out.println(this.name+"は時速"+this.velocity+"で走った"); + } + +} diff --git a/Question15-Polymorphism/src/main/java/Question15_1.java b/Question15-Polymorphism/src/main/java/Question15_1.java new file mode 100644 index 0000000..b63a73d --- /dev/null +++ b/Question15-Polymorphism/src/main/java/Question15_1.java @@ -0,0 +1,14 @@ + +public class Question15_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + + Car sp = new SportCar(); + sp.run(); + Car tr = new Truck(); + tr.run(); + + } + +} diff --git a/Question15-Polymorphism/src/main/java/Question15_2.java b/Question15-Polymorphism/src/main/java/Question15_2.java new file mode 100644 index 0000000..107910d --- /dev/null +++ b/Question15-Polymorphism/src/main/java/Question15_2.java @@ -0,0 +1,20 @@ + +public class Question15_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + + Car sp = new SportCar(); + Car tr = new Truck(); + + Car[] cars = new Car[2]; + cars[0] = sp; + cars[1] = tr; + + for (Car c:cars) { + c.run(); + } + + } + +} diff --git a/Question15-Polymorphism/src/main/java/Question15_3.java b/Question15-Polymorphism/src/main/java/Question15_3.java new file mode 100644 index 0000000..96e9a0c --- /dev/null +++ b/Question15-Polymorphism/src/main/java/Question15_3.java @@ -0,0 +1,12 @@ + +public class Question15_3 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + + Car car = new SportCar(); + ((SportCar)car).run(); + + } + +} diff --git a/Question15-Polymorphism/src/main/java/SportCar.java b/Question15-Polymorphism/src/main/java/SportCar.java new file mode 100644 index 0000000..37929ad --- /dev/null +++ b/Question15-Polymorphism/src/main/java/SportCar.java @@ -0,0 +1,13 @@ + +public class SportCar extends Car { + + public SportCar() { + super("スポーツカー",100); + } + + @Override + public void run() { + System.out.println(this.name+"は時速"+(3*this.velocity)+"で走った"); + } + +} diff --git a/Question15-Polymorphism/src/main/java/Truck.java b/Question15-Polymorphism/src/main/java/Truck.java new file mode 100644 index 0000000..0e4b198 --- /dev/null +++ b/Question15-Polymorphism/src/main/java/Truck.java @@ -0,0 +1,8 @@ + +public class Truck extends Car { + + public Truck() { + super("トラック",30); + } + +}