Skip to main content

data validation



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);


Comments

  1. you are saying if the amount is greater than or equal to one million cause an error. you want to say if it is greater than show an error

    ReplyDelete
  2. Use else if (d>max), since you want up to 1,000,000 (and 1,000,000 can be included).

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?

CCNA 1 Final Exam 2011 latest (hot hot hot)

  Hi! I have been posted content of ccna1 final exam (latest and only question.) I will post the answer and insert image on sunday. If you care, please subscribe your email an become a first person have full test content. Subcribe now  Some question  have not content because this question have images content. So that can you wait for me? SUNDAY 1. A user sees the command prompt: Router(config-if)# . What task can be performed at this mode? Reload the device. Perform basic tests. Configure individual interfaces. Configure individual terminal lines. 2. Refer to the exhibit. Host A attempts to establish a TCP/IP session with host C. During this attempt, a frame was captured with the source MAC address 0050.7320.D632 and the destination MAC address 0030.8517.44C4. The packet inside the captured frame has an IP source address 192.168.7.5, and the destination IP address is 192.168.219.24. At which point in the network was this packet captured? leaving host A leaving ATL leaving...