Results 1 to 5 of 5
Thread: Code not working
- 06-05-2012, 01:38 PM #1
Member
- Join Date
- Jun 2012
- Posts
- 2
- Rep Power
- 0
Code not working
Please check the following code the condition to check invalid attempts only fires once
i.e. it asks to re-enter user name and password only once, I am supposing it to
ask 3/4 times as per my code:
Please helpJava Code:import java.io.Console; public class AtmApp { public static String username; public static String password; public static int invalidAttempts; public static Console console = System.console(); public static void main(String[] args) { invalidAttempts=0; dispLogin(); if(isAuthenticated(username, password)) { System.out.println("Welcome"); } else { invalidAttempts++; if(invalidAttempts==3) { System.out.println("Too many attemps made !"); System.exit(0); } else { System.out.println(""); System.out.println("Invalid id or password try again " + invalidAttempts); dispLogin(); } } } private static boolean isAuthenticated(String username2, String password2) { if(username2.equals("ali") && password2.equals("123")) return true; else return false; } private static void dispLogin() { System.out.print("Enter name: "); username = console.readLine(); password = new String (console.readPassword ("Enter pin: ")); } }Last edited by usman400; 06-05-2012 at 01:44 PM.
- 06-05-2012, 01:46 PM #2
Re: Code not working
Can you post the contents of the console window from when you execute the program? Add comments to the posting that shows what the problem is and explains what is wrong.
Why do you think the code will repeat without a loop?If you don't understand my response, don't ignore it, ask a question.
- 06-05-2012, 08:05 PM #3
Member
- Join Date
- May 2012
- Location
- Dublin
- Posts
- 1
- Rep Power
- 0
Re: Code not working
I'm thinking a do-while loop
- 06-05-2012, 08:21 PM #4
Re: Code not working
Forum Rules -- particularly the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 06-06-2012, 08:55 AM #5
Member
- Join Date
- Jun 2012
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Working On Code
By maximumammo in forum New To JavaReplies: 6Last Post: 04-04-2012, 04:11 PM -
this code is not working I Dont know why ? Public void close the last code!!
By lukote04 in forum New To JavaReplies: 1Last Post: 03-25-2012, 02:40 AM -
\n not working in GUI (working code, but \n isn't working)
By cc11rocks in forum New To JavaReplies: 2Last Post: 01-04-2011, 04:30 AM -
Why is the code not working
By sanox in forum New To JavaReplies: 12Last Post: 09-08-2009, 11:28 AM -
JNI: Why this code not working?
By playwin2 in forum Advanced JavaReplies: 5Last Post: 11-25-2008, 01:12 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks