// Tyler Rigsby, CSE 142 // Contains a class that defines a bank account, with the following state: // - id (int) // - name (String) // - balance (double) // - num transactions (int) public class BankAccount { private int id; private String name; private double balance; private int transactionCount; private static int numAccounts = 0; // Initializes a BankAccount object with the specified parameters public BankAccount(String name, double balance) { numAccounts++; this.id = numAccounts; this.name = name; this.balance = balance; this.transactionCount = 0; } // returns the balance of the bank account public double getBalance() { return balance; } // returns a string representation of the account public String toString() { return "account #" + id + ", belongs to: " + name + ", balance: $" + balance + ", num transactions: " + transactionCount; } // takes an amount as a paremeter, and if the amount is greater than 0, adds the amount // to the balance and increments the transaction counter public void deposit(double amount) { if (amount > 0) { balance += amount; transactionCount++; } } // takes an amount as a paremeter and if the amount is greater than 0 but less than or // equal to the balance, decrements the balance by that amount. Otherwise prints an error message public void withdraw(double amount) { if (amount > 0 && amount <= balance) { balance -= amount; transactionCount++; } else { System.out.println("Amount exceeds balance"); } } }