function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aravind Y BAravind Y B 

Hai Guys,

How to create Bank Class With Deposit And Withdraw Methods?
(i want to Add Min balance Condition in withdraw)
please help me

Thanks 
Best Answer chosen by Aravind Y B
rathinti nagarajurathinti nagaraju
hii aravind !




public class bank {
   

    //Properties
    public String accholdername;
    public String accNumber;
    public String acctype;
    Public string accBranch;
    public Decimal mainBalance;
    public decimal minbalance;
    public Decimal totalaccbal;
    //constutor: 
    public Bank(){
        accholdername = 'naga';
        accNumber = '8758245748';
        acctype = 'Saving';
        accBranch ='atp';
        mainBalance=100000;
        minbalance=10000;
        
        system.debug('accholdername================='+accholdername);
        system.debug('accNumber==========='+accNumber);
        system.debug('acctype========='+acctype);
        system.debug('accBranch==========='+accBranch);
        system.debug('mainBalance========'+mainBalance);
        system.debug('minbalance========'+minbalance);
        
    }
    //Method 
    public Void Deposite(Decimal amount){
        totalaccbal = mainBalance+amount;
        system.debug('==After deposit account balance====='+totalaccbal);
        
    }
    
    
    
    public void withdraw(Decimal withdrawamount){
        
        
        
        if((totalaccbal-withdrawamount)<=minbalance){
            system.debug('Minimum balance is required');
        }
        else{  
            totalaccbal =  totalaccbal- withdrawamount;
            system.debug('After withdraw  acooount balance========='+totalaccbal);
            
        }
        
        
    }
   
}

this the bank class  this is usefull u and others
any errors can best onswer

 


 

All Answers

PriyaPriya (Salesforce Developers) 

Hey Aravind,

Can you please provide all your requirement and how do you want to achieve ? I mean using Visualaforce page + apex class or lightning component?

Regards,

Priya Ranjan

rathinti nagarajurathinti nagaraju
hii aravind !




public class bank {
   

    //Properties
    public String accholdername;
    public String accNumber;
    public String acctype;
    Public string accBranch;
    public Decimal mainBalance;
    public decimal minbalance;
    public Decimal totalaccbal;
    //constutor: 
    public Bank(){
        accholdername = 'naga';
        accNumber = '8758245748';
        acctype = 'Saving';
        accBranch ='atp';
        mainBalance=100000;
        minbalance=10000;
        
        system.debug('accholdername================='+accholdername);
        system.debug('accNumber==========='+accNumber);
        system.debug('acctype========='+acctype);
        system.debug('accBranch==========='+accBranch);
        system.debug('mainBalance========'+mainBalance);
        system.debug('minbalance========'+minbalance);
        
    }
    //Method 
    public Void Deposite(Decimal amount){
        totalaccbal = mainBalance+amount;
        system.debug('==After deposit account balance====='+totalaccbal);
        
    }
    
    
    
    public void withdraw(Decimal withdrawamount){
        
        
        
        if((totalaccbal-withdrawamount)<=minbalance){
            system.debug('Minimum balance is required');
        }
        else{  
            totalaccbal =  totalaccbal- withdrawamount;
            system.debug('After withdraw  acooount balance========='+totalaccbal);
            
        }
        
        
    }
   
}

this the bank class  this is usefull u and others
any errors can best onswer

 


 
This was selected as the best answer