Closed Thread
Results 1 to 7 of 7

Thread: badly need arraylist help please

  1. #1
    noel's Avatar
    noel is offline Newbie
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    11
    Rep Power
    0

    Angry badly need arraylist help please

    I have a problem trying to understand how to get one out of the arraylist print out
    say this one "noel - 2001 - 5446.0 // is a passbook account " and use it i.e make a deposit
    into it or a withdrawal and then update the record resave it back into the arraylist??

    if you can give me some examples it would be great thank you Noel

    super class is abstract BankAccount.
    SavingAccount extends BankAccount
    their are three children classes
    1.PassBookAccount extends SavingAccount
    2.InvestmentAccount extends SavingAccount
    3.ChequeAccount extends SavingAccount
    this 3 are added to the arraylist as objects using the main contructor parms
    ArrayList<BankAccount> savingAccountList =newArrayList<BankAccount>();

    if(openingDep > 0.01 && CustomerName != "" )
    {
    savingAccountList.add(new PassBookAccount(CustomerName,openingDep));
    System.out.println("Thank Account has been added");

    }

    noel - 2001 - 5446.0 // is a passbook account
    jane - 2002 - 5443.0 // is a passbook account
    null - 1001 - 234434.0 // is a investment account
    bill - 3001 - 345.0 // is a cheque account
    ______________________
    | - PLEASE SELECT - |
    | Enter Number only |
    |_____________________|
    | 0.Quit |
    | 1.Add new account |
    | 2.Withdraw |
    | 3.Deposit |
    | 4.Update overdraft |
    | 5.Add interest |
    | 6.Print balance |
    | 7.Print all |
    | 8.New Customer | // currently used to display arraylist
    |_____________________|

    if (s == 8)
    {
    // using the bankaccount as the super
    for(BankAccount q : savingAccountList)
    {
    System.out.println(q.getAccountName()+ " - " + q.getAccountNumber() + " - " + q.getCurrantBalance());
    }

    }// end if == 8

    }while(s !=0);

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Sinipull's Avatar
    Sinipull is offline Programming Expert
    Join Date
    Jun 2009
    Location
    Tallinn, Estonia, Estonia
    Posts
    382
    Rep Power
    13

    Re: badly need arraylist help please

    does you BankAccount have these methods?

    Code:
    q.getAccountName()+ " - " + q.getAccountNumber() + " - " +  q.getCurrantBalance()
    If not, then you should add them as abstract methods.

  4. #3
    noel's Avatar
    noel is offline Newbie
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    11
    Rep Power
    0

    Re: badly need arraylist help please

    yes it does but i just don't know have to get the right account out of the arraylist and work with it and put it back in the is not a lot about it in books or online. that i could find

  5. #4
    Shaddix's Avatar
    Shaddix is offline Programmer
    Join Date
    Apr 2009
    Location
    Westmalle, Antwerpen, Belgium, Belgium
    Posts
    104
    Rep Power
    11

    Re: badly need arraylist help please

    you'll have to read every object from the arraylist in a loop until you find the object (account) you need
    than you put the object somewhere else, you delete it from the arraylist (using the index you found while searching the object)
    you change the object (withdraw money for example)
    when you're finished you simply add the object back to the arraylist

  6. #5
    noel's Avatar
    noel is offline Newbie
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    11
    Rep Power
    0

    Re: badly need arraylist help please

    thank you for that but could you please give me an example in code (with three values) so i can tranlate it to my script needs as this is the area that i have little knowlege in thank you Noel

  7. #6
    f03nix is offline Newbie
    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0

    Re: badly need arraylist help please

    Whats wrong with
    for(BankAccount q : savingAccountList)
    {
    if(q.getAccountNumber() == 1001) {
    //Change q via any of its methods. ... eg. q.setBalance(2000);
    // break; if required
    }
    }


    I believe as long as its the same object from the arraylist you are modifying ... the changes will be propagated inside arraylist too. It'd be wrong if you do something like ... q = new SavingAccount(1002); and expect the object to be updated inside it.

    Also, i am presuming that BankAccount has all these abstract methods you're calling on the object.

  8. #7
    noel's Avatar
    noel is offline Newbie
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    11
    Rep Power
    0

    Re: badly need arraylist help please

    Thank you all for your help i have worked it out and all is well

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. ArrayList help
    By Ritwik I the programmer in forum Java Help
    Replies: 5
    Last Post: 08-14-2011, 11:42 AM
  2. C++ ArrayList Help
    By reaper in forum C and C++
    Replies: 1
    Last Post: 05-19-2011, 12:45 PM
  3. arrayList help
    By needHelp0611 in forum Java Help
    Replies: 5
    Last Post: 10-13-2010, 09:24 AM
  4. Replies: 3
    Last Post: 01-12-2010, 08:20 AM
  5. Need help with ArrayList...
    By Turk4n in forum Java Help
    Replies: 4
    Last Post: 12-03-2008, 10:14 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts