Help adding non repetition.
Ok, im looking for something to add in this code to avoid the cases 0-9 being repeated. Out of the 10 cases I want 5 to happen, and for them to be totally random and different each time. Anyone help me add the missing lines for no-repetition?
Code java:
import javax.swing.JOptionPane;
public class KK
{
public static void main (String arg[])
{
int menu;
menu = Integer.parseInt (JOptionPane.showInputDialog("Seleccione una opcion :\n1. Jugar Trivia.\n2. Salir."));
while(menu<3)
{
switch (menu)
{
case 1:
int repetidor, correctas, preguntas, respuesta;
repetidor= 0;
correctas= 0;
while(repetidor<5)
{
repetidor = repetidor+1;
preguntas= ( int ) ( Math.random() * 10 );
switch (preguntas)
{
case 0:
respuesta =Integer.parseInt (JOptionPane.showInputDialog("blablablalba\n1. La respuesta es 1\n.2. La respuesta es 2\n3. No existe respuesta \n4. Es un numero irreal..."));
switch (respuesta)
{
case 1:
correctas= correctas +1;
break;
default:
correctas= correctas;
break;
} break;
case 1:
respuesta =Integer.parseInt (JOptionPane.showInputDialog(" blablabla = \n1. La respuesta es 4\n.2. La respuesta es 5\n3. No existe respuesta \n4. La respuesta es 33"));
switch (respuesta)
{
case 2:
correctas= correctas +1;
break;
default:
correctas= correctas;
break;
}break;
case 2:
respuesta =Integer.parseInt (JOptionPane.showInputDialog(" blablablabala \n1. La respuesta es 27\n.2. La respuesta es 17\n3. La respuesta es 47 \n4. La respuesta es 57"));
switch (respuesta)
{
case 4:
correctas= correctas +1;
break;
default:
correctas= correctas;
break;
}break;
case 3:
respuesta =Integer.parseInt (JOptionPane.showInputDialog(" blablablablabal\n1. La respuesta es 17\n.2. La respuesta es 82\n3. No existe respuesta \n4. La respuesta es 12."));
switch (respuesta)
{case 4:
correctas= correctas +1;
break;
default:
correctas= correctas;
break;
}break;
case 4:
respuesta =Integer.parseInt (JOptionPane.showInputDialog("blablablabala:\n1. Eds Adventures\n.2. Full Metal Alchemist\n3. ED & EDDE & EDDY\n4. Pokemon"));
switch (respuesta)
{case 2:
correctas= correctas +1;
break;
default:
correctas= correctas;
break;
}break;
case 5:
respuesta =Integer.parseInt (JOptionPane.showInputDialog("blablablabla:\n1. Perro\n.2. Gato\n3. Canario\n4. Pokemon"));
switch (respuesta)
{case 2:
correctas= correctas +1;
break;
default:
correctas= correctas;
break;
}break;
case 6:
respuesta =Integer.parseInt (JOptionPane.showInputDialog("blablabla:\n1. Filosofia\n.2. Arte\n3. Quimica\n4. Danza"));
switch (respuesta)
{case 3:
correctas= correctas +1;
break;
default:
correctas= correctas;
break;
}break;
case 7:
respuesta =Integer.parseInt (JOptionPane.showInputDialog("blablabla:\n1. Soyla\n.2. Alex\n3. Mario\n4. Ese evento no existe...-.-"));
switch (respuesta)
{case 4:
correctas= correctas +1;
break;
default:
correctas= correctas;
break;
}break;
case 8:
respuesta =Integer.parseInt (JOptionPane.showInputDialog("blablabla:\n1. 30%\n.2. 44%\n3. 20%\n4. 25%...-.-"));
switch (respuesta)
{case 4:
correctas= correctas +1;
break;
default:
correctas= correctas;
break;
}break;
case 9:
respuesta =Integer.parseInt (JOptionPane.showInputDialog("25x3 =\n1. 70\n.2. 50\n3. 75\n4. 25"));
switch (respuesta)
{case 3:
correctas= correctas +1;
break;
default:
break;
}break;
}
}
break;
case 2:
System.exit(0);
break;
}
}
}
}
Re: Help adding non repetition.
It would be much easier if you tell us what have to do your code and change that language (spanish?) to english ;)
Re: Help adding non repetition.
Quote:
Out of the 10 cases I want 5 to happen, and for them to be totally random and different each time.
Put the numbers 1 to 10 in a list, shuffle the list and remove and use the first 5.
Re: Help adding non repetition.
Code java:
while
switch
while
switch
switch
When you have this many nested levels you need to:
Review your design. Are you sure that the code is doing what is needed.
Refactor the code. Break it down into smaller parts and move these into their own methods.
Re: Help adding non repetition.
Just spotted this is several places. Completely pointless.