Java validation with nested loops
<p>The program runs good but the nested do-while loop is not working. If you see the condition of the while you can see that it have to be a validation and if it is not in the range of those numbers it has to ask the questions again. You can see that the principal do- while has to validate that principal is not equal to 0 if it is it goes out from the program</p>

<p>I declare:  </p>

<pre><code>import java.util.Scanner;
import java.text.DecimalFormat;
public class ACMEMORTGAGE
{
   public static void main (String args [])

   {
       //Declare variables 
        double rate=0, monthlyPayments, numberMonthlyPayments, paymentAmount;
        int mortgageTerm, principal, years=0;

        Scanner key=new Scanner(System.in);

        DecimalFormat decimalPlaces=new DecimalFormat("$0.00");
        do
        {
            System.out.print("Enter principal amount (0 to end program):");
            principal=key.nextInt();

            do

            {
            System.out.print("Enter mortgage amortization (1, 2, 3, 5, 10.):");
            mortgageTerm=key.nextInt();

            if (mortgageTerm==1)
            {
                rate=0.035;
            }
            else if (mortgageTerm==2)
            {
                rate=0.039;
            }
            else if (mortgageTerm==3)
            {
               rate=0.044;
            }
            else if (mortgageTerm==5)
            {
               rate=0.05;
            }
             else if (mortgageTerm==10)
            {
                rate=0.060;  
            }


            } while (mortgageTerm==1 || mortgageTerm==2 || mortgageTerm==3 || mortgageTerm==5 || mortgageTerm==10);


            do
           {     
            System.out.print("Enter mortgage ammortization period (5, 10, 15, 20, 25):");
            years=key.nextInt();

           } while (years==5 &amp;&amp; years==10 &amp;&amp; years==15 &amp;&amp; years==20 &amp;&amp; years==25);               

       double i, n, x;

       i=rate/12;
       n=12*years;


       monthlyPayments= ((principal*(Math.pow(i+1, n)*(i))) / (Math.pow(i+1, n) - 1));
       System.out.print("Monthly payments amount:");    
       System.out.println(decimalPlaces.format(monthlyPayments));

     }while (principal!=0);

   }

}
</code></pre>
