
ayuda con mi codigo
Publicado por alejandro (4 intervenciones) el 23/06/2015 21:16:11
hola necesito soy nuevo en el foro y necesito ayuda estoy haciendo un programa de preguntas y respuestas en java.
tengo muy pocos conocimientos en java pero logre hacer este codigo viendo videos leyendo un poco y copiando tambien un poko de otros. no entiendo que esta mal por que coloco preguntas con opciones multiples y siempre que contesto correctas las preguntas hay algunas que salen incorrectas pongo mi codigo con ejemplos para que me ayuden gracias.
tengo muy pocos conocimientos en java pero logre hacer este codigo viendo videos leyendo un poco y copiando tambien un poko de otros. no entiendo que esta mal por que coloco preguntas con opciones multiples y siempre que contesto correctas las preguntas hay algunas que salen incorrectas pongo mi codigo con ejemplos para que me ayuden gracias.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package ejemplos;
import javax.swing.*;
public class ejemplo {
public static void main(String args[])
{
/***Declarando Listado de Preguntas**/
String pregunta1="¿como se dice azul en ingles?";
String respuesta_1_1="blue";
String respuesta_1_2="bluu";
int opcion_correcta1=1;
String pregunta2="¿como se escribe arroz en ingles?";
String respuesta_2_1="ricee";
String respuesta_2_2="rice";
int opcion_correcta2=2;
String pregunta3="¿que numero es seven?";
String respuesta_3_1="7";
String respuesta_3_2="6";
int opcion_correcta3=1;
/************Declaración de Variable para la pregunta actual****************/
String pregunta_actual="";
String respuesta_actual1="";
String respuesta_actual2="";
int opcion_correcta=0;
String respuesta_verificar="";
int inicio=1;
int limite=3;
int ultimo=0;
int opcion_ok=0;
int cant_respuestas_correctas=0;
int cant_respuestas_incorrectas=0;
for(int x=0;x<3;x++)
{
int aleatorio=0;
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;
opcion_ok=opcion_correcta1;
break;
case 2:
pregunta_actual=pregunta2;
respuesta_actual1=respuesta_2_1;
respuesta_actual2=respuesta_2_2;
opcion_ok=opcion_correcta2;
break;
case 3:
pregunta_actual=pregunta3;
respuesta_actual1=respuesta_3_1;
respuesta_actual2=respuesta_3_2;
opcion_ok=opcion_correcta3;
break;
}
respuesta_verificar=JOptionPane.showInputDialog("Pregunta...."+(x+1)+"\n"+pregunta_actual+"\nIngrese su Respuesta:\n1. "+respuesta_actual1+"\n2. "+respuesta_actual2);
opcion_correcta=Integer.parseInt(respuesta_verificar);
if(opcion_correcta1==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


0