|
¿Cómo hago para que mi programa (juego de Lotería)
|
|
Estoy intentando escribir un programa de lotería (basado en un juego húngaro, 5 números del 1 al 90), funciona casi bien, la primera vez que le doy números incorrectos (más de 90 o 0) me dice que lo hice mal. . Pero la segunda vez no es así he vuelto a verificar los resultados de Estoy intentando escribir un programa de lotería (basado en un juego húngaro, 5 números del 1 al 90), funciona casi bien, la primera vez que le doy números incorrectos (más de 90 o 0) me dice que lo hice mal. . Pero la segunda vez no es así he vuelto a verificar los resultados de https://loteriasdehoycolombia.co/. Continúa ejecutando el juego con los números no válidos. ¿Cuáles fueron sus consejos y qué harían ustedes de manera diferente? Gracias por tu tiempo. El código:. Continúa ejecutando el juego con los números no válidos. ¿Cuáles fueron sus consejos y qué harían ustedes de manera diferente? Gracias por tu tiempo. El código: import java.util.*; class Lottery { static int hits = 0; Integer[] tippek = new Integer[5]; Random rand = new Random(); ArrayList static Lottery lot = new Lottery(); public static void main (String[] args){ lot.wnums(); lot.tipread(); lot.tipcheck(); lot.wincheck(); lot.result(); } public void wnums () { // GENERATING THE WINNER NUMBERS Set for(int i = 0; set.size() < 5; i++){ int x = rand.nextInt(90) + 1; set.add(x); } nums.addAll(set); } public void tipread (){ // READING THE TIPS System.out.println(\"Please write 5 different number from 1 to 90.\"); try{ Scanner scan = new Scanner(System.in); tippek[0] = scan.nextInt(); tippek[1] = scan.nextInt(); tippek[2] = scan.nextInt(); tippek[3] = scan.nextInt(); tippek[4] = scan.nextInt(); }catch (InputMismatchException ex){ System.out.println(\"Error.\"); } } public void tipcheck() { int fault = 0; List try{ for(int tipp : tippek){ System.out.println(tipp); if(tipp == 0 || tipp > 90){ fault++; } } if(fault == 1){ System.out.println(\"One of your tips is invalid \"); System.out.println(\"Write other numbers\"); lot.tipread(); } if(fault > 1){ System.out.println(fault + \" of your tips are invalid \"); System.out.println(\"Write other numbers\"); lot.tipread(); } for(int tipp : tips){ for(int i = 0; i < tips.size(); i++){ if(tips.indexOf(tips.get(i)) != tips.lastIndexOf(tips.get(i))){ System.out.println(\"You can write a number only once\"); lot.tipread(); } } } }catch (NullPointerException ex){ System.out.println(\"Error.\"); } } public void wincheck () { // CHECKING THE TIPS try{ for(int tipp : tippek){ for(int i = 0; i < 5; i++){ if(nums.get(i) == tipp){ hits++; } } } }catch(Exception ex){ System.out.println(\" \"); } } public void result() { try{ Arrays.sort(tippek); Collections.sort(nums); String tippeksor = Arrays.toString(tippek); System.out.println(\"Your tips in ascending order: \" + tippeksor); System.out.println(\"You have \" + hits + \" hits.\"); System.out.println(\"The winning numbers are: \" + nums); }catch(Exception ex){ lot.tipread(); } } } |