-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04-Banking-App.java
More file actions
170 lines (135 loc) · 4.15 KB
/
Copy path04-Banking-App.java
File metadata and controls
170 lines (135 loc) · 4.15 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import java.util.Scanner;
class BankDetails
{
private String accno;
private String name;
private String acc_type;
private long balance;
Scanner sc = new Scanner(System.in);
public void openAccount()
{
System.out.print("Enter Account No: ");
accno = sc.next();
System.out.print("Enter Account Type: ");
acc_type = sc.next();
sc.nextLine(); // consume newline
System.out.print("Enter Name: ");
name = sc.nextLine();
System.out.print("Enter Balance: ");
balance = sc.nextLong();
}
public void showAccount()
{
System.out.println("\nName: " + name);
System.out.println("Account No: " + accno);
System.out.println("Account Type: " + acc_type);
System.out.println("Balance: " + balance);
}
public void deposit()
{
System.out.print("Enter amount to deposit: ");
long amt = sc.nextLong();
balance += amt;
System.out.println("Updated Balance: " + balance);
}
public void withdrawal()
{
System.out.print("Enter amount to withdraw: ");
long amt = sc.nextLong();
if (balance >= amt)
{
balance -= amt;
System.out.println("Balance after withdrawal: " + balance);
} else {
System.out.println("Insufficient balance!");
}
}
public boolean search(String ac_no)
{
if (accno.equals(ac_no))
{
showAccount();
return true;
}
return false;
}
}
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("How many customers? ");
int n = sc.nextInt();
BankDetails[] C = new BankDetails[n];
for (int i = 0; i < C.length; i++)
{
C[i] = new BankDetails();
C[i].openAccount();
}
int ch;
do
{
System.out.println("\n1.Display\n2.Search\n3.Deposit\n4.Withdraw\n5.Exit");
System.out.print("Enter choice: ");
ch = sc.nextInt();
switch (ch)
{
case 1:
for (BankDetails account : C)
account.showAccount();
break;
case 2:
System.out.print("Enter account no: ");
String ac_no = sc.next();
boolean found = false;
for (BankDetails account : C) {
if (account.search(ac_no)) {
found = true;
break;
}
}
if (!found)
System.out.println("Account not found!");
break;
case 3:
System.out.print("Enter account no: ");
ac_no = sc.next();
found = false;
for (BankDetails account : C)
{
if (account.search(ac_no))
{
account.deposit();
found = true;
break;
}
}
if (!found)
System.out.println("Account not found!");
break;
case 4:
System.out.print("Enter account no: ");
ac_no = sc.next();
found = false;
for (BankDetails account : C)
{
if (account.search(ac_no))
{
account.withdrawal();
found = true;
break;
}
}
if (!found)
System.out.println("Account not found!");
break;
case 5:
System.out.println("Thank you!");
break;
default:
System.out.println("Invalid choice!");
}
} while (ch != 5);
}
}