I have a problem that I can not solve with a java loop for a class exercise. I need to make a program that asks 10 questions of random multiplication tables. At the end of the 10 questions, it have to show me the questions that were right the first time. In case a question is not right the first time, it must show the table of the failed number and then reformulate the question.
The flaw I have is that within the for of the 10 questions I have an if -else for the right questions and inside the else the do-while to reformulate the questions. The problem is when I fail the question, the program reformulates it as it should do but if I enter the correct answer, the do-while loop closes the for and stops asking questions.
The use of arrays is banned in the exercise.
Here is the code:
for (int i=1; i<=10; i++) {
Tablas operacion=new Tablas();
int pregunta = Integer.parseInt(JOptionPane.showInputDialog(null, operacion.getNumeroPregunta()+"\n"+operacion.multiplicacion()));
if (pregunta == operacion.resultado()) {
Tablas.comprobadorPreguntas(true);
}
else {
do {
String salida="";
for (i=1; i<=10; i++) {
salida+=operacion.getMultiplicando() + "x"+i+"=" + (operacion.getMultiplicando() * i) + "\n";
}
JOptionPane.showMessageDialog(null, salida);
pregunta = Integer.parseInt(JOptionPane.showInputDialog(null, operacion.getNumeroPregunta()+"\n"+operacion.multiplicacion()));
} while(pregunta != operacion.resultado());
Tablas.comprobadorPreguntas(false);
}
}
JOptionPane.showMessageDialog( null, "Preguntas acertadas a la primera: "+Tablas.getContador());
Here are also the classes in pastebin:
Program > http://ift.tt/2ibMKYy
Methods > http://ift.tt/2jGrqee
Aucun commentaire:
Enregistrer un commentaire