
public class BankAccount {
	
	// Fields
	
	// the number of BankAccounts that have ever been created
	private static int count = 0;
	
	//private final double TRANSACTION_FEE = 0.25;
	private double balance;
	
	// Constructors
	
	public BankAccount(double balance) {
		this.balance = balance;
		count++;
	}
	
	public BankAccount() {
		this(0);

		//this.balance = 0;
	}
	
	public BankAccount(BankAccount b) {
		this(b.balance);
		//this.balance = b.balance;
	}
	
	// Methods
	
	public void deposit(double amount) {
		
		if (amount > 0) {
			// this.balance = this.balance - TRANSACTION_FEE;
			this.balance += amount;
		}
	}
	
	public boolean withdraw(double amount) {
		if (this.balance >= amount) {
			// this.balance = this.balance - TRANSACTION_FEE;
			this.balance -= amount;
			return true;
		}
		return false;
	}
	
	public double getBalance() {
		return this.balance;
	}

	public String toString() {
		//Transforms the class into a string of the following form 
		//(for example, if the balance is 10.56): [BankAccount:balance=10.56] 
		String s = "[BankAccount:balance="+this.balance+"]";
		return s;
	}	
	
	public boolean equals(Object o) {
		
		// see if it's null
		if (o == null)
			return false; // this cannot be null
		
		// Since we start with ANY object, we have to see if we can cast it to BankAccount
		if (this.getClass() != o.getClass())
			return false;
		// DO NOT USE instanceof
		
		// if we can cast it, do so
		BankAccount b = (BankAccount)o;
		
		// check to see if the internal state (i.e. balance) is the same
		if (this.balance != b.balance)
			return false;
		
		// if I'm here, it's a BankAccount with the same balance
		return true;
		
		/*if ((o != null)&&(this.getClass()==o.getClass())&&(this.balance == ((BankAccount)o).balance))
			return true;
		return false;*/
	}
	
	public static int numBankAccounts() {
		// returns the number of bank accounts that have ever been created
		//System.out.println(this.balance);
		return count;
	}
	
	
}
