Advertisement
Guest User

account class

a guest
Feb 19th, 2020
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. package just;
  2.  
  3. public class Account {
  4.  
  5.     private double balance ;
  6.     private static int accounts;
  7.     private int account_no;
  8.     public Account () {
  9.         balance=0;
  10.         account_no = ++accounts;
  11.        
  12.     }
  13.      /***
  14.       * this is b = to intialize the balance of the Account .
  15.       * @param b
  16.       */
  17.     public Account ( double b) {
  18.         balance=b;
  19.         account_no=++accounts;
  20.        
  21.     }
  22.     /***
  23.      *
  24.      * @param b : to set a new balance to the Account .
  25.      */
  26.    
  27.     public void setbalance(double b) {
  28.         balance=b;
  29.     }
  30.    
  31.     /**
  32.      *
  33.      * @return the balance of the Account .
  34.      */
  35.     public double getbalance() {
  36.         return balance;
  37.     }
  38.     /**
  39.      * returns the number of accounts in the Bank .
  40.      * @return
  41.      */
  42.     public int getno_accounts(){
  43.         return account_no;
  44.     }
  45.     /***
  46.      * to take money from the Account .
  47.      * @param money
  48.      */
  49.     public void withdraw(double money) {//getmoney
  50.         if (money<balance&&money>0)
  51.             balance-=money;
  52.         else {
  53.             System.out.println("sorry you only have "+getbalance());
  54.         }
  55.     }
  56. /**
  57.  *  to add money to the Account .
  58.  * @param money
  59.  */
  60.     public void deposite (double money) {
  61.         balance+=money;
  62.     }
  63.     /**
  64.      * override to To_String fuunction to print the details of the account .
  65.      */
  66.     public String toString () {
  67.         return String.format("The account number is: " + account_no + " \nthe account balance is "+balance);
  68.     }
  69.    
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement