title: Trying to translate Javascript to Java - help fix?
body: <p>I'm trying to learn Java, but I'm struggling a little bit. I'm trying to do an assignment from a textbook, so I did it in javascript and was using my limited knowledge of Java to convert it over. (Here's the original instructions - <a href="http://i518.photobucket.com/albums/u341/ACrippledFerret/5ea8ec0e-02aa-4b96-b207-a83c52f8db48_zps2cd2ab7f.jpg" rel="nofollow">http://i518.photobucket.com/albums/u341/ACrippledFerret/5ea8ec0e-02aa-4b96-b207-a83c52f8db48_zps2cd2ab7f.jpg</a>)</p>
  
  <p>I think I've got most of it correct, but I'm running into a couple of errors. Almost all of it is "(variable) cannot be resolved to a variable". It happens to lots of variables in my last method. I also seem to have an issue with a bracket somewhere... "Syntax error on token "}", { expected after this token".</p>
  
  <p>If anyone can help fix this code, I would be very grateful. I am new to Java so this is a bit tough for me to translate. The first set of code is the javascript, the second set of code is my translated java (That's not working). Thanks for any help.</p>
  
  <p>JAVASCRIPT</p>
  
  <pre><code>window.onload=function(){
  var difficulty = 1,
      operators = ['plus', 'minus', 'times', 'divided by'],
      selectedOperator = 1,
      correctAnswers = 0,
      answeredTyped = 0;
  
  var difficultyInput = parseInt(prompt('Please choose the difficulty. Enter the number of digits to use in each problem.'), 10);
  if(difficultyInput &gt; 0) {
      difficulty = difficultyInput;
  }
  
  var arithmeticMethod = parseInt(prompt('Choose an arithmetic problem to study:\n1 = Addition Only\n2 = Subtraction Only\n3 = Multiplication Only\n4 = Division Only\n5 = Random Problems'), 10);
  if(arithmeticMethod == 5 || operators[arithmeticMethod - 1]) {
      selectedOperator = arithmeticMethod;
  }
  
  function checkResponse(primaryInt, secondaryInt, operatorText, suggestedAnswer) {
      var result = false;
      switch (operatorText) {
        case 'plus':
             return (primaryInt + secondaryInt) == suggestedAnswer;
        case 'minus':
             return (primaryInt - secondaryInt) == suggestedAnswer;
        case 'times':
             return (primaryInt * secondaryInt) == suggestedAnswer;
        case 'divided by':
             return (primaryInt / secondaryInt) == suggestedAnswer;
        default:
          return false;
      }
  }
  
  function displayResponse(isCorrect) {
      var randomIndex = Math.floor(Math.random() * (4 - 1 + 1)) + 1;
      switch (randomIndex) {
        case 1:
              return isCorrect ? 'Very good!' : 'No. Please try again.';
        case 2:
              return isCorrect ? 'Excellent!' : 'Wrong. Try once more.';
        case 3:
              return isCorrect ? 'Nice Work!' : 'Don\'t give up!';
        case 4:
              return isCorrect ? 'Keep up the good work!' : 'No. Keep trying.';
        default:
             return 'Woops...';
      }
  }
  
  function askQuestion() {
      var correctAnswer = false;
      var primaryInt = Math.floor(Math.pow(10, difficulty-1) + Math.random() * 9 * Math.pow(10, difficulty-1));
      secondaryInt = Math.floor(Math.pow(10, difficulty-1) + Math.random() * 9 * Math.pow(10, difficulty-1));
      operatorText = (selectedOperator == 5) ? operators[Math.floor(Math.random() * operators.length)] : operators[selectedOperator - 1];
  
      while(!correctAnswer &amp;&amp; answeredTyped &lt; 10) {
          var response = parseFloat(prompt('How much is ' + primaryInt + ' ' + operatorText + ' ' + secondaryInt + '?'));
          correctAnswer = checkResponse(primaryInt, secondaryInt, operatorText, response);
          alert(displayResponse(correctAnswer));
  
          answeredTyped++;
  
          if(correctAnswer)
              correctAnswers++;
      }
  }
  
  while(answeredTyped &lt; 10) {
      askQuestion();
  }
  
  if((correctAnswers / answeredTyped) &gt;= 0.75) {
      alert('Congratulations, you are ready to go on the next level!');
  } else {
      alert('Please ask your teacher for extra help.');
  }
  
  
  }
  </code></pre>
  
  <p>JAVA</p>
  
  <pre><code>import java.util.*;
  import javax.swing.JOptionPane;
  /**
   * 
   */
  
  /**
   * @author Tyler
   *
   */
  public class Assignment2 {
  
      /**
       * @param args
       */
      public static void main(String[] args) {
  // TODO Auto-generated method stub
  Scanner input = new Scanner(System.in);
          int difficulty = 1;
          String[] operators = {"plus", "minus", "times", "divided by"};
          int selectedOperator = 1;
          int correctAnswers = 0;
          int answeredTyped = 0;
  
          int difficultyInput = Integer.parseInt(JOptionPane.showInputDialog("Please choose the difficulty. Enter the number of digits to use in each problem."));
  
  if (difficultyInput &gt; 0) {
      difficulty = difficultyInput;
  }
  int arithmeticMethod = Integer.parseInt(JOptionPane.showInputDialog("Choose an arithmetic problem to study: 1 = Addition Only, 2 = Subtraction Only, 3 = Multiplication Only, 4 = Division Only, 5 = Random Problems" ));
  
      selectedOperator = arithmeticMethod;
  
      }
  
  
  
  
      public static boolean checkResponse (double primaryInt, double secondaryInt, String operatorText, float response){
          boolean result = false;
          switch (operatorText){
          case "1":
              return (primaryInt + secondaryInt) == response;
          case "2":
              return (primaryInt - secondaryInt) == response;
          case "3":
              return (primaryInt * secondaryInt) == response;
          case "4":
              return (primaryInt / secondaryInt) == response;
          }
          return false;
      }
  
  
  
  
      public static String displayResponse (boolean isCorrect){
      int randomIndex = (int) (Math.floor(Math.random() * (4 - 1 + 1)) + 1);
      switch (randomIndex){
      case 1:
          return isCorrect ? "Very Good!" : "No. Please try again.";
      case 2:
          return isCorrect ? "Excellent!" : "Wrong. Try once more.";
      case 3:
          return isCorrect ? "Nice Work!" : "Don\'t give up!";
      case 4:
          return isCorrect ? "Keep up the good work!" : "No. Keep trying.";
      }
      return "Oops...";
  }
  
  
  
  
      public static void askQuestion(int difficulty, String operatorText, int selectedOperator, int answeredTyped, String[] operators, int correctAnswers){
          boolean correctAnswer = false;
          double primaryInt = Math.floor(Math.pow(10,  difficulty-1) + Math.random() * 9 * Math.pow(10,  difficulty-1));
          double secondaryInt = Math.floor(Math.pow(10,  difficulty-1) + Math.random() * 9 * Math.pow(10, difficulty-1));
          operatorText = (selectedOperator == 5) ? operators[(int) Math.floor(Math.random() * operators.length)] : operators[selectedOperator - 1];
  
          while(!correctAnswer &amp;&amp; answeredTyped &lt; 10) {
              float response = Float.parseFloat (JOptionPane.showInputDialog("How much is " + primaryInt + " " + operatorText + " " + secondaryInt + "?")); 
              correctAnswer = checkResponse (primaryInt, secondaryInt, operatorText, response);
              JOptionPane.showMessageDialog(null, displayResponse(correctAnswer));
  
              answeredTyped++;
  
              if(correctAnswer)
                  correctAnswers++;
          }
  
      {
  
      while(answeredTyped &lt; 10){
          askQuestion(0, null, 0, 0, null, 0);
  
      }
  
      if((correctAnswers / answeredTyped) &gt;= 0.75) {
          JOptionPane.showMessageDialog(null, "Congratulations, you are ready to go on to the next level!");
      }
      else{
              JOptionPane.showMessageDialog(null, "Please ask your teacher for extra help.");
      }
  }
  }
  }
  </code></pre>