From b6af93ba982e0a1d1f8c31dfa59b7fcf1f9fe62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=8F=E6=A3=AE=E3=80=80=E7=99=BE=E5=A4=A2?= <26-m-fukumori-cosmicb@it-college.co.jp> Date: Mon, 19 Oct 2026 16:45:02 +0900 Subject: [PATCH] 20261019 --- .../src/main/java/Question04_05.java | 65 ++++++++++++++++--- .../src/main/java/Question05_03.java | 54 ++++++++++++++- .../src/main/java/Class.java | 4 ++ .../src/main/java/Question10_05.java | 2 +- .../src/main/java/Atm.java | 2 +- .../src/main/java/Question11_03.java | 11 +++- .../src/main/java/Student.java | 16 +++++ .../src/main/java/Item.java | 24 +++++++ .../src/main/java/Question12_02.java | 15 +++++ Question13-Extends/.classpath | 6 ++ Question13-Extends/.gitignore | 1 + Question13-Extends/.project | 23 +++++++ .../.settings/org.eclipse.jdt.core.prefs | 9 +++ ....eclipse.wst.common.project.facet.core.xml | 4 ++ Question13-Extends/src/main/java/Animal.java | 4 ++ .../src/main/java/Question13_01.java | 2 +- .../src/main/java/Question13_02.java | 9 +++ 17 files changed, 236 insertions(+), 15 deletions(-) create mode 100644 Question10-InstanceAndClass/src/main/java/Class.java rename Question05-switch/src/main/java/Question05_04.java => Question10-InstanceAndClass/src/main/java/Question10_05.java (78%) create mode 100644 Question11-ConstructorAndStatic/src/main/java/Student.java create mode 100644 Question12-Encapsulation/src/main/java/Item.java create mode 100644 Question12-Encapsulation/src/main/java/Question12_02.java create mode 100644 Question13-Extends/.classpath create mode 100644 Question13-Extends/.gitignore create mode 100644 Question13-Extends/.project create mode 100644 Question13-Extends/.settings/org.eclipse.jdt.core.prefs create mode 100644 Question13-Extends/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 Question13-Extends/src/main/java/Animal.java rename Question05-switch/src/main/java/Question05_05.java => Question13-Extends/src/main/java/Question13_01.java (78%) create mode 100644 Question13-Extends/src/main/java/Question13_02.java diff --git a/Question04-while/src/main/java/Question04_05.java b/Question04-while/src/main/java/Question04_05.java index 5376064..514c6d1 100644 --- a/Question04-while/src/main/java/Question04_05.java +++ b/Question04-while/src/main/java/Question04_05.java @@ -1,22 +1,67 @@ +import java.util.Random; import java.util.Scanner; + public class Question04_05 { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ //勝敗 boolean winFlag = false; - - //最初の言葉 - System.out.println("じゃんけんを行います。、あなたの出す手を入力してください、0:グー, 1:チョキ, 2:パー"); - Scanner sc = new Scanner(System.in); - int select = sc.nextInt(); - int playerHand = select; + - - - while(true) { + while(true) { + //自分側の手 + System.out.println("じゃんけんを行います。、あなたの出す手を入力してください、0:グー, 1:チョキ, 2:パー"); + Scanner sc = new Scanner(System.in); + int select = sc.nextInt(); + int playerHand = select; + + if(playerHand == 0) { + System.out.println("あなたはグーを出しました"); + + } else if(playerHand == 1) { + System.out.println("あなたはチョキを出しました"); + + } else { + System.out.println("あなたはパーを出しました"); + } + - } + //コンピュータ側の手 + + // 1. Randomクラスのインスタンスを生成 + Random rand = new Random(); + + // 2. 乱数を取得するメソッドを呼ぶ + int npcHand = rand.nextInt(2); // int型の範囲でランダムな整数 + + if(npcHand == 0) { + System.out.println("相手はグーを出しました"); + + } else if(playerHand == 1) { + System.out.println("相手はチョキを出しました"); + + } else { + System.out.println("相手はパーを出しました"); + } + + //勝敗を決める + + if(playerHand == npcHand) { + System.out.println("あいこです"); + continue; + + } else if((playerHand == 0 && npcHand == 1) || (playerHand == 1 && npcHand == 2) || (playerHand == 2 && npcHand == 0)) { + System.out.println("あなたの勝ちです"); + + } else { + System.out.println("あなたの負けです"); + continue; + } + break; + } + + } diff --git a/Question05-switch/src/main/java/Question05_03.java b/Question05-switch/src/main/java/Question05_03.java index febf202..ffd8949 100644 --- a/Question05-switch/src/main/java/Question05_03.java +++ b/Question05-switch/src/main/java/Question05_03.java @@ -1,9 +1,61 @@ +import java.util.Random; +import java.util.Scanner; public class Question05_03 { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ + System.out.println( + "=========================================\n" + + "ゲームの説明\n" + + "=========================================\n" + + + "これからハイ&ローゲームを行います。\n" + + "ハイ&ローゲームは、あなたのカードがディーラーのカードより大きいか小さいかを予想するゲームです。\n" + + "=========================================\n" + + "ゲーム開始\n" + + "========================================="); + + + Random random = new Random(); + //ディーラーのカード + int dealerCard = random.nextInt(14); + + System.out.println("ディーラーのカードは" + dealerCard +"です"); + + //自分のカード + int myCard = random.nextInt(14); + + //空行 + System.out.println(); + + System.out.println("あなたのカードがディーラのカードより大きい場合は H 小さい場合は L を入力してください。"); + System.out.println("※ カードの数値が同じ場合はあなたの勝ちです。"); + + + //あなたのカードがディーラーのカードより大きいか小さいか + Scanner scan = new Scanner(System.in); + String judgement = scan.nextLine(); + + System.out.println("あなたのカードは" + myCard + "です"); + + //空行 + System.out.println(); + + System.out.println( + "=========================================\n" + + "勝敗判定\n" + + "=========================================" + ); + //勝敗判定 + if((myCard == dealerCard) || (judgement == "H" && myCard > dealerCard) || (judgement == "L" && myCard < dealerCard)) { + System.out.println("あなたの勝ちです"); + } else if ((judgement !="H") || (judgement != "L")) { + System.out.println("不正な値が入力されました"); + } else { + System.out.println("あなたの負けです"); + } } - + } diff --git a/Question10-InstanceAndClass/src/main/java/Class.java b/Question10-InstanceAndClass/src/main/java/Class.java new file mode 100644 index 0000000..066d608 --- /dev/null +++ b/Question10-InstanceAndClass/src/main/java/Class.java @@ -0,0 +1,4 @@ + +public class Class { + int baseNum; +} diff --git a/Question05-switch/src/main/java/Question05_04.java b/Question10-InstanceAndClass/src/main/java/Question10_05.java similarity index 78% rename from Question05-switch/src/main/java/Question05_04.java rename to Question10-InstanceAndClass/src/main/java/Question10_05.java index e2feaa8..0cd38cd 100644 --- a/Question05-switch/src/main/java/Question05_04.java +++ b/Question10-InstanceAndClass/src/main/java/Question10_05.java @@ -1,5 +1,5 @@ -public class Question05_04 { +public class Question10_05 { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ diff --git a/Question11-ConstructorAndStatic/src/main/java/Atm.java b/Question11-ConstructorAndStatic/src/main/java/Atm.java index 2d9c4d6..4efdde7 100644 --- a/Question11-ConstructorAndStatic/src/main/java/Atm.java +++ b/Question11-ConstructorAndStatic/src/main/java/Atm.java @@ -12,7 +12,7 @@ public class Atm { if(credit < money) { System.out.println("預金残高不足です。現金の引き出しに失敗しました。"); } else { - System.out.println("ATMの残り残高はx" + (credit - money) + "です"); + System.out.println("ATMの残り残高はx" + (credit - wallet.money) + "です"); } } diff --git a/Question11-ConstructorAndStatic/src/main/java/Question11_03.java b/Question11-ConstructorAndStatic/src/main/java/Question11_03.java index f5f386f..d99dac7 100644 --- a/Question11-ConstructorAndStatic/src/main/java/Question11_03.java +++ b/Question11-ConstructorAndStatic/src/main/java/Question11_03.java @@ -3,7 +3,16 @@ public class Question11_03 { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ - + //インスタンスの生成 + Student schooldate = new Student(); + + schooldate.name = "太郎"; + schooldate.group = "A"; + schooldate.teacher = "山田"; + + schooldate.studentProfile(); + schooldate.groupProfile(); + } } diff --git a/Question11-ConstructorAndStatic/src/main/java/Student.java b/Question11-ConstructorAndStatic/src/main/java/Student.java new file mode 100644 index 0000000..ef05502 --- /dev/null +++ b/Question11-ConstructorAndStatic/src/main/java/Student.java @@ -0,0 +1,16 @@ + +public class Student { + //フィールドの宣言 + String name; + String group; + String teacher; + + //メソッドの生成 + public void studentProfile() { + System.out.println(name + "は" + group + "教室の生徒です。"); + } + + public void groupProfile() { + System.out.println(group + "教室の担任は" + teacher + "先生です。"); + } +} diff --git a/Question12-Encapsulation/src/main/java/Item.java b/Question12-Encapsulation/src/main/java/Item.java new file mode 100644 index 0000000..261834e --- /dev/null +++ b/Question12-Encapsulation/src/main/java/Item.java @@ -0,0 +1,24 @@ +public class Item { + + private String item = "アイテムA"; + + + // ゲッターセッターの設定 + public String getItem() { + return item; + } + + public void setItem(String item) { + this.item = item; + } + + //コンストラクタの設定 + public Item(String item) { + this.item = item; + } + + //メソッドの設定 + public void itembox() { + System.out.println(item); + } +} diff --git a/Question12-Encapsulation/src/main/java/Question12_02.java b/Question12-Encapsulation/src/main/java/Question12_02.java new file mode 100644 index 0000000..b6d8572 --- /dev/null +++ b/Question12-Encapsulation/src/main/java/Question12_02.java @@ -0,0 +1,15 @@ + +public class Question12_02 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + //インスタンスの生成 + Item secretitem = new Item(); + + secretitem.itembox(); + secretitem.setItem(); + System.out.println(secretitem.getItem()); + + } + +} diff --git a/Question13-Extends/.classpath b/Question13-Extends/.classpath new file mode 100644 index 0000000..c771657 --- /dev/null +++ b/Question13-Extends/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/Question13-Extends/.gitignore b/Question13-Extends/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/Question13-Extends/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/Question13-Extends/.project b/Question13-Extends/.project new file mode 100644 index 0000000..5c757c4 --- /dev/null +++ b/Question13-Extends/.project @@ -0,0 +1,23 @@ + + + Question13-Extends + + + + + + 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/Question13-Extends/.settings/org.eclipse.jdt.core.prefs b/Question13-Extends/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..23fa13b --- /dev/null +++ b/Question13-Extends/.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/Question13-Extends/.settings/org.eclipse.wst.common.project.facet.core.xml b/Question13-Extends/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..c1a8d07 --- /dev/null +++ b/Question13-Extends/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Question13-Extends/src/main/java/Animal.java b/Question13-Extends/src/main/java/Animal.java new file mode 100644 index 0000000..ea2c5d1 --- /dev/null +++ b/Question13-Extends/src/main/java/Animal.java @@ -0,0 +1,4 @@ + +public class Animal { + +} diff --git a/Question05-switch/src/main/java/Question05_05.java b/Question13-Extends/src/main/java/Question13_01.java similarity index 78% rename from Question05-switch/src/main/java/Question05_05.java rename to Question13-Extends/src/main/java/Question13_01.java index 8eb0692..ca90db0 100644 --- a/Question05-switch/src/main/java/Question05_05.java +++ b/Question13-Extends/src/main/java/Question13_01.java @@ -1,5 +1,5 @@ -public class Question05_05 { +public class Question13_01 { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ diff --git a/Question13-Extends/src/main/java/Question13_02.java b/Question13-Extends/src/main/java/Question13_02.java new file mode 100644 index 0000000..4558298 --- /dev/null +++ b/Question13-Extends/src/main/java/Question13_02.java @@ -0,0 +1,9 @@ + +public class Question13_02 { + + public static void main(String[] args) { + // TODO 自動生成されたメソッド・スタブ + + } + +}