title: How do i pass a specific content of an index of an arraylist to a method?
body: <p>How do i pass a specific content of an index of an arraylist to a method? (i'm not sure of the correct terms)</p>
  <p>This is what i'm trying to achieve:
  Get user input for the amount to withdraw from the first account, then print the balance. Repeat
  the same for deposit.</p>
  <p>This is my class code:</p>
  <pre class="lang-java prettyprint-override"><code>import java.util.Date;
  
  public class Account2 {
      private int id = 0;
      private double balance = 0;
      private static double annualInterestRate = 0;
      private Date dateCreated;
  
      public Account2() {
          id = 0;
          balance = 0;
      }
  
      public Account2(int id, double balance) {
          this.id = id;
          this.balance = balance;
      }
  
      // getters and setters (omitted for brevity)
  
      public double withdraw(int amount) {
          return balance - amount;
      }
  
      public double deposit(int amount) {
          return balance + amount;
      }
  }
  </code></pre>
  <p>This is the Test class:</p>
  <pre class="lang-java prettyprint-override"><code>import java.util.ArrayList;
  import java.util.Scanner;
  
  public class TestAccount2 {
      public static void main(String[] args) {
          //Account2 acc = new Account2();
          Account2.setannualInterestRate(4.5);
          //Creates an ArrayList of 3 Account objects
          ArrayList&lt;Account2&gt; list = new ArrayList&lt;Account2&gt;();
  
          for(int i=1; i&lt;4; i++) {
              //USE ARRAYLIST SYNTAX
              list.add(new Account2(i+100, i*10000 ));
          }
  
          //print all the content of ArrayList
          for(Account2 auto : list) {
              System.out.println(temp);
          }
      
          System.out.println(&quot;Enter the amount you'd like to withdraw: &quot;);
          Scanner input = new Scanner(System.in);
          double amount = amount.nextDouble;
          // Get user input for the amount to withdraw from the first account, then print the balance. 
          // Repeat the same for deposit
      }
  }
  </code></pre>
  <p>This is where i'm stuck:</p>
  <pre class="lang-java prettyprint-override"><code>        System.out.println(&quot;Enter the amount you'd like to withdraw: &quot;);
          Scanner input = new Scanner(System.in);
          double amount = amount.nextDouble;
          // Get user input for the amount to withdraw from the first account, then print the balance. 
          // Repeat the same for deposit
  </code></pre>
  <p>This is the method i'm trying to pass the index of arraylist into:</p>
  <pre class="lang-java prettyprint-override"><code>public double withdraw(int amount) {
      return balance - amount;
  }
  </code></pre>
  <p>thank u.</p>