Advertisement
GSculerlor

Account.java

Oct 26th, 2017
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. /**
  2.  * Represents a bank account
  3.  */
  4. public class Account {
  5.     private int accountNumber; // account number
  6.     private int pin; // PIN for authentication
  7.     private double availableBalance; // funds available for withdrawal
  8.     private double totalBalance; // funds available + pending deposits
  9.  
  10.     // Account constructor initializes attributes
  11.     public Account(int theAccountNumber, int thePIN, double theAvailableBalance, double theTotalBalance) {
  12.         accountNumber = theAccountNumber;
  13.         pin = thePIN;
  14.         availableBalance = theAvailableBalance;
  15.         totalBalance = theTotalBalance;
  16.     } // end Account constructor
  17.  
  18.     // determines whether a user-specified PIN matches PIN in Account
  19.     public boolean validatePIN(int userPIN) {
  20.         if (userPIN == pin)
  21.             return true;
  22.         else
  23.             return false;
  24.     } // end method validatePIN
  25.  
  26.     // returns available balance
  27.     public double getAvailableBalance() {
  28.         return availableBalance;
  29.     } // end getAvailableBalance
  30.  
  31.     // returns the total balance
  32.     public double getTotalBalance() {
  33.         return totalBalance;
  34.     } // end method getTotalBalance
  35.  
  36.     // credits an amount to the account
  37.     public void credit(double amount) {
  38.         totalBalance += amount; // add to total balance
  39.     } // end method credit
  40.  
  41.     // debits an amount from the account
  42.     public void debit(double amount) {
  43.         availableBalance -= amount; // subtract from available balance
  44.         totalBalance -= amount; // subtract from total balance
  45.     } // end method debit
  46.  
  47.     // returns account number
  48.     public int getAccountNumber() {
  49.         return accountNumber;
  50.     } // end method getAccountNumber
  51. } // end class Account
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement