Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Shuvo8693/bb395bac1c3d1333f08a42535d370e66 to your computer and use it in GitHub Desktop.
Save Shuvo8693/bb395bac1c3d1333f08a42535d370e66 to your computer and use it in GitHub Desktop.
abstract class on Accountability an Bank Account
abstract class Account{
int accountNumber;
double accountBalance;
Account(this.accountNumber,this.accountBalance);
void deposit(double amount)=> accountBalance += amount;
void withdraw(double amount);
}
class SavingAccount extends Account{
double interestRate;
SavingAccount(int accountNumber, double accountBalance,this.interestRate):super(accountNumber,accountBalance);
@override
void withdraw(double amount) {
accountBalance -= amount;
accountBalance += (accountBalance * interestRate);
print('withdraw $amount tk , & New balance: $accountBalance');
}
}
class CurrentAccount extends Account{
double overDraftLimit;
CurrentAccount(super.accountNumber, super.accountBalance,this.overDraftLimit);
@override
void withdraw(double amount) {
if(amount <= overDraftLimit){
accountBalance -= amount;
print('New Account balance: ${accountBalance.toStringAsPrecision(9)}');
}else{
print('insufficient funds ,Your current balance is ${accountBalance.toStringAsPrecision(9)}');
}
}
}
void main() {
SavingAccount savingAccount=SavingAccount(32165165161, 500000.458, 0.07);
savingAccount.deposit(4000);
savingAccount.withdraw(2000);
CurrentAccount currentAccount=CurrentAccount(32165165161, 150000.336, 60000);
currentAccount.deposit(50000);
currentAccount.withdraw(61000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment