Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- A bank account has a balance that can be changed by
- deposits and withdrawals.
- */
- public class BankAccount
- {
- private double balance;
- private int transactions;
- /**
- Constructs a bank account with a zero balance.
- */
- public BankAccount()
- {
- balance = 0;
- transactions = 0;
- }
- /**
- Constructs a bank account with a given balance.
- @param initialBalance the initial balance
- */
- public BankAccount(double initialBalance)
- {
- balance = initialBalance;
- transactions = 0;
- }
- /**
- Deposits money into the bank account.
- @param amount the amount to deposit
- */
- public void deposit(double amount)
- {
- double newBalance = balance + amount;
- balance = newBalance;
- transactions++;
- }
- /**
- Withdraws money from the bank account.
- @param amount the amount to withdraw
- */
- public void withdraw(double amount)
- {
- double newBalance = balance - amount;
- balance = newBalance;
- transactions++;
- }
- /**
- Gets the current balance of the bank account.
- @return the current balance
- */
- public double getBalance()
- {
- return balance;
- }
- /**
- Gets the total number of transactions of the bank account.
- @return the transaction count
- */
- public double getTransactionCount()
- {
- return transactions;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement