J
Jeff B
Hi everyone,
I am trying to write a program for my assignment, it is a banking program.
I have created an array of accounts, I hard coded the first two accounts
while writing to test program and until i could figure out how to create the
accounts in the program. I figured that out now i am trying to figure out
how to delete (or set to null) one of the accounts. I ask the user what
acount they want to delete and i take that input and run
public void deleteAccount( int userAcct)
{
int usAC = userAcct;
for ( int i = 0; i<accounts.length; i++ )
{
if(accounts!=null)
{
if(usAC== accounts.getAccountNumber())
{
//accounts=null;
System.out.println("account found " + accounts.getAccountNumber());
accounts=null;
break;
}
else
{
System.out.println("account not found ");
}
}
else
{
System.out.println("did not find ");
}
}
}
this works in that it does find the account and sets it to null but it also
deletes all the accounts after the one it finds? All the accounts before
the one it finds is still there but the rest are gone.
Can someone tell me what I am doing wrong?
I attached the one java file that has this code in it in case this snippet
is not enough to go by.
Thanks,
Jeff.
I am trying to write a program for my assignment, it is a banking program.
I have created an array of accounts, I hard coded the first two accounts
while writing to test program and until i could figure out how to create the
accounts in the program. I figured that out now i am trying to figure out
how to delete (or set to null) one of the accounts. I ask the user what
acount they want to delete and i take that input and run
public void deleteAccount( int userAcct)
{
int usAC = userAcct;
for ( int i = 0; i<accounts.length; i++ )
{
if(accounts!=null)
{
if(usAC== accounts.getAccountNumber())
{
//accounts=null;
System.out.println("account found " + accounts.getAccountNumber());
accounts=null;
break;
}
else
{
System.out.println("account not found ");
}
}
else
{
System.out.println("did not find ");
}
}
}
this works in that it does find the account and sets it to null but it also
deletes all the accounts after the one it finds? All the accounts before
the one it finds is still there but the rest are gone.
Can someone tell me what I am doing wrong?
I attached the one java file that has this code in it in case this snippet
is not enough to go by.
Thanks,
Jeff.