Results 1 to 3 of 3

Thread: Array List

  1. #1
    mprentice84 is offline Member
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Default Array List

    I am working on a bank account program. There is Bank.java, BankAccount.java, and BankTester.java. I am trying to finish up a deposit method in the Bank class but am running into problems when trying to change the current balance to the new one. Here is my code for the method:


    //PART B: Deposit funds
    public void deposit(int accountNumber, double amount)
    {

    BankAccount a = accounts.get(accountNumber);
    double bal = a.getBalance();
    bal = (bal + amount);
    //How do I make bal the current balance for the account??
    }:confused:
    Last edited by mprentice84; 02-19-2009 at 09:37 PM.

  2. #2
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    BankAccount a = accounts.get(accountNumber);
    does get(int) return an instance of BankAccount? And what is "accounts"?... Actually why are you making a new instance of BankAccount at all? Just use the BankAccount that calls the method.
    //How do I make bal the current balance for the account??
    does the Account have a field for its balance? Then you could just do (this.)balanceField = amount + (this.)getBalance;
    where amount is your parameter in the method. I just put (this.) so you know it belongs to the calling Object. Hope that helped.
    -MK12
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    First of all, when you post next time please use an appropriate title in your question. Here your title and the question not make sense.

    If you want to call a method from a class of another what you have to do basically? Create an instance of it. Then call the method. If that methods returns anything you have to store it in a correct data type variable. Do you have a clear idea about that?

Similar Threads

  1. array list help
    By dorno83 in forum New To Java
    Replies: 9
    Last Post: 11-07-2008, 09:56 AM
  2. Array List problem
    By kurenai in forum New To Java
    Replies: 2
    Last Post: 06-25-2008, 07:30 AM
  3. How to convert List to Array
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 10:37 PM
  4. Array List Problem
    By khamuruddeen in forum New To Java
    Replies: 1
    Last Post: 12-22-2007, 08:10 AM
  5. using an Array list
    By toad in forum New To Java
    Replies: 1
    Last Post: 11-18-2007, 09:08 PM

Posting Permissions

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