***********************************************************************************
******************************************
MAIN
***********************************************************************************
******************************************
import java.util.*;
public class Main {
public static void main(String[] args) {
// CREAMOS EL ARRAYLIST:
ArrayList <Lanzamiento> lanzamientos = new ArrayList<Lanzamiento>();
Lanzamiento lan = new Lanzamiento();
Scanner lector = new Scanner(System.in);
System.out.println("Ingrese la cantidad de lanzamientos de su CACHITO:
");
int cant1 = lector.nextInt();
int cant2=5;
if (cant1 < 100 || cant1 > 200) {
while (cant1 < 100 || cant1 > 200) {
System.out.println("La cantidad debe estar entre 100 y 200
vuelva a ingresar el dato!");
System.out.println("***************************************************************
********");
System.out.println("Ingrese la cantidad de lanzamientos de
su CACHITO: ");
cant2 = lector.nextInt();
cant1 = cant2;
}
}else {
cant2 = cant1;
}
// PARA DETERMINAR SI ES POKER
int cantidadPoker=0;
int a=0;
while(a<= cant2) {
lanzamientos.add(new Lanzamiento());
//lan.esPoker();
if(lan.esPoker() == true) {
cantidadPoker++;
}
a++;
}
// PORCENTAJE DE OCURRENCIA
int ocurrencia=0;
ocurrencia = cantidadPoker * 100 / cant2;
//System.out.println("numeros: " + lanzamientos);
System.out.println("Cantidad de veces que salió poker: " +
cantidadPoker);
System.out.println("Porcentaje de ocurrencia: " + ocurrencia + "%");
***********************************************************************************
******************************************
LANZAMIENTO
***********************************************************************************
******************************************
import java.util.*;
import java.util.Random;
public class Lanzamiento {
private int dado1;
private int dado2;
private int dado3;
private int dado4;
private int dado5;
int sumaUno=0;
int sumaDos=0;
int sumaTres=0;
int sumaCuatro=0;
int sumaCinco=0;
int sumaSeis=0;
// ***** CONSTRUCTOR:
public Lanzamiento() {
// Para crear números aleatorios:
Random rand = new Random();
// Generamos números randomicos entre 1 y 6
this.dado1 = rand.nextInt(6-1+1)+1;
this.dado2 = rand.nextInt(6-1+1)+1;
this.dado3 = rand.nextInt(6-1+1)+1;
this.dado4 = rand.nextInt(6-1+1)+1;
this.dado5 = rand.nextInt(6-1+1)+1;
}
// ***** POKER:
public Boolean esPoker() {
Boolean poker = false;
int uno = this.dado1;
int dos = this.dado2;
int tre = this.dado3;
int cua = this.dado4;
int cin = this.dado5;
// SUMATORIA POR SI SALIERON DADOS IGUAL A 1
if(uno == 1) { sumaUno++;
}else if(dos==1) { sumaUno++;
}else if(tre==1) { sumaUno++;
}else if(cua==1) { sumaUno++;
}else if(cin==1) { sumaUno++;
}
// SUMATORIA POR SI SALIERON DADOS IGUAL A 2
if(uno == 2) { sumaDos++;
}else if(dos==2) { sumaDos++;
}else if(tre==2) { sumaDos++;
}else if(cua==2) { sumaDos++;
}else if(cin==2) { sumaDos++;
}
// SUMATORIA POR SI SALIERON DADOS IGUAL A 3
if(uno == 3) { sumaTres++;
}else if(dos==3) { sumaTres++;
}else if(tre==3) { sumaTres++;
}else if(cua==3) { sumaTres++;
}else if(cin==3) { sumaTres++;
}
// SUMATORIA POR SI SALIERON DADOS IGUAL A 4
if(uno == 4) { sumaCuatro++;
}else if(dos==4) { sumaCuatro++;
}else if(tre==4) { sumaCuatro++;
}else if(cua==4) { sumaCuatro++;
}else if(cin==4) { sumaCuatro++;
}
// SUMATORIA POR SI SALIERON DADOS IGUAL A 5
if(uno == 5) { sumaCinco++;
}else if(dos==5) { sumaCinco++;
}else if(tre==5) { sumaCinco++;
}else if(cua==5) { sumaCinco++;
}else if(cin==5) { sumaCinco++;
}
// SUMATORIA POR SI SALIERON DADOS IGUAL A 6
if(uno == 6) { sumaSeis++;
}else if(dos==6) { sumaSeis++;
}else if(tre==6) { sumaSeis++;
}else if(cua==6) { sumaSeis++;
}else if(cin==6) { sumaSeis++;
}
if (sumaUno==4 || sumaDos==4 || sumaTres==4 || sumaCuatro==4 ||
sumaCinco==4 || sumaSeis==4) {
poker = true;
} else {
poker = false;
}
return poker;
}
// ***** SETTERS & GETTERS
public int getDado1() {
return dado1;
}
public void setDado1(int dado1) {
this.dado1 = dado1;
}
public int getDado2() {
return dado2;
}
public void setDado2(int dado2) {
this.dado2 = dado2;
}
public int getDado3() {
return dado3;
}
public void setDado3(int dado3) {
this.dado3 = dado3;
}
public int getDado4() {
return dado4;
}
public void setDado4(int dado4) {
this.dado4 = dado4;
}
public int getDado5() {
return dado5;
}
public void setDado5(int dado5) {
this.dado5 = dado5;
}
// ***** TO STRING
@Override
public String toString() {
return dado1 + "\t" + dado2 + "\t" + dado3 + "\t" + dado4 + "\t" +
dado5 ;
}