-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbank.java
More file actions
166 lines (159 loc) · 4.38 KB
/
Copy pathbank.java
File metadata and controls
166 lines (159 loc) · 4.38 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
package prjjava;
import java.util.Scanner;
public class bank {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
InvalidAmountException amountException = new InvalidAmountException("Invalid Amount");
InsufficientFundsExceptions fundsException = new InsufficientFundsExceptions("Insufficient Funds");
System.out.println("* Banking System Application *");
System.out.println("Enter number of customers:");
int noOfCustomers=sc.nextInt();
Customer[] obj = new Customer[noOfCustomers];
for (int i=0; i<noOfCustomers; i++) {
System.out.println("*Enter Customer Details*");
obj[i] = new Customer();
obj[i].setCustomerDetails();
}
int choice=0,i=0;
do {
System.out.println("1.Display all account details");
System.out.println("2.Search by account number");
System.out.println("3.Deposit the amount");
System.out.println("4.Withdraw the amount");
System.out.println("5.Exit");
choice=sc.nextInt();
switch (choice) {
case 1:
for (i=0; i<noOfCustomers; i++) {
System.out.println("Customer No."+(i+1));
obj[i].getCustomerDetails();
}
break;
case 2:
System.out.println("Enter Account Number:");
int searchNumber=sc.nextInt();
for (i=0; i<noOfCustomers; i++) {
if (searchNumber==obj[i].accountNumber) {
obj[i].getCustomerDetails();
break;
}
else if (i==noOfCustomers-1) {
System.out.println("*Invalid Account No.*");
}
else {
continue;
}
}
break;
case 3:
System.out.println("Enter Account Number:");
searchNumber=sc.nextInt();
try {
System.out.println("Enter Amount to deposit:");
int depositAmount = sc.nextInt();
if (depositAmount<=0) {
throw amountException;
}
else {
for (i=0; i<noOfCustomers; i++) {
if (searchNumber==obj[i].accountNumber) {
obj[i].accountBalance+=depositAmount;
obj[i].getCustomerDetails();
}
else if (i==noOfCustomers-1) {
System.out.println("*Invalid Account No.*");
}
else {
continue;
}
}
}
}
catch (InvalidAmountException e) {
System.out.println(e.getMessage());
}
break;
case 4:
System.out.println("Enter Account Number:");
searchNumber=sc.nextInt();
try {
System.out.println("Enter Amount to withdraw:");
int withdrawlAmount = sc.nextInt();
if (withdrawlAmount<=0) {
throw amountException;
}
else {
for (i=0; i<noOfCustomers; i++) {
if (searchNumber==obj[i].accountNumber) {
if (withdrawlAmount>obj[i].accountBalance) {
throw fundsException;
}
else {
obj[i].accountBalance-=withdrawlAmount;
obj[i].getCustomerDetails();
}
break;
}
else if (i==noOfCustomers-1) {
System.out.println("*Invalid Account No.*");
}
else {
continue;
}
}
}
}
catch (InvalidAmountException e){
System.out.println(e.getMessage());
}
catch (InsufficientFundsExceptions e){
System.out.println(e.getMessage());
}
break;
case 5:
System.out.println("**********");
System.out.println(" Thank You ");
System.out.println("**********");
break;
default:
System.out.println("Invalid Choice");
break;
}
}while (choice<5);
}
}
class Customer {
int accountNumber;
String accountType;
String customerName;
int accountBalance;
Scanner sc = new Scanner(System.in);
public void setCustomerDetails() {
System.out.println("Enter Account number:");
accountNumber=sc.nextInt();
System.out.println("Enter Account type:");
accountType=sc.next();
System.out.println("Enter Customer name:");
customerName=sc.next();
System.out.println("Enter Account opening balance:");
accountBalance=sc.nextInt();
}
public void getCustomerDetails() {
System.out.println("**-CUSTOMER DETAILS-**");
System.out.println("Account Number: " + accountNumber);
System.out.println("Account Type: " + accountType);
System.out.println("Customer Name: " + customerName);
System.out.println("Account Balance: " + accountBalance);
System.out.println("************************");
}
}
class InvalidAmountException extends Exception {
InvalidAmountException(String str) {
super(str);
}
}
class InsufficientFundsExceptions extends Exception {
InsufficientFundsExceptions(String str) {
super(str);
}
}