-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBankingApp_BB.java
More file actions
153 lines (137 loc) · 5.1 KB
/
BankingApp_BB.java
File metadata and controls
153 lines (137 loc) · 5.1 KB
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
144
145
146
147
148
149
150
151
152
153
import java.util.*;
class Bankdetails {
String acc;
String name;
String acctype;
long balance;
Scanner sc = new Scanner(System.in);
// this method is for opening new account
void bankDetails() {
System.out.print("Enter Account number: ");
acc = sc.nextLine();
System.out.print("Enter Account Type (Saving | Current ): ");
acctype = sc.nextLine();
System.out.print("Enter Account Holder Name: ");
name = sc.nextLine();
System.out.print("Enter Initial Balance(MIN 5000): ");
balance = sc.nextLong();
System.out.println();
}
// This method is for display the details of the accounts
void displayacc() {
System.out.println("Name of the account holder is: " + name);
System.out.println("Account no is: " + acc);
System.out.println("Account type is: " + acctype);
System.out.println("Initial balance in the account is: " + balance);
sc.nextLine();
System.out.println("Press Enter To Continue...");
sc.nextLine();
}
// This method is for deposit money
void deposit() {
long amount;
System.out.print("Enter the amount to be deposited ");
amount = sc.nextLong();
balance = balance + amount;
}
// This method is for withdraw money
void withdraw() {
long amount;
System.out.println("Enter the amount to be withdrawn ");
amount = sc.nextLong();
if (balance >= amount) {
balance = balance - amount;
System.out.println("Updated balance is " + balance);
} else {
System.out.println("Your balance is less than the " + amount + "\n" + "Transaction failed");
}
}
boolean search(String acno) {
if (acc.equals(acno)) {
displayacc();
return true;
}
return (false);
}
}
class Bankingapp {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// System.out.println("Enter the number of account's details you hve to enter");
// int a=sc.nextInt();
Bankdetails arr[] = new Bankdetails[100];
int count = 0;
int choice;
do {
System.out.println("\n-------BANKING SYSTEM APPLICATION-------");
System.out.println("1.Creat A Account\n2.Display all account deatils\n3.Search acc by Account type\n4.Deposit the amount\n5.Withdraw the amount\n6.Exit");
System.out.print("Enter (1-6) : ");
choice = sc.nextInt();
switch (choice) {
case 1:
// to create a new account
for (int i = count; i <= count && i < 100; i++) {
arr[count] = new Bankdetails();
arr[count].bankDetails();
}
count++;
break;
case 2:
for (int i = 0; i < count; i++) {
arr[i].displayacc();
}
break;
case 3:
System.out.print("Enter the account No");
String acno = sc.next();
boolean b = false;
for (int i = 0; i < count; i++) {
b = arr[i].search(acno);
if (b) {
break;
}
}
if (!b) {
System.out.println("Account not found!!");
}
break;
case 4:
System.out.println("Enter the Account No ");
acno = sc.next();
b = false;
for (int i = 0; i < arr.length; i++) {
b = arr[i].search(acno);
if (b) {
arr[i].deposit();
break;
}
}
if (!b) {
break;
}
if (!b) {
System.out.println("Account not found!!");
}
break;
case 5:
System.out.println("Enter the account no ");
acno = sc.next();
b = false;
for (int i = 0; i < count; i++) {
b = arr[i].search(acno);
if (b) {
arr[i].withdraw();
break;
}
}
if (!b) {
System.out.println("Account not found!!");
}
break;
case 6:
System.out.println("Thank You\n----SEE YOU SOON----");
break;
}
} while (choice != 6);
}
}