title: Difficulty with displaying array data in java
body: <p>I am learning java by myself and using the book Java in Two Semesters by Quentin Charatan and Aaron Kans.
  I am currently reading the chapter on Classes and Objects and I am having difficulty solving the last part of an exercise question.
  I have basic knowledge of objects, classes and arrays.
  I have yet to read about collections
  I would be really grateful for some help here. Thanks in advance.</p>
  <p>Ques: Design and implement a program that performs in the following way:</p>
  <ol>
  <li>When the program starts, two bank accounts are created, using names and
  numbers which are written into the code.</li>
  <li>The user is then asked to enter an account number, followed by an amount to
  deposit in that account.</li>
  <li>The balance of the appropriate account is then updated accordingly—or if an
  incorrect account number was entered a message to this effect is displayed.</li>
  <li>The user is then asked if he or she wishes to make more deposits.</li>
  <li>If the user answers does wish to make more deposits, the process continues.</li>
  <li>If the user does not wish to make more deposits, then details of both accounts
  (account number, account name and balance) are displayed</li>
  </ol>
  <p>The authors have provided a BankAccount class file which I have to use to create the bank Accounts and the methods given in the class to deposit and get balance.
  I am providing the code of the my attempt here</p>
  <pre><code>import java.util.Scanner;
   
  public class ProgEx4
  {
  public static void main(String[] args)
    {
        int choice;
        Scanner keyboard = new Scanner(System.in);
      do
      { // Create a MENU system for user to choose options 
        System.out.println();
        System.out.println(&quot;Welcome to Bank Accounts&quot;);
        System.out.println(&quot;MENU&quot;);
        System.out.println(&quot;[1] Deposit Amount&quot;);
        System.out.println(&quot;[2] Exit&quot;);
    
        // User can enter choice here
        System.out.print(&quot;What would you like to do today? : &quot;);
        choice = keyboard.nextInt();
    
        // switch used to process choice entered by user
        switch(choice)
        {
          case 1: deposit(); // this will go to the deposit method 
                  break;
          case 2: break;    // this will exit the program 
          default: System.out.println(&quot;Invalid Choice&quot;); // if user enters an invalid choice this will allow another attempt at entering choice
                   System.out.print(&quot;Please enter a option ( 1 or 2): &quot;);
                   choice = keyboard.nextInt();
        }
        }while(choice != 2); // the loop will go on till user chooses to exit
     }
        static void deposit() // created a method which takes no values and also returns no values
        {
    
        Scanner keyboard = new Scanner(System.in);
        BankAccount[] account = new BankAccount[2];        // created an array account[] using the BankAccount class provided by book
    
        account[0] = new BankAccount(&quot;88&quot;,&quot;John Smith&quot;);   // filled the array as required by the BankAccount class constructor
        account[1] = new BankAccount(&quot;99&quot;,&quot;Robert Jones&quot;); // passing to string values containing account number and account name 
    
        System.out.print(&quot;Enter the account number: &quot;);    // ask user to enter the account number        
        String accNum = keyboard.nextLine();               // declare a String variable 'accNum' to take account number from user
    
        String num0 = account[0].getAccountNumber();       // access the account numbers held in the account array 
        String num1 = account[1].getAccountNumber();       // using two string variables num0 and num1 to hold these strings
    
        if(accNum.equals(num0))                        // compare two strings accNum and num0 to confirm account number entered by user is correct
        {
          System.out.print(&quot;How much would you like to deposit: &quot;);  // user will deposit here
          double depositAmount = keyboard.nextDouble();              // created a double variable depositAmount to take entered amount
    
          account[0].deposit(depositAmount);                         // using BankAccount class deposit method to enter amount into account
          System.out.println(&quot;The current balance is &quot; + account[0].getBalance());  // using BankAccount class getBalance method to get Balance
        }
        else if(accNum.equals(num1))       // same as above for account[0] on line 48 but this time for account[1]
        {
          System.out.print(&quot;How much would you like to deposit: &quot;);
          double depositAmount = keyboard.nextDouble();
          account[1].deposit(depositAmount);
          System.out.println(&quot;The current balance is &quot; + account[1].getBalance());
        }
        }
     /*
        {    
    
          System.out.println(&quot;The Account belonging to &quot; + account[0].getAccountName() + &quot; with Account Number &quot; + account[0].getAccountNumber());
          System.out.println(&quot; has the balance: &quot; + account[0].getBalance());
    
    
          System.out.println(&quot;The Account belonging to &quot; + account[1].getAccountName() + &quot; with Account Number &quot; + account[1].getAccountNumber());
          System.out.println(&quot; has the balance: &quot; + account[1].getBalance());
          
        }
    
        */
    
    }
    
  </code></pre>
  <p>The BankAccount Class file is below</p>
  <pre><code>   
     
     public class BankAccount
     {
     // the attributes
     private String accountNumber;
     private String accountName;
     private double balance;
     
    // the methods
    
    // the constructor
    public BankAccount(String numberIn, String nameIn)
    {
    accountNumber = numberIn;
    accountName = nameIn;
    balance = 0;
    }
    
    // methods to read the attributes
    public String getAccountName()
    {
    return accountName;
    }
    
    public String getAccountNumber()
    {
    return accountNumber;
    }
    
    public double getBalance()
    {
    return balance;
   }
    
    // methods to deposit and withdraw money
    public void deposit(double amountIn)
    {
    balance = balance + amountIn;
    }
    public boolean withdraw(double amountIn)
    {
        if(amountIn &gt; balance)
        {
          return false; // no withdrawal was made
        }
        else
        {
      balance = balance - amountIn;
      return true; // money was withdrawn successfully
    }
      }
    }
    
  </code></pre>
  <p>I do not know how to send the account[] array to get printed in the main method when the user requests to exit the program as I do not know what type of array it is. I wish to know how to send this array to the main method please.</p>