I've created a random question generator. All questions are in the form: x=3/random number. The problem is that the program never recognizes the fact that the user's answer is correct. I've made it print out the answer and copy it into the answer input (text pane), yet it always prints out "wrong."
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//Generates random value for n (2 decimal plcae)
double nMin = 1.0;//minimum
double nMax = 38.6;//maximum
Random rn = new Random();
double nRand = nMin + (nMax - nMin) * rn.nextDouble();
//Calculates corresponding value of v
String x = String.format("%.2f", 3/nRand );
double nAns = Double.parseDouble(x);//corresponding value of c
check.setText(x);
//displays question
question.setText("n = " + String.format( "%.2f", nRand ) + " v = ?");//question
String answer = answerInput.getText();
Double nUserA = Double.parseDouble(answer);
//checks user's answer
if(x.equals(answer)) {
check.setText("correct");
}
else
check.setText("wrong");
}