Last questions: Mastermind Java program
<p>I have two questions regarding my code. </p>

<ol>
<li><p>Why does is the output "Oops please enter a number between 1 and 6" when I enter a number between 1 and 6. When I try to be more specific and make an else if statement, nothing happens when I enter a number NOT between 1 and 6.</p></li>
<li><p>How do I restart my program? In my code, there is an if statement
when the user inputs "play again" My commented out line reads
<code>Mastermind.main()</code> to re run the program, but that didn't work.</p></li>
</ol>

<p>Here is the code: </p>

<pre><code>import java.util.Scanner;

public class Mastermind {

    public static void main (String [] args) {
        // boolean variable to signal when the game is over.
        boolean done = false;

        // Scanner object
        Scanner scanner = new Scanner(System.in);

        // sets the value to twelve outside the loop so it doesn't set back each time.
        int guesses = 12;

       System.out.println("Please enter a number between 1-6 to begin (or \"quit\") to exit.");

        // while loop for the game
        while (!done) {

            //System.out.println("Please enter a number between 1-6  (or \"quit\") to exit the game:");

            // user input
            String input = scanner.nextLine();
            int number = 0; //Just initialized to some number


            // checks to see if the user wants to quit the game.
            if (input.equalsIgnoreCase("quit")) {
                System.out.println("Goodbye!");
                done = true;
                scanner.close();
            }

            else{

                try{
                    //Trying to see if the input was a number
                    number = Integer.parseInt(input);


                }
                catch(Exception e){
                    //The input wasn't an integer, it's invalid the starts loop again.
                    System.out.println("Invalid input.");
                    continue;
                }
            }

            // defines necessary int variables
            int random1 = (int) (Math.random() * 7);
            int random2 = (int) (Math.random() * 7);
            int random3 = (int) (Math.random() * 7);
            int random4 = (int) (Math.random() * 7);

           // If the user doesn't and decides to play, it runs this code.
            // checks to see if the user enters a number between 1-6
            if (number &gt;= 1 &amp;&amp; number &lt;= 6) {

                if (number == random1) {
                    System.out.println("You guessed a correct number!");
                   guesses--;
                   System.out.println("guesses = " + guesses);

                }
                else if (number == random2) {
                    System.out.println("You guessed a correct number!");
                    guesses--;
                    System.out.println("guesses = " + guesses);


                }
                else if (number == random3) {
                    System.out.println("You guessed a correct number!");
                    guesses--;
                    System.out.println("guesses = " + guesses);
                }
                else if (number == random4) {
                    System.out.println("You guessed a correct number!");
                    guesses--;
                    System.out.println("guesses = " + guesses);

                }
                else {

                    System.out.println("Sorry that's not one of the numbers! Try again.");
                    guesses--;
                    System.out.println("guesses = " + guesses);
                }
            }


            if (guesses == 0){

                System.out.println("You've run out of guesses. To play again, enter \"play again\". Otherwise, enter or \"quit\")");
                if (input.equalsIgnoreCase("play again")){
                    // how do I restart the program?
                    //Mastermind.main(); // QUESTION 2
                }
                else if (input.equalsIgnoreCase("quit")){
                    System.out.println("Goodbye!");
                    done = true;
                    scanner.close();
                }
                else {
                    System.out.println("Goodbye!");
                    done = true;
                    scanner.close();
                }
            }
            else { //QUESTION 1

                System.out.println("Oops! Please choose a number between 1 and 6");
            }
        }
    }
}
</code></pre>