0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Javaでの学習記録

Last updated at Posted at 2025-05-06

概要

今回はjavaで基礎学習用のコード(じゃんけん)を書いてみました。
学習のメモ程度に記述していますのでご承知ください。

動作環境

・windows:Windows11Pro 23H2
・java:22.0.1
・統合開発環境:Eclipse

UML(統一モデリング言語)図 作成中

UML.png

スクリプト

JANKEN.java
package helloworld;

public class JANKEN {

	public static void main(String[] args) {
		OutPrint log = new OutPrint();//ログ出力用のオブジェクト
		OpponentInput opponentInput = new OpponentInput();
		MyHand hands = new MyHand();
		//Game Start
		log.GameStartPrint();
		
		//相手の数を決定する
		int opnum = opponentInput.getOpponentNum();
		System.out.println("相手の数:"+opnum);
		
		//出し手の出力
		hands.AskMyHand();
		hands.setMyHand();
		
		//Game Finish
		log.GameFinishPrint();
	}

}
OutPrint.java
package helloworld;

public class OutPrint {
	//ゲーム開始のログ出力
	public void GameStartPrint() {
		System.out.println("Game Start!");
	}
	//ゲーム終了のログ出力
	public void GameFinishPrint() {
		System.out.println("Game Finish!");
	}
	
}
OpponentInput.java
package helloworld;

public class OpponentInput {
	final int OpponentNum = 3;
	//OpponentNumの取得
	int getOpponentNum() {
		return OpponentNum;
	}
}
MyHand.java
package helloworld;

public class MyHand {
	int selecthand;
	int myhand;
	void AskMyHand() {
		System.out.println("ROCK:0,SCISSORS:1,PAPER:2");
		selecthand = 0;		
	}
	void setMyHand() {
		myhand = selecthand;
		switch (myhand) {
		case 0: {
			HandKind hands = HandKind.ROCK;
			System.out.println("自分の手:"+hands.toString());		
			break;
		}
		case 1: {
			HandKind hands = HandKind.SCISSORS;
			System.out.println("自分の手:"+hands.toString());
			break;
		}
		case 2: {
			HandKind hands = HandKind.PAPER;
			System.out.println("自分の手:"+hands.toString());
			break;
		}
		default:
			throw new IllegalArgumentException("Unexpected value: " + myhand);
		}
	}
	int getMyHand() {
		return myhand;
	}
}
HandKind.java
package helloworld;

public enum HandKind {
	ROCK,
	SCISSORS,
	PAPER;
}
ResultKind.java
package helloworld;

public enum ResultKind {
	WIN,
	LOSE,
	DRAW,
	EXCEPT;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?