From 3036f2c3c32146e84c273eefb8a53178a1ef3450 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: Thu, 15 Oct 2026 11:34:01 +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 --- Question11-ConstructorAndStatic/.classpath | 6 +++++ Question11-ConstructorAndStatic/.gitignore | 1 + Question11-ConstructorAndStatic/.project | 23 +++++++++++++++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 ++++++++ ....eclipse.wst.common.project.facet.core.xml | 4 ++++ .../src/main/java/Atm.java | 20 ++++++++++++++++ .../src/main/java/Cat.java | 14 +++++++++++ .../src/main/java/Jam.java | 10 ++++++++ .../src/main/java/Question11_1.java | 20 ++++++++++++++++ .../src/main/java/Question11_2.java | 20 ++++++++++++++++ .../src/main/java/Question11_3.java | 15 ++++++++++++ .../src/main/java/Question11_4.java | 17 ++++++++++++++ .../src/main/java/Question11_5.java | 14 +++++++++++ .../src/main/java/Student.java | 16 +++++++++++++ .../src/main/java/Toast.java | 14 +++++++++++ .../src/main/java/User.java | 16 +++++++++++++ .../src/main/java/Wallet.java | 6 +++++ 17 files changed, 225 insertions(+) create mode 100644 Question11-ConstructorAndStatic/.classpath create mode 100644 Question11-ConstructorAndStatic/.gitignore create mode 100644 Question11-ConstructorAndStatic/.project create mode 100644 Question11-ConstructorAndStatic/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question11-ConstructorAndStatic/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question11-ConstructorAndStatic/src/main/java/Atm.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Cat.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Jam.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Question11_1.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Question11_2.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Question11_3.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Question11_4.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Question11_5.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Student.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Toast.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/User.java create mode 100644 Question11-ConstructorAndStatic/src/main/java/Wallet.java diff --git a/Question11-ConstructorAndStatic/.classpath b/Question11-ConstructorAndStatic/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question11-ConstructorAndStatic/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question11-ConstructorAndStatic/.gitignore b/Question11-ConstructorAndStatic/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question11-ConstructorAndStatic/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question11-ConstructorAndStatic/.project b/Question11-ConstructorAndStatic/.project new file mode 100644 index 0000000..ba1d001 --- /dev/null +++ b/Question11-ConstructorAndStatic/.project @@ -0,0 +1,23 @@ + + + Question11-ConstructorAndStatic + + + + + + 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/Question11-ConstructorAndStatic/.settings/org.eclipse.jdt.core.prefs b/Question11-ConstructorAndStatic/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question11-ConstructorAndStatic/.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/Question11-ConstructorAndStatic/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question11-ConstructorAndStatic/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question11-ConstructorAndStatic/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question11-ConstructorAndStatic/src/main/java/Atm.java b/Question11-ConstructorAndStatic/src/main/java/Atm.java new file mode 100644 index 0000000..4dbb3b2 --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Atm.java @@ -0,0 +1,20 @@ + +public class Atm { + + int credit; + + public Atm () { + this.credit = 100000; + } + + public void withdraw( Wallet wallet , int money ) { + if ( this.credit < money ) { + System.out.println("預金残高不足です。現金の引き出しに失敗しました。"); + } else { + this.credit = this.credit - money; + wallet.money = wallet.money + money; + System.out.println("ATMの残り残高は"+this.credit+"です"); + } + } + +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Cat.java b/Question11-ConstructorAndStatic/src/main/java/Cat.java new file mode 100644 index 0000000..d80b990 --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Cat.java @@ -0,0 +1,14 @@ + +public class Cat { + + String name; + + public Cat() { + this.name = "タマ"; + } + + public Cat( String name ) { + this.name = name; + } + +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Jam.java b/Question11-ConstructorAndStatic/src/main/java/Jam.java new file mode 100644 index 0000000..8d4de8a --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Jam.java @@ -0,0 +1,10 @@ + +public class Jam { + + String material; + + public Jam( String jam ) { + this.material = jam; + } + +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Question11_1.java b/Question11-ConstructorAndStatic/src/main/java/Question11_1.java new file mode 100644 index 0000000..d8d2d21 --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Question11_1.java @@ -0,0 +1,20 @@ + +public class Question11_1 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + + Wallet wallet = new Wallet(); + wallet.money = 10000; + + User user = new User(); + user.name = "太郎"; + user.wallet = wallet; + + user.confirmWallet(); + user.useMoney(1000); + user.confirmWallet(); + + } + +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Question11_2.java b/Question11-ConstructorAndStatic/src/main/java/Question11_2.java new file mode 100644 index 0000000..dfc1966 --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Question11_2.java @@ -0,0 +1,20 @@ + +public class Question11_2 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + + Wallet wallet = new Wallet(); + wallet.money = 10000; + + Atm atm = new Atm(); + + atm.withdraw(wallet,100000); + System.out.println(wallet.money); + + atm.withdraw(wallet,100000); + System.out.println(wallet.money); + + } + +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Question11_3.java b/Question11-ConstructorAndStatic/src/main/java/Question11_3.java new file mode 100644 index 0000000..12f1065 --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Question11_3.java @@ -0,0 +1,15 @@ + +public class Question11_3 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + + Cat cat1 = new Cat(); + System.out.println(cat1.name); + + Cat cat2 = new Cat("ミケ"); + System.out.println(cat2.name); + + } + +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Question11_4.java b/Question11-ConstructorAndStatic/src/main/java/Question11_4.java new file mode 100644 index 0000000..59ff575 --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Question11_4.java @@ -0,0 +1,17 @@ + +public class Question11_4 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + + Student student = new Student(); + student.name = "太郎"; + student.group = "A"; + student.teacher = "山田"; + + student.studentProfile(); + student.groupProfile(); + + } + +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Question11_5.java b/Question11-ConstructorAndStatic/src/main/java/Question11_5.java new file mode 100644 index 0000000..29cd9af --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Question11_5.java @@ -0,0 +1,14 @@ + +public class Question11_5 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + + Jam jam = new Jam("ブルーベリー"); + Toast toast = new Toast(jam); + + toast.taste(); + + } + +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Student.java b/Question11-ConstructorAndStatic/src/main/java/Student.java new file mode 100644 index 0000000..6417147 --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Student.java @@ -0,0 +1,16 @@ + +public class Student { + + String name; + static String group; + static String teacher; + + public void studentProfile() { + System.out.println(this.name+"は"+this.group+"教室の生徒です。"); + } + + public void groupProfile() { + System.out.println(this.group+"教室の担任は"+this.teacher+"先生です。"); + } + +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Toast.java b/Question11-ConstructorAndStatic/src/main/java/Toast.java new file mode 100644 index 0000000..7b362cf --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Toast.java @@ -0,0 +1,14 @@ + +public class Toast { + + Jam jam; + + public Toast(Jam jam) { + this.jam = jam; + } + + public void taste() { + System.out.println(jam.material+"味のトーストです。"); + } + +} diff --git a/Question11-ConstructorAndStatic/src/main/java/User.java b/Question11-ConstructorAndStatic/src/main/java/User.java new file mode 100644 index 0000000..0998463 --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/User.java @@ -0,0 +1,16 @@ + +public class User { + + String name; + Wallet wallet; + + public void useMoney( int money ) { + this.wallet.money = this.wallet.money - money; + System.out.println(this.name+"は財布の中のお金を"+money+"円使用しました"); + } + + public void confirmWallet() { + System.out.println(this.name+"の財布の中の残額は"+this.wallet.money+"円です"); + } + +} diff --git a/Question11-ConstructorAndStatic/src/main/java/Wallet.java b/Question11-ConstructorAndStatic/src/main/java/Wallet.java new file mode 100644 index 0000000..cc6c2f6 --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Wallet.java @@ -0,0 +1,6 @@ + +public class Wallet { + + int money; + +}