javaは双色球の宝くじのゲームを実現します。
総合事例開発:双色球宝くじのゲームをシミュレーションします。参考にしてください。具体的な内容は以下の通りです。
遊び方の説明:
ダブルカラーボールはレッドボールの番号エリアとブルーボールの番号エリアに分かれています。赤いボールの番号は01~33で、ブルーボールの番号は01~16です。ダブルカラーボールは毎号33個の赤いボールの中から6つの番号(重複できません)を出して、16個のブルーボールの中から1つの番号を当選番号として出して、双色球の遊び方はつまり当選番号の6つの赤いボールの番号と1つの青いボールの番号をクイズするので、順番は制限しません。ユーザーは赤いボールと青いボールの番号を入力して、プログラムはこのユーザーの中で何等賞を出力します。
コードの実装:
遊び方の説明:
ダブルカラーボールはレッドボールの番号エリアとブルーボールの番号エリアに分かれています。赤いボールの番号は01~33で、ブルーボールの番号は01~16です。ダブルカラーボールは毎号33個の赤いボールの中から6つの番号(重複できません)を出して、16個のブルーボールの中から1つの番号を当選番号として出して、双色球の遊び方はつまり当選番号の6つの赤いボールの番号と1つの青いボールの番号をクイズするので、順番は制限しません。ユーザーは赤いボールと青いボールの番号を入力して、プログラムはこのユーザーの中で何等賞を出力します。
コードの実装:
import java.util.Random;
import java.util.Scanner;
public class SimulatedLottery {
public static void main(String[] args) {
//
int maxMoney = 500;
//
System.out.print(" :");
Scanner input = new Scanner(System.in);
int blueBall = input.nextInt();
//
int[] redBall = new int[6];
System.out.print(" ( ):");
for (int i = 0; i < redBall.length; i++) {
redBall[i] = input.nextInt();
}
//
System.out.println("----------------");
System.out.print(" :");
for (int i = 0; i < redBall.length; i++) {
System.out.print(redBall[i]+",");
}
System.out.println();
System.out.println(" :"+blueBall);
System.out.println("--- ---");
//
Random numsRandom = new Random();
int blueBallRandom = numsRandom.nextInt(16)+1;
//
int[] redBallRandom = new int[6];
int index = redBallRandom.length;
int inputRandom = 0;
int k = 0;
while (index>0) {
if (exist(redBallRandom, inputRandom)) {
// ,
inputRandom = numsRandom.nextInt(33)+1;
}else {
//
redBallRandom[k] = inputRandom;
k++;
index--;
}
}
//
System.out.println(" :"+blueBallRandom);
System.out.print(" :");
for (int i = 0; i < redBallRandom.length; i++) {
System.out.print(redBallRandom[i]+",");
}
System.out.println();
//
int blueCount = 0;
if (blueBall == blueBallRandom) {
blueCount = 1;
}
//
int redCount = 0;
for (int i = 0; i < redBallRandom.length; i++) {
if (redBall[i] == redBallRandom[i]) {
redCount++;
}
}
//
if (blueCount == 0 && redCount <= 3) {
//
System.out.println(" , , , !");
//
}else if(blueCount == 1 && redCount < 3) {
System.out.println(" , , 5 ");
}else if((blueCount == 1 && redCount == 3) || (blueCount == 0 && redCount == 4)) {
System.out.println(" , , 10 ");
}else if((blueCount == 1 && redCount == 4) && (blueCount == 0 && redCount == 5)) {
System.out.println(" , , 200 ");
}else if(blueCount == 1 && redCount == 5) {
System.out.println(" , , 3000 ");
}else if(blueCount == 0 && redCount == 6) {
System.out.println(" , , "+(int)(maxMoney*0.3)+" ");
}else if(blueCount == 1 && redCount == 6 ) {
System.out.println(" , , "+maxMoney+" ");
}
}
// , true
public static boolean exist(int[] redBallRandom, int inputRandom) {
for (int i = 0; i < redBallRandom.length; i++) {
if(redBallRandom[i] == inputRandom) {
return true;
}
}
return false;
}
}
以上が本文の全部です。皆さんの勉強に役に立つように、私たちを応援してください。