Created
October 22, 2022 06:32
-
-
Save CoderNamedHendrick/0aa0d045a9bb90d8b22815e4da0e2edd to your computer and use it in GitHub Desktop.
Zuri Account Challange
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
final userAccount = | |
Account(accountName: 'Femi Adebayo', accountNumber: '1011234355'); | |
userAccount.deposit(20000); | |
print('Account Balance: ${userAccount.availableBalance}\n'); | |
userAccount.withdraw(4000); | |
print('Account Balance: ${userAccount.availableBalance}\n'); | |
userAccount.deposit(1000); | |
print('\n $userAccount'); | |
} | |
class Account { | |
final String _accountName; | |
final String _accountNumber; | |
double _accountBalance; | |
Account({ | |
required String accountName, | |
required String accountNumber, | |
double openingBalance = 0.0, | |
}) : _accountName = accountName, | |
_accountNumber = accountNumber, | |
_accountBalance = openingBalance; | |
@override | |
String toString() { | |
return ''' | |
Account Info Table | |
------------------------------ | |
Account Name ::::: $_accountName | |
Account Number ::: $_accountNumber | |
Account Balance :: $availableBalance | |
'''; | |
} | |
double get availableBalance => _accountBalance; | |
void deposit(double amount) { | |
_accountBalance += amount; | |
print('$amount deposited successfully!'); | |
} | |
void withdraw(double amount) { | |
if (amount > availableBalance) { | |
print('Insufficient Funds'); | |
return; | |
} | |
_accountBalance -= amount; | |
print('$amount withdrawn successfully!'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment