Exemplo n.º 1
0
 public String getNextQuestion(int level) {
   int currMax = super.getMaxInt(level, 5);
   type = randomNum.nextInt(6);
   System.out.println("type=" + type);
   String question;
   int correctAnswer = 0;
   int a = randomNum.nextInt(currMax);
   int b = randomNum.nextInt(currMax);
   if (a > b) {
     int temp = a;
     a = b;
     b = temp;
   }
   ++b; // make sure no divide by zero
   if (type == FRACTION_TO_DECIMAL) {
     correctAnswer = ((a * 1000 / b) + 5) / 10;
     question = "what is " + a + "/" + b + " as a decimal (2 decimal places)?";
   } else if (type == FRACTION_TO_PERCENTAGE) {
     correctAnswer = ((a * 1000 / b) + 5) / 10;
     question = "what is " + a + "/" + b + " as a percentage?";
   } else if (type == DECIMAL_TO_PERCENTAGE) {
     correctAnswer = ((a * 1000 / b) + 5) / 10;
     question = "what is " + (correctAnswer / 100.0) + " as a percentage?";
   } else if (type == PERCENTAGE_TO_FRACTION) {
     correctAnswer = ((a * 1000 / b) + 5) / 10;
     question = "what is " + correctAnswer + "% as a fraction (a / b)?";
   } else if (type == DECIMAL_TO_FRACTION) {
     correctAnswer = ((a * 1000 / b) + 5) / 10;
     question = "what is " + (correctAnswer / 100.0) + " as a fraction (a / b)?";
   } else { // percentage to decimal
     correctAnswer = ((a * 1000 / b) + 5) / 10;
     question = "what is " + correctAnswer + "%" + " as a decimal (2 decimal places)?";
   }
   super.setQuestionAnswer(question, correctAnswer);
   return question;
 }