Created
October 3, 2022 01:33
-
-
Save dimeprog/9229aad398cbd3eec431ced756f1d9ab to your computer and use it in GitHub Desktop.
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
import 'dart:math'; | |
void main() { | |
// user1 | |
final user1 = TheBank(accountName: 'Dime Dush'); | |
print('accountBalance of ${user1.accountName} is ${user1.accountBalance}'); | |
print('accountNumber of ${user1.accountName} is ${user1.accountNumber}'); | |
user1.deposit(payIn: 2000); | |
print(user1.accountBalance); | |
user1.withdrawal(payOut: 1000); | |
print(user1.accountBalance); | |
user1.displayBalance(); | |
// user2 | |
final user2 = TheBank(accountName: 'Mike Dean'); | |
print('accountBalance of ${user2.accountName} is ${user2.accountBalance}'); | |
print('accountNumber of ${user2.accountName} is ${user2.accountNumber}'); | |
user1.deposit(payIn: 10000); | |
print(user2.accountBalance); | |
user1.withdrawal(payOut: 2000); | |
print(user2.accountBalance); | |
user1.displayBalance(); | |
} | |
class TheBank { | |
final String accountName; | |
int? accountNumber; | |
double? accountBalance; | |
TheBank({ | |
required this.accountName, | |
}) { | |
accountNumber = Random().nextInt(1000000000); | |
accountBalance = 0.0; | |
displayBalance(); | |
} | |
// deposit method use to add money to you balance | |
void deposit({double payIn = 0.0}) { | |
double newBal = payIn + accountBalance!; | |
if (payIn > 0.0) { | |
accountBalance = newBal; | |
print('Money deposited successfully!'); | |
} else { | |
print('Deposit fail. The lowest deposit is 1.0 Naira'); | |
} | |
} | |
void withdrawal({double payOut = 0.0}) { | |
double newBal = accountBalance! - payOut; | |
if (accountBalance! >= payOut && payOut > 0.0) { | |
accountBalance = newBal; | |
print('withdrawal succesful'); | |
} else { | |
print("Insufficient funds!"); | |
} | |
} | |
void displayBalance() { | |
print('Your balance is $accountBalance'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
my console bank app