Created
February 20, 2018 06:31
-
-
Save parzibyte/0bb844f2bfa304cf0d27e85e7f7bdeb6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class CuestionarioParzibyte { | |
public static void main(String[] args) { | |
Pregunta[] preguntas = { | |
new Pregunta("Creador de PHP", new Respuesta[] { | |
new Respuesta("Bill Gates", 'A', false), | |
new Respuesta("Steve Jobs", 'B', false), | |
new Respuesta("Rasmus Lerdorf", 'C', true) | |
}), | |
new Pregunta("NetBeans es un lenguaje de programacion", new Respuesta[] { | |
new Respuesta("Verdadero", 'A', false), | |
new Respuesta("Falso", 'B', true), | |
}), | |
new Pregunta("Funcion Javascript para decodificar una cadena JSON", new Respuesta[] { | |
new Respuesta("json_decode", 'A', false), | |
new Respuesta("eval", 'B', false), | |
new Respuesta("JSON.parse", 'C', true), | |
new Respuesta("JSON.decode", 'D', false), | |
}), | |
new Pregunta("Javascript es lo mismo que Java", new Respuesta[] { | |
new Respuesta("Verdadero", 'A', false), | |
new Respuesta("Falso", 'B', true), | |
}), | |
new Pregunta("En Javascript no necesitamos punto y coma", new Respuesta[] { | |
new Respuesta("Verdadero", 'A', false), | |
new Respuesta("Falso", 'B', true), | |
}), | |
new Pregunta("jQuery es un lenguaje de programacion", new Respuesta[] { | |
new Respuesta("Verdadero", 'A', false), | |
new Respuesta("Falso", 'B', true), | |
}) | |
}; | |
for (Pregunta p: preguntas) { | |
p.preguntar(); | |
} | |
} | |
} | |
class Pregunta { | |
private String pregunta; | |
private Respuesta[] respuestasPosibles; | |
public Pregunta(String pregunta, Respuesta[] respuestasPosibles) { | |
this.pregunta = pregunta; | |
this.respuestasPosibles = respuestasPosibles; | |
} | |
public void preguntar() { | |
System.out.println(this.pregunta); | |
char letraCorrecta = 'A'; | |
for (Respuesta opcion: this.respuestasPosibles) { | |
if (opcion.esCorrecta()) letraCorrecta = opcion.getLetra(); | |
System.out.print(String.valueOf(opcion.getLetra()) + ")" + opcion.getRespuesta() + " "); | |
} | |
System.out.println("\nElige: "); | |
Scanner sc = new Scanner(System.in); | |
char letraElegidaPorElUsuario = sc.next().toUpperCase().charAt(0); | |
if (letraElegidaPorElUsuario == letraCorrecta) | |
System.out.println("Correcto"); | |
else | |
System.out.println("Incorrecto, la respuesta correcta era " + String.valueOf(letraCorrecta)); | |
} | |
} | |
class Respuesta { | |
private String respuesta; | |
private char letra; | |
private boolean correcta; | |
public Respuesta(String respuesta, char letra, boolean correcta) { | |
this.respuesta = respuesta; | |
this.letra = letra; | |
this.correcta = correcta; | |
} | |
public String getRespuesta() { | |
return this.respuesta; | |
} | |
public char getLetra() { | |
return this.letra; | |
} | |
public boolean esCorrecta() { | |
return this.correcta; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment