Skip to content

Instantly share code, notes, and snippets.

@dimeprog
Created October 3, 2022 01:33
Show Gist options
  • Save dimeprog/9229aad398cbd3eec431ced756f1d9ab to your computer and use it in GitHub Desktop.
Save dimeprog/9229aad398cbd3eec431ced756f1d9ab to your computer and use it in GitHub Desktop.
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');
}
}
@dimeprog
Copy link
Author

dimeprog commented Oct 3, 2022

my console bank app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment