I am having a problem with the validation of the account number and password.
The beginning of the program asks for users account # then pwd. The program is then supposed to go to a checkID method that checks the account number and pwd with 3 stored accounts (each account/pwd/balance is stored as one long string) so the checkID method breaks up the string into its seperate parts and then checks if the input matches. If it does match one of the accounts it returns the balance of the account as a string. If not it returns an error string.
My problem is that when I enter a correct account/ pwd it continues the for loop even though the while loop conditions has been met. So, it just keeps asking me to input a account number then password until max attempts has been reached. So either there is a problem in my checkID method or in the if statement that activates the counter for he for-while loop. I just cant seem to spot my error. Here is the main method and checkID method in my program. Can someone help find my error or at least point me in the right directon. -
public class ATM {
-
-
public static Scanner kbd = new Scanner (System.in);
-
-
public static void main(String[] args) {
-
-
int choice, count = 1;
-
double balance;
-
String acctNum, pwd, check;
-
-
do{
-
System.out.print("Enter your account number: ");
-
acctNum = kbd.nextLine();
-
System.out.print("Enter your account's password: ");
-
pwd = kbd.nextLine();
-
-
check = checkID(acctNum, pwd);
-
-
if (check == "error"){
-
System.out.println("\nError: Account number and/or password is incorrect.\n");
-
count++;
-
}
-
}while (count <= 3 && count > 1);
-
-
if (count > 3){
-
System.out.println("\nYou have reached the maximum attempts allowed.");
-
return;
-
}
-
-
else{
-
-
balance = Double.parseDouble(check);
-
choice = menu();
-
if (choice == 0){
-
System.out.print("Error: Select menu item 1-4");
-
choice = menu();}
-
else if (choice == 1)
-
displayBalance(balance);
-
else if (choice == 2)
-
balance = deposit(balance);
-
else if (choice == 3)
-
balance = withdraw(balance);
-
}
-
}
-
-
// The checkID method determines if acctNum is a valid account number
-
// and pwd is the correct password for the account. If the account information
-
// is valid, the method returns the current account balance, as a string.
-
// If the account information is invalid, the method returns the string "error".
-
-
public static String checkID(String acctNum, String pwd){
-
-
String result = "error";
-
-
// Strings a, b, and c contain the valid account numbers and passwords.
-
// For each string, the account number is listed first, followed by
-
// a space, followed by the password for the account, followed by a space,
-
// followed by the current balance.
-
-
String a = "44567-5 mypassword 520.36";
-
String b = "1234567-6 anotherpassword 48.20";
-
String c = "4321-0 betterpassword 96.74";
-
-
// insert code here to determine if acctNum is a valid account number
-
// and pwd is the correct password for the account.
-
String acctnumA, acctnumB, acctnumC, pwdA, pwdB, pwdC;
-
-
acctnumA = a.substring(0, a.indexOf(' '));
-
pwdA = a.substring(a.indexOf(' ')+1, a.lastIndexOf(' '));
-
acctnumB = b.substring(0, b.indexOf(' '));
-
pwdB = b.substring(b.indexOf(' ')+1, b.lastIndexOf(' '));
-
acctnumC = c.substring(0, c.indexOf(' '));
-
pwdC = c.substring(c.indexOf(' ')+1, c.lastIndexOf(' '));
-
-
if (acctnumA == acctNum && pwdA == pwd){
-
return a.substring(a.lastIndexOf(' ')+1);
-
} else if (acctnumB == acctNum && pwdB == pwd){
-
return b.substring(b.lastIndexOf(' ')+1);
-
} else if (acctnumC == acctNum && pwdC == pwd){
-
return c.substring(c.lastIndexOf(' ')+1);
-
} else {
-
return result;}
-
}
-
2 7612
I said for loop up there a few times i meant do-while...sorry
Do not compare strings using == . Use the .equals method instead.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Anand |
last post by:
Hi i am having trouble adding a recordset into the access database,
the code seems to be working fine it passs and parses through all
variables just fine without showing any errors and also when i access
the recordset it displays the results, what the real issue is that the
entry is not made into the database even though i use the Update...
|
by: ed |
last post by:
i'm having trouble with a form. I want to be able to type in the address of
the form with the data for the form items in the URL (ie:
http://somesite.com/formpage.html?field1=data1&field2=data2).
It saves the data if I type it in manually to an html file. But it won't do
that if I use the URL notation above. How do I get it to do this. ...
|
by: Lauren Wilson |
last post by:
I'm having trouble with the Access VBA help on my installation of A2K
with Dev tools. Every time I try to retrieve help for items listed in
the Object Browser (and SOME other items as well), Access tells me
that the "feature is broken" and prompts me to repair it. When I do
so, it goes through the motions but does NOT repair the help files....
|
by: Jozef |
last post by:
Hello,
I am trying to put together a module and open a workspace on a database that
has a simple password (using Access XP). This is the lin that I'm having
trouble with;
Set wrk = CreateWorkspace("TestWrkspc", "Admin", conDbPwd)
conDBPwd is a variable that contains the password. There is no independant
workgroup file, just the...
|
by: Jozef |
last post by:
Hello,
I'm having trouble with the download links on my web server. The error I'm
getting is;
CGI Timeout
The specified CGI application exceeded the allowed time for processing. The
server has deleted the process.
It's a fresh Windows 2000 server install, but I also installed the ASP.net
| |
by: Jozef |
last post by:
Hello.
I'm having trouble creating a blank solution (and ASP.net web application)
from my laptop. I own the server (in fact it's sitting right next to me)
and have added the URL to the trusted sites on my laptop. Here are the
details;
This is what I'm selecting from the start page....
>Add New Blank Solution
>Visual Basic Projects,
|
by: MLH |
last post by:
Am having trouble with the filter property setting below.
Would like to filter the listing to car makes beginning
with "D". I'm blowing it on the filter spec somehow???
Sub OpenRecordsetX()
Dim MyDB As Database
Dim rstTemp As Recordset
Dim rstTemp2 As Recordset
Set MyDB = CurrentDb()
|
by: tkondal |
last post by:
Hi all.
I just started looking at Python's ctypes lib and I am having trouble
using it for a function.
For starters, here's my Python code:
from ctypes import*;
myStringDLL= cdll.LoadLibrary("myStringDLL.dll");
|
by: Stu |
last post by:
Hi guys,
I've been having trouble getting the clock function to work portably,
please could I get some thoughts?
<Possibly OT comments>
It works fine on my laptop (under WinXP) and on my office computer
(under Linux), but I have to write some code for the system simulator
for the Cell BE processor (the thing inside the PS3), which is...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |