20261019
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Question04_05 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
@@ -6,18 +8,61 @@ public class Question04_05 {
|
||||
//勝敗
|
||||
boolean winFlag = false;
|
||||
|
||||
//最初の言葉
|
||||
|
||||
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("あなたはチョキを出しました");
|
||||
|
||||
while(true) {
|
||||
|
||||
} 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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("あなたの負けです");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
4
Question10-InstanceAndClass/src/main/java/Class.java
Normal file
4
Question10-InstanceAndClass/src/main/java/Class.java
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
public class Class {
|
||||
int baseNum;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
public class Question05_04 {
|
||||
public class Question10_05 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
@@ -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) + "です");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,15 @@ 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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
16
Question11-ConstructorAndStatic/src/main/java/Student.java
Normal file
16
Question11-ConstructorAndStatic/src/main/java/Student.java
Normal file
@@ -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 + "先生です。");
|
||||
}
|
||||
}
|
||||
24
Question12-Encapsulation/src/main/java/Item.java
Normal file
24
Question12-Encapsulation/src/main/java/Item.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
15
Question12-Encapsulation/src/main/java/Question12_02.java
Normal file
15
Question12-Encapsulation/src/main/java/Question12_02.java
Normal file
@@ -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());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
6
Question13-Extends/.classpath
Normal file
6
Question13-Extends/.classpath
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
<classpathentry kind="output" path="build/classes"/>
|
||||
</classpath>
|
||||
1
Question13-Extends/.gitignore
vendored
Normal file
1
Question13-Extends/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build/
|
||||
23
Question13-Extends/.project
Normal file
23
Question13-Extends/.project
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Question13-Extends</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
9
Question13-Extends/.settings/org.eclipse.jdt.core.prefs
Normal file
9
Question13-Extends/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -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
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<installed facet="java" version="21"/>
|
||||
</faceted-project>
|
||||
4
Question13-Extends/src/main/java/Animal.java
Normal file
4
Question13-Extends/src/main/java/Animal.java
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
public class Animal {
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
public class Question05_05 {
|
||||
public class Question13_01 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
9
Question13-Extends/src/main/java/Question13_02.java
Normal file
9
Question13-Extends/src/main/java/Question13_02.java
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
public class Question13_02 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user