Greenfoot / Java - incompatible types: boolean cannot be converted to int

the new user is here ... and I feel my code is wrong.

I would like to ask for help since I'm relatively new to Greenfoot. The problem is as stated in the question: I get an "incompatible type" error when compiling my code, and I cannot fix it regardless of any changes I make. The specific part of the code where the problem is located is as follows:

        public void answerValidation()
      {
          int ansCorrect = 0;
          int ansIncorrect = 0;

          for(int i = 0; i <= 10; i++)
          {
              answerArray[0] = array1[0] * array2[0];
              if(answer != answerArray[0])
              {
                  ansIncorrect = ansIncorrect + 1;
                  JOptionPane.showMessageDialog(null, array1[0] + "*" + array2[0] + "=" + answerArray[0]);
              }
              else
              {
                  ansCorrect = ansCorrect + 1;
              }
          }

      switch(ansCorrect)
      {
          case 10:  JOptionPane.showMessageDialog(null, "Wow! You got all the questions right!");
                    break;

          case ansCorrect>=8 && ansCorrect < 9:    JOptionPane.showMessageDialog(null, "You scored" + ansCorrect + "out of 10. 80%-90% scored.");
                    break;

          case ansCorrect >=6 && ansCorrect < 7:   JOptionPane.showMessageDialog(null, "You scored" + ansCorrect + "out of 10. Keep practicing in Lv2 to improve.");
                    break;

          case ansCorrect == 0 && ansCorrect < 6:   JOptionPane.showMessageDialog(null, "You scored" + ansCorrect + "out of 10. Keep practicing in Lv1 to improve.");
                    break;
      }

}

The compilation error indicates that it is where it says "& & ansCorrect <9", although I do not know how to fix it.

Any corrections / requests to see my code are welcome, and thanks very much to those who help!

+4
3
case ansCorrect>=8 && ansCorrect < 9: 

param int wnere case ansCorrect>=8 && ansCorrect < 9:, .

ansCorrect>=8 && ansCorrect < 9

case 8?? case ansCorrect >=6 && ansCorrect < 7:, case 6.

case ansCorrect == 0 && ansCorrect < 6

case 0;
case 1;
case 2;
case 3;
case 4;
case 5;
JOptionPane.showMessageDialog(null, "You scored" + ansCorrect + "out of 10. Keep practicing in Lv1 to improve.");
break;
+2

case. if, , .

+2

case:. :

 if(ansCorrect>=8 && ansCorrect < 9){
    JOptionPane.showMessageDialog(null, "You scored" + ansCorrect + "out of 10. 80%-90% scored.");
    }

- : ansCorrect = ansCorrect + 1 ansCorrect++

: , , case , , - double, . 5.15 5

+1

Source: https://habr.com/ru/post/1606919/


All Articles