while & do-while loop with users decision to run program again
<p>I have a problem with my restaurant assignment - I'm required to </p>

<ol>
<li><p>Create a while loop with a required quantity that user purchases to be between 1 and 15. User has 3 attempts and if after the third time he doesn't put the right quantity 1</li>
<li><p>Using a do- while loop user has to answer if he wants to run a program again. If he answers 'Y' (for yes) it runs again, if the answer is 'N' (for no ) it terminates. </p></li>
</ol>

<p>I keep getting errors: the while loop does only 2 attempts, and the do while doesn't work at all. </p>

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

    public class newone {
       public static void main (String[] args){
         char repeat;             
         // To hold 'y' or 'n'      
         String input;      

        DecimalFormat df = new DecimalFormat("$0.00");
        //to use: df.format(doubleVariable)

        //Display any welcome message at the top of the output screen
        System.out.println("Welcome!");

        double price = 5.0;
        System.out.println("Burger is " + df.format(price));

        Scanner keyboard = new Scanner(System.in); 

            int attempts = 0;
            int maxAttempts = 3;
            int quantity;

            System.out.print("Enter amount of burgers: ");

            quantity = keyboard.nextInt();
        //LESS THAN OR EQUAL TO 3... 
        while(quantity &lt;1 || quantity &gt;=15 &amp;&amp; attempts&lt;=maxAttempts){

            if(quantity &lt; 1 || quantity &gt;= 15){

                System.out.println("That is an invalid amount, please try  again");
                    quantity= keyboard.nextInt();
                    ++attempts;
                    }
                    else if(quantity&gt;1 &amp;&amp; quantity&lt;15){

                //user entered a valid amount  
                System.out.println("The amount is valid. You ordered: "+ quantity);
                double subTotal = quantity * price;
            }

            while (attempts&gt;=maxAttempts){
                System.out.println("Too many attempts, you can't order");
                break;
                }
            }

         do{ 
     System.out.println("Would you like to run the program again?");        
     System.out.print("Enter Y for yes or N for no: "); 
     input = keyboard.nextLine();    // Read a line.     
     repeat = input.charAt(0);       // Get the first char.   
     } 
//it gives me an error Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    at java.lang.String.charAt(Unknown Source)

     while (repeat == 'Y' || repeat == 'y'); 



            }
        }}
</code></pre>