title: Java loan calculator
body: <p>I'm trying to code a loan calculator. I seem to be having issues. I am trying to get an input from the user and validate the input. I know I am doing it wrong the problem is I'm scratching my head wondering how to do it right.
  I get a red line on the d = getDouble(sc, prompt); and the i = getInt(sc, prompt); which I understand I don't have that coded correctly. I'm just unsure how to go about fixing it.</p>
  
  <p>I also have to validate the continue statement which I wasn't to sure the best way to go about that and finally the instructor expects the code to be 80 lines or less which I am right about 80 lines. I guess I'm looking for a better way to do this but being new I'm scratching my head and I'm hoping someone can lend a hand.</p>
  
  <p>As always I really appreciate the help.</p>
  
  <pre><code>   import java.util.Scanner;
     import java.text.NumberFormat;
  
      public class LoanCalculator
      {   
          public static double getDoubleWithinRange(Scanner sc, String prompt, double min, double max)
          {
            double d = 0.0;
            boolean isValid = false;
            while(isValid == false);
             {
                  d = getDouble(sc, prompt);
                  if (d &lt;= min)
                     {
                     System.out.println("Error! Number must be greater tha 0.0");
                     }
                     else if (d &gt;= max)
                    {
                       System.out.println("Error number must be less than 1000000.0");
                  }
                  else 
                      isValid = true;
              }
              return d;       
          }
              public static int getIntWithinRange(Scanner sc, String prompt, int min, int max)
          {
              int i = 0;
              boolean isvalid = false;
              while(isvalid == false)
               {
                  i = getInt(sc, prompt);
                  if (i &lt;= min)
                         System.out.println("Error! Number must be more than 0");
                  else if (i &gt;= max)
                      System.out.println("Error! Number must be less than 100");
                  else 
                      isvalid = true;
              }   
          }
            public static void main(String[] args)
           {
              System.out.println("Welcome to the loan calculator");
              Scanner sc = new Scanner(System.in);
              String choice = "y";
              while (choice.equalsIgnoreCase("y"))
              {
                  System.out.println("DATA ENTRY");
                  double loanAmount = getDoubleWithinRange(sc, "Enter loan amount: ", 0.0, 1000000.0);
                  double interestRate = getDoubleWithinRange(sc, "Enter yearly interest rate: ", 0, 20);
                  int years = getIntWithinRange(sc, "Enter number of years: ", 0, 100);
                  int months = years * 12;
  
                  double monthlyPayment = loanAmount * interestRate/
                          (1 - 1/Math.pow(1 + interestRate, months));
  
                  NumberFormat currency = NumberFormat.getCurrencyInstance();
                  NumberFormat percent = NumberFormat.getPercentInstance();
                  percent.setMaximumFractionDigits(3);
                  System.out.println("RESULST");
                  System.out.println("Loan Amount" + currency.format(loanAmount));
                  System.out.println("Yearly interest rate: " + percent.format(interestRate));
                  System.out.println("Number of years: " + years);
                  System.out.println("Monthly payment: " + currency.format(monthlyPayment));
  
                  System.out.println();
                  System.out.println("Continue? (y/n): ");
                  choice =sc.next();
                  System.out.println();
  
              }           
          }
      }
  </code></pre>