Java - ayuda !!!! programa sin terminar

 
Vista:
sin imagen de perfil

ayuda !!!! programa sin terminar

Publicado por alejandro (4 intervenciones) el 12/07/2015 14:19:03
buenas soy alejandro soy muy nuevo en java estoy aprendiendo y quisiera utilizar este codigo que es un programa de preguntas con opción multiple pero tengo el siguiente problema utilizo la funcion math.Random y no logro hacer que dejen de repetirse las preguntas me gustaria si alguien puede ayudarme no tengo idea de como hacer para evitar que se repitan las preguntas constantemente.
use este ejemplo que encontre en internet pero no logre conectarlos entre mi codigo y este si alguien puede ayudarme se lo agradesco
ESTE ES EL EJEMPLO
public class lista {

public static void main(String[] args) {
int[] arreglo = new int[20];
int number;

for (int j = 0; j < 20; j++) {
do {
number = (int) (Math.random() * ((20 + 1) - 1));
} while (repetido(number, arreglo));
arreglo[j] = number;

}

}

static boolean repetido(int numero, int[] arreglo) {
boolean rep = false;

for (int i = 0; i < arreglo.length; i++) {
if (arreglo[i] == numero) {
rep = true;
}
}
return rep;
}

}

ACA TERMINA EL EJEMPLO









ESTE ES MI CODIGO

import javax.swing.JOptionPane;

public class tema1 {

private static int opcion_correcta;

public static void main(String args[]){


/***Declarando Listado de Preguntas**/
String pregunta1="";
String respuesta_1_1="";// respuesta correcta
String respuesta_1_2="";
String respuesta_1_3="";
int opcion_correcta1=1;

String pregunta2="¿?";
String respuesta_2_1="";
String respuesta_2_2="";// respuesta correcta
String respuesta_2_3="";
int opcion_correcta2=2;

String pregunta3="¿?";
String respuesta_3_1="";
String respuesta_3_2="";
String respuesta_3_3=""; // respuesta correcta
int opcion_correcta3=3;

String pregunta4="";
String respuesta_4_1="";
String respuesta_4_2="";// respuesta correcta
String respuesta_4_3="";
int opcion_correcta4=2;

String pregunta5="¿?";
String respuesta_5_1=""; // respuesta correcta
String respuesta_5_2="";
String respuesta_5_3="";
int opcion_correcta5=1;

String pregunta6="¿?";
String respuesta_6_1="";
String respuesta_6_2="";
String respuesta_6_3="";// respuesta correcta
int opcion_correcta6=3;

String pregunta7="¿?";
String respuesta_7_1="";// respuesta correcta
String respuesta_7_2="";
String respuesta_7_3="";
int opcion_correcta7=1;

String pregunta8="¿?";
String respuesta_8_1="";
String respuesta_8_2="";
String respuesta_8_3="";// respuesta correcta
int opcion_correcta8=3;

String pregunta9="¿?";
String respuesta_9_1="";
String respuesta_9_2="";// respuesta correcta
String respuesta_9_3="";
int opcion_correcta9=2;

String pregunta10="¿?";
String respuesta_10_1="";
String respuesta_10_2="";
String respuesta_10_3="";// respuesta correcta
int opcion_correcta10=3;

String pregunta11="¿?";
String respuesta_11_1="";
String respuesta_11_2="";// respuesta correcta
String respuesta_11_3="";
int opcion_correcta11=2;

String pregunta12="¿?";
String respuesta_12_1="";// respuesta correcta
String respuesta_12_2="";
String respuesta_12_3="";
int opcion_correcta12=1;

String pregunta13="¿?";
String respuesta_13_1="";
String respuesta_13_2="";// respuesta correcta
String respuesta_13_3="";
int opcion_correcta13=2;

String pregunta14="¿?";
String respuesta_14_1="";
String respuesta_14_2="";
String respuesta_14_3="";// respuesta correcta
int opcion_correcta14=3;

String pregunta15="¿?";
String respuesta_15_1="";
String respuesta_15_2="";// respuesta correcta
String respuesta_15_3="";
int opcion_correcta15=2;

String pregunta16="¿?";
String respuesta_16_1="";// respuesta correcta
String respuesta_16_2="";
String respuesta_16_3="";
int opcion_correcta16=1;

String pregunta17="¿?";
String respuesta_17_1="";
String respuesta_17_2="";
String respuesta_17_3="";// respuesta correcta
int opcion_correcta17=3;

String pregunta18="¿?";
String respuesta_18_1="";
String respuesta_18_2="";// respuesta correcta
String respuesta_18_3="";
int opcion_correcta18=2;

String pregunta19="¿?";
String respuesta_19_1="";// respuesta correcta
String respuesta_19_2="";
String respuesta_19_3="";
int opcion_correcta19=1;

String pregunta20="¿?";
String respuesta_20_1="";
String respuesta_20_2="";
String respuesta_20_3="";// respuesta correcta
int opcion_correcta20=3;

/************Declaración de Variable para la pregunta actual****************/

String pregunta_actual="";
String respuesta_actual1="";
String respuesta_actual2="";
String respuesta_actual3="";
opcion_correcta = 0;
String respuesta_verificar="";

int inicio=1;
int limite=20;
int ultimo=0;
int opcion_ok=0;
int cant_respuestas_correctas=0;
int cant_respuestas_incorrectas=0;

for(int x=0;x<20;x++)
{
int aleatorio=1;
do
{
aleatorio= inicio + (int) (Math.random() * ((limite + 1) - inicio));
}while(ultimo==aleatorio);
ultimo=aleatorio;

switch (aleatorio)
{
case 1:
pregunta_actual=pregunta1;
respuesta_actual1=respuesta_1_1;
respuesta_actual2=respuesta_1_2;
respuesta_actual3=respuesta_1_3;
opcion_ok=opcion_correcta1;
break;

case 2:
pregunta_actual=pregunta2;
respuesta_actual1=respuesta_2_1;
respuesta_actual2=respuesta_2_2;
respuesta_actual3=respuesta_2_3;
opcion_ok=opcion_correcta2;

break;


case 3:
pregunta_actual=pregunta3;
respuesta_actual1=respuesta_3_1;
respuesta_actual2=respuesta_3_2;
respuesta_actual3=respuesta_3_3;
opcion_ok=opcion_correcta3;
break;

case 4:
pregunta_actual=pregunta4;
respuesta_actual1=respuesta_4_1;
respuesta_actual2=respuesta_4_2;
respuesta_actual3=respuesta_4_3;
opcion_ok=opcion_correcta4;
break;

case 5:
pregunta_actual=pregunta5;
respuesta_actual1=respuesta_5_1;
respuesta_actual2=respuesta_5_2;
respuesta_actual3=respuesta_5_3;
opcion_ok=opcion_correcta5;
break;

case 6:
pregunta_actual=pregunta6;
respuesta_actual1=respuesta_6_1;
respuesta_actual2=respuesta_6_2;
respuesta_actual3=respuesta_6_3;
opcion_ok=opcion_correcta6;

break;


case 7:
pregunta_actual=pregunta7;
respuesta_actual1=respuesta_7_1;
respuesta_actual2=respuesta_7_2;
respuesta_actual3=respuesta_7_3;
opcion_ok=opcion_correcta7;
break;

case 8:
pregunta_actual=pregunta8;
respuesta_actual1=respuesta_8_1;
respuesta_actual2=respuesta_8_2;
respuesta_actual3=respuesta_8_3;
opcion_ok=opcion_correcta8;
break;

case 9:
pregunta_actual=pregunta9;
respuesta_actual1=respuesta_9_1;
respuesta_actual2=respuesta_9_2;
respuesta_actual3=respuesta_9_3;
opcion_ok=opcion_correcta9;
break;

case 10:
pregunta_actual=pregunta10;
respuesta_actual1=respuesta_10_1;
respuesta_actual2=respuesta_10_2;
respuesta_actual3=respuesta_10_3;
opcion_ok=opcion_correcta10;

break;


case 11:
pregunta_actual=pregunta11;
respuesta_actual1=respuesta_11_1;
respuesta_actual2=respuesta_11_2;
respuesta_actual3=respuesta_11_3;
opcion_ok=opcion_correcta11;
break;

case 12:
pregunta_actual=pregunta12;
respuesta_actual1=respuesta_12_1;
respuesta_actual2=respuesta_12_2;
respuesta_actual3=respuesta_12_3;
opcion_ok=opcion_correcta12;
break;

case 13:
pregunta_actual=pregunta13;
respuesta_actual1=respuesta_13_1;
respuesta_actual2=respuesta_13_2;
respuesta_actual3=respuesta_13_3;
opcion_ok=opcion_correcta13;
break;

case 14:
pregunta_actual=pregunta14;
respuesta_actual1=respuesta_14_1;
respuesta_actual2=respuesta_14_2;
respuesta_actual3=respuesta_14_3;
opcion_ok=opcion_correcta14;

break;


case 15:
pregunta_actual=pregunta15;
respuesta_actual1=respuesta_15_1;
respuesta_actual2=respuesta_15_2;
respuesta_actual3=respuesta_15_3;
opcion_ok=opcion_correcta15;
break;

case 16:
pregunta_actual=pregunta16;
respuesta_actual1=respuesta_16_1;
respuesta_actual2=respuesta_16_2;
respuesta_actual3=respuesta_16_3;
opcion_ok=opcion_correcta16;
break;

case 17:
pregunta_actual=pregunta17;
respuesta_actual1=respuesta_17_1;
respuesta_actual2=respuesta_17_2;
respuesta_actual3=respuesta_17_3;
opcion_ok=opcion_correcta17;
break;

case 18:
pregunta_actual=pregunta18;
respuesta_actual1=respuesta_18_1;
respuesta_actual2=respuesta_18_2;
respuesta_actual3=respuesta_18_3;
opcion_ok=opcion_correcta18;

break;


case 19:
pregunta_actual=pregunta19;
respuesta_actual1=respuesta_19_1;
respuesta_actual2=respuesta_19_2;
respuesta_actual3=respuesta_19_3;
opcion_ok=opcion_correcta19;
break;

case 20:
pregunta_actual=pregunta20;
respuesta_actual1=respuesta_20_1;
respuesta_actual2=respuesta_20_2;
respuesta_actual3=respuesta_20_3;
opcion_ok=opcion_correcta20;
break;
}

respuesta_verificar=JOptionPane.showInputDialog("Pregunta...."+(+x)+"\n"+pregunta_actual+"\nIngrese su Respuesta:\n1. "+respuesta_actual1+"\n2. "+respuesta_actual2+"\n3"+respuesta_actual3);
opcion_correcta=Integer.parseInt(respuesta_verificar);

if(opcion_correcta==opcion_ok ) {
cant_respuestas_correctas++;
}
else
{
cant_respuestas_incorrectas++;
}
}

JOptionPane.showMessageDialog(null,"Sus Resultados Son"+"\nRespuestas Correctas "+cant_respuestas_correctas+"\nRespuestas Incorrectas "+cant_respuestas_incorrectas);

}


}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder