// Allison Obourn
// CS& 141, Winter 2021
// Lecture 15

// Blueprint for creating objects of type BankAccount
// which represents an person's account at a bank. It keeps 
// track of the account owner, account number and balance.
// Contains a static field that starts at 1000. Every time a bank 
// account is created it gets a unique account number and then this 
// fields value is increased by 1 to be ready to be used for the
// next account.

public class BankAccount {
   private String name;
   private int accountNumber;
   private double balance;
   private static int accountsCreated = 1000;

   
   // Creates a new BankAccount with the passed in information
   public BankAccount(String newName, double newBalance) {
      name = newName;
      accountNumber = accountsCreated;
      accountsCreated++;
      balance = newBalance;
   }
   
   // withdraws the passed in amount of money from the 
   // account as long as this will not overdraw the account
   // (make the balance negative). Returns true if a withdraw was
   // able to be made succesfully and false otherwise.
   public boolean withdraw(double money) {
      if(money <= balance && money >= 0) {
         balance = balance - money;
         return true;
      }
      return false;
   }
   
   // adds the passed in amount of money to the account as long
   // as the amount is a non-negative number. Returns true if it 
   // was able to add successfully, false otherwise.
   boolean deposit(double money) {
      if(money >= 0) {
         balance += money;
         return true;
      }
      return false;
   }
   
   // returns the current account balance
   double getBalance() {
      return balance;
   }
}