Help with Array

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.
 
M

Mark Space

Jeff said:
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.


Nope, works ok for me. Why do you think all accounts after that one are
gone? Have you looked at it in a debugger? What IDE do you use?
 
J

Jeff B

Hi Mark,

Thanks for the response. I am using textpad as my editor as it was the one
that i was assigned to use. I have a selection that can be chosen ( 8 ) and
it will display all of the accounts. Not sure if you looked at my java file
that i attached but it is 3 up from where this method is at at the end of
the file called

public void displayAccountList()

i run this after creating a few accounts and all newly created accounts
display but then when i run the option to delete an account it runs, finds
the account that it was suppossed to, but when i run the option to display
all acounts and only the accounts upto that recently deleted account still
remain and all the other accounts that were created after the deleted one
are gone.

I am stumped? I thought that maybe it might have something to do with the
way i generated and assign the account numbers but i do not think that
should be the case as i have a break statement right after it deletes the
account so it should exit and from everything that i can see it seems to.

Any other ideas?
 
M

Mark Space

Jeff said:
Hi Mark,

Thanks for the response. I am using textpad as my editor as it was the
one that i was assigned to use.


Get a real editor. Seriously. You can't program efficiently in Java
with out full support from a modern IDE.

http://www.netbeans.org/downloads/index.html


As for other ideas, I think it has something to do with the way you list
out the accounts. Here's a hint:

What does the break do the first time it encounters a null entry in the
middle of your list?


public void displayAccountList()
{
for ( Account currentAccount : accounts )
{
if(currentAccount != null)
{
System.out.println("Customer Name: " + currentAccount.getfirstName()
+ " " + currentAccount.getlastName() );
System.out.println("Account Number: " +
currentAccount.getAccountNumber());
System.out.println("Account Balance: " + currentAccount.getBalance());
System.out.println(" ");
}
else
{
System.out.println("The End ");
break;
}

}
 
J

Jeff B

Mark,

You are correct I just found that myself, I commented out that break and it
showed the other accounts after. So now what I am trying to find is I have
an option to display an individual account and it is bombing also (which is
why i thought that it was my deleteAccount method) so I am trying to trace
my code now to find that except that i do not have it wrote in the same
place or the sameway. I think for that method there is now something wrong
in the user name validation that i have and that it is hitting the new null
account and breaking.

I really do appreciate your help, and yes i would like to learn how to use
netbeans i have it installed but i am not familiar with how to use it and it
was a requirement to use textpad for the editor. You have to love learning
:)

Jeff
 
A

Arne Vajhøj

Mark said:
Get a real editor. Seriously. You can't program efficiently in Java
with out full support from a modern IDE.

Actually I think we can program efficiently with a standard editor or
with punched cards for that matter.

Characters per second is rarely relevant for software development.

It would just be irritating like hell to have to manually do all the
stuff we know the IDE can do for us.

Pure laziness.

Arne
 
L

Lew

Arne said:
Actually I think we can program efficiently with a standard editor or
with punched cards for that matter.

Characters per second is rarely relevant for software development.

It would just be irritating like hell to have to manually do all the
stuff we know the IDE can do for us.

Pure laziness.

Beyond that, IDEs catch certain problems earlier in the development cycle than
project build. Not only can one often produce code more quickly using an IDE
than with a "standad" editor, or with punched cards for that matter, but with
the IDE's assistance one is likely to leak fewer mistakes into the code
repository.

Beyond even that, IDEs integrate (putting the "I" into "IDE") testing and
debugging. Even if I never used its editor, NetBeans is a great control
console for databases and enterprise servers. As programmers we tend to get
monomania about code production; that is the least of software development
tasks. Deployment, testing and troubleshooting are much larger
considerations. In this area IDEs really shine. Even programmers are able to
be useful with this help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top