Reputation: 53
I am writing a loan calculate with data validation. My maximum loan amount is 1,000,000 and I am using the method below to validate. When I enter 1,000,000 into the program it comes back with my error method. I thought (d >= max) would allow me to go up to and including my max. Can anyone see a problem with this method or is it possible I should be looking elsewhere in my code for a problem.
Any help is appreciated.
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 <= min)
{
System.out.println(
"Error! Number must be greater than " + min + "." );
}
else if (d >= max)
{
System.out.println("Error! Number must be less than " + max + "." );
}
else
isValid = true;
}
return d;
//Get input from user System.out.println("DATA ENTRY"); double loanAmount = getDoubleWithinRange (sc, "Enter loan amount: ",0, 1000000); double interestRate = getDoubleWithinRange (sc, "Enter yearly interest rate: " , 0, 20); int years = getIntWithinRange (sc, "Enter number of years: ",0,100);
Upvotes: 1
Views: 478