-
Notifications
You must be signed in to change notification settings - Fork 0
/
banking.dart
143 lines (132 loc) · 4.03 KB
/
banking.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import 'dart:io';
import 'dart:math';
import 'newfile.dart';
class Bank {
String name;
int accountId;
var balance;
int choice;
var accountsList = [];
Bank(
{required this.name,
required this.accountId,
required this.balance,
required this.choice});
// functions
void bankMenu() {
print("************Menu*************");
print("1:Create a new account here...");
print("2:Creadit to the account here...");
print("3:Debit to the account here...");
print("4:Check balance here by account id...");
print("5:Display All Accounts here...");
print("6:For exit...");
}
// get the user choice here...
void userChoice() {
print("Enter Your choice here...");
choice = int.parse(stdin.readLineSync()!);
}
// if the user choice 1
// Opening the new account process is given below!
void OpenAccount() {
print("Enter the name...");
name = stdin.readLineSync()!;
print("Enter your id...");
accountId = int.parse(stdin.readLineSync()!);
print("Congress ! Your account is created successfully...");
print("Your Balance...");
print("$balance");
print("Your Acount id...");
print(accountId);
accountsList.add(
{"name": name, "accountId": accountId, "balance": balance},
);
print(accountsList);
}
void creaditToAccount() {
print("Please Enter your account id for creating");
var checkID = int.parse(stdin.readLineSync()!);
for (var i = 0; i < accountsList.length; i++) {
if (checkID == accountsList[i]['accountId']) {
print("Enter the ammount here...");
var ammount = int.parse(stdin.readLineSync()!);
accountsList[i]['balance'] = accountsList[i]['balance'] + ammount;
print(accountsList[i]);
return;
}
}
}
void debitFromAccount() {
print("Please Enter your account id for debiting");
var checkID = int.parse(stdin.readLineSync()!);
for (var i = 0; i < accountsList.length; i++) {
if (checkID == accountsList[i]['accountId']) {
print("Enter the ammount here...");
var ammount = int.parse(stdin.readLineSync()!);
if (ammount > accountsList[i]['balance']) {
print("Low balance");
} else {
accountsList[i]['balance'] = accountsList[i]['balance'] - ammount;
print(accountsList[i]['balance']);
}
}
}
}
void checkAccountDetails() {
print("Please Enter your account id for debiting");
var checkID = int.parse(stdin.readLineSync()!);
for (var i = 0; i < accountsList.length; i++) {
if (checkID == accountsList[i]['accountId']) {
if (checkID == accountsList[i]['accountId']) {
print("Your Account Detail");
print("Your Account name");
print(accountsList[i]['name']);
print("Your Account id");
print(accountsList[i]['accountId']);
print("Your Account balance");
print(accountsList[i]['balance']);
}
}
}
}
void allBankAccounts() {
for (var i = 0; i < accountsList.length; i++) {
print("Your Account Detail");
print("Your Account name");
print(accountsList[i]['name']);
print("Your Account id");
print(accountsList[i]['accountId']);
print("Your Account balance");
print(accountsList[i]['balance']);
print("******************************");
}
}
// initial starter of the program here...
void start() {
do {
// because we need this
bankMenu();
userChoice();
switch (choice) {
case 1:
OpenAccount();
break;
case 2:
creaditToAccount();
break;
case 3:
debitFromAccount();
break;
case 4:
checkAccountDetails();
break;
case 5:
allBankAccounts();
break;
default:
print("Bye Bye");
}
} while (choice != 6);
}
}