Olá a todos, eu tenho uma duvida em gerar uma chave para um sorteio em java basico…
tenho a classe Chave
[code]public class Chave {
private int[] numeros;
private int[] estrelas;
public Chave(int[] numeros, int[] estrelas) {
this.numeros = new int [5];
this.estrelas = new int [2];
}
public int[] getEstrelas() {
return this.estrelas;
}
public int[] getNumeros() {
return this.numeros;
}
private boolean isNumeroValido(int nums){
if (nums>=1 && nums<=50)
return true;
return false;
}
private boolean isEstrelaValida(int ests){
if (ests>=1 && ests<=9)
return true;
return false;
}
public boolean isNumeroRepetido(int numeros[]){
for (int i = 0; i < numeros.length; i++){
if (numeros[i]==numeros[i])
return true;
}
return false;
}
public boolean isEstrelaRepetida(int estrelas[]){
for ( int i = 0; i < estrelas.length; i++){
if (estrelas[i]==estrelas[i])
return true;
}
return false;
}
public boolean isChaveValida(int numeros[],int estrelas[] ){
int nums = 0;
int ests = 0;
if(numeros==null)
return false;
if( isNumeroRepetido(numeros))
return false;
if(!isNumeroValido(nums))
return false;
if(estrelas==null)
return false;
if( isEstrelaRepetida(estrelas))
return false;
if(!isEstrelaValida(ests))
return false;
else
return true;
}
}
[code]
/__________________________________________________________________/
e depois nesta classe sorteio
[code]public class Sorteio {
/**
* Pre�o de uma aposta.
*/
public static final float PRECO_REGISTO_APOSTA = 2.0f;
/**
* Percentagem da receita a ser distribuida pelos pr�mios.
*/
public static final float PERCENTAGEM_PARA_PREMIOS = 0.9f;
/**
* Constante com a tabela de pr�mios disponiveis em fun��o da quantidade de
* numeros e estrelas acertadas.
*/
public static final Premio[] PREMIOS = {new Premio(1, 5, 2, 0.5000f),
new Premio(2, 5, 1, 0.2000f),
new Premio(3, 5, 0, 0.800f),
new Premio(4, 4, 2, 0.600f),
new Premio(5, 4, 1, 0.500f),
new Premio(6, 4, 0, 0.400f),
new Premio(7, 3, 2, 0.300f),
new Premio(8, 3, 1, 0.200f),
new Premio(9, 2, 2, 0.100f),
new Premio(10, 3, 0, 0.050f),
new Premio(11, 1, 2, 0.030f),
new Premio(12, 2, 1, 0.020f)};
/**
* Indica a data em que o sorteio foi realizado.
*/
private java.util.Calendar dataSorteio;
/**
* Numero de registos de apostas ate ao momento.
*/
private int nrRegistos = 0;
/**
* Indica se o sorteio foi ou n�o realizado.
*/
private boolean realizado = false;
public Chave chave;
/**
* Indica qual a combina��o de n�meros e estrelas correspondentes ao primeiro
* pr�mio atribu�do.
*/
private Premio primeiroPremio;
/**
* Cont�m as apostas realizadas para o presente sorteio.
*/
private Aposta lances[];
private Chave chaveVencedora;
/**
* Efectua a gera��o de uma chave com os numeros e estrelas fornecidos. Nao podera
* haver repeti�oes de numeros e/ou de estrelas. Devera ser sempre validado se as
* chaves introduzidas/geradas sao validas. Os numeros variam entre 1 e 50. As
* estrelas variam entre 1 e 9 (limites incluidos).
*
* @param numeros
* @param estrelas estrelas
*/
public static Chave gerarChave(byte[] numeros, byte[] estrelas) {
return null;
}
/**
*
* @param chave chave
*/
public boolean validarChave(Chave chave) {
if(chave != null)
return false;
return false;
}
// Incluir os métodos seguintes:
// Recebendo os números e estrelas correspondentes à chave
// efectua o calculo e atribuição de prémios pelas apostas
public Chave efectuarSorteio(int[] nums, int[] ests) {
return null;
}
// Devolve a data de sorteio
public Calendar getDataSorteio() {
return this.dataSorteio;
}
// Devolve os lances de apostas existentes
public Aposta[] getLances() {
return this.lances;
}
// Regista uma aposta no array de lances
public void registaAposta(Aposta aposta) {
}
// Devolve o número de apostas efectuadas
public int getNrRegistos() {
return this.nrRegistos;
}
// Devolve o primeiro premio do sorteio
public Premio getPrimeiroPremio() {
return this.primeiroPremio;
}
// Devolve true se o sorteio já se tiver efectuado
public boolean isRealizado() {
return this.realizado;
}
}
// Converter byte par int
public int [] converterByteparaInt(byte[] x) {
if (x==null) return null;
int[] y= new int[x.length];
for(int i=0;i<x.length;i++) {
y[i] = (int) x[i];
}
return y;
}
//converter int para byte
public byte [] converterIntparaByte(int[] x) {
if (x==null) return null;
byte[] y= new byte[x.length];
for(int i=0;i<x.length;i++) {
y[i] = (byte) x[i];
}
return y;
}
}[/code]