title: How do I keep track of the balance on a bank account?
body: <p>I am going to create a program that keeps track of the balance on a bank account. The program shall use a loop that continues until the user choses to exit by answering <strong><em>no</em></strong> to the question <strong><em>Do you want to continue?</em></strong>.</p>
  
  <p>In the loop the user shall be asked to enter an amount (positive for deposit and negative for withdraw). The amount shall be added/subtracted from an account balance variable. All deposits/withdraws shall be saved as a <em>history</em> so that we can print it later. When the user choses to exit the loop the current account balance together with the account history (from the array/ArrayList) shall be printed.</p>
  
  <p><strong><em>Now, I want to use an array with ten slots for the history feature.</em></strong></p>
  
  <p><strong><em>My question is how can I keep track of the all deposit, withdraw and current account balance (using an array with ten slots for the history feature) so that I can print it out while the user exits the program?</em></strong></p>
  
  <p>My code:</p>
  
  <p>BankApp class:</p>
  
  <pre><code>package bankapp;
  
  import java.util.Scanner;
  
  public class BankApp {
  
      public static void main(String[] args) {
  
          Scanner input = new Scanner(System.in);
          askingUser au = new askingUser();
  
          System.out.println("WELCOME TO OUR BANK!\nYou have 100 SEK by default in your account.");
  
          while (true) {
  
              au.userInput();
  
              System.out.println("Do you want to continue? Answer by Yes or No.");
              String yesOrNo = input.next();
  
              if (yesOrNo.equalsIgnoreCase("yes")) {
  
                  au.userInput();
  
              } else if (yesOrNo.equalsIgnoreCase("no")) {
                  System.out.println("History: ");
  
                  //print out the transaction history
                  System.exit(0);
  
              } else {
  
                  System.out.println("Invalid character input.");
  
              }
  
          }
  
      }
  }
  </code></pre>
  
  <p>askingUser class:</p>
  
  <pre><code>package bankapp;
  
  import java.util.Scanner;
  
  public class askingUser {
  
      Scanner input = new Scanner(System.in);
      double initialBal = 100;
  
      public void userInput() {
          System.out.println("Enter your amount: (+ve for deposit &amp; -ve for withdraw)");
          double inputAmount = input.nextDouble();
  
          if (inputAmount &gt;= 0) {
  
              double newPosAm = initialBal + inputAmount;
              System.out.println("Your current balance is: " + newPosAm + " SEK");
  
          } else {
  
              double newNegAm = initialBal + inputAmount;
              System.out.println("Your current balace is: " + newNegAm + " SEK");
          }
  
      }
  
  }
  </code></pre>