-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankexcept.java
More file actions
132 lines (131 loc) · 3.55 KB
/
Copy pathBankexcept.java
File metadata and controls
132 lines (131 loc) · 3.55 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
import java.util.Scanner;
class InvalidAmountException extends Exception{
InvalidAmountException(String str){
super(str);
}
}
class InsufficentFundsException extends Exception{
InsufficentFundsException(String str){
super(str);
}
}
public class Bankexcept{
public static void main(String [] args) {
Scanner sc=new Scanner(System.in);
InvalidAmountException amountException=new InvalidAmountException("Invalid Amount");
InsufficentFundsException fundsException=new InsufficentFundsException("Invalid Fund");
int choice;
System.out.println("Enter the Number of Customers:");
int noOfCustomer=sc.nextInt();
Customer [] customer=new Customer[noOfCustomer];
for(int i=0;i<noOfCustomer;i++) {
customer[i]=new Customer();
customer[i].getCustomerdetails();
}
do {
System.out.println("1.Display 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 ");
System.out.println("Enter your choice");
choice=sc.nextInt();
switch(choice) {
case 1:
for(int i=0;i<noOfCustomer;i++) {
customer[i].printCustomerdetails();
}
break;
case 2:
System.out.println("Enter the Account Number:");
long searchAccount=sc.nextLong();
for(int i=0;i<noOfCustomer;i++) {
if(customer[i].accountNumber==searchAccount) {
customer[i]. printCustomerdetails();
}
}
break;
case 3:
System.out.println("Enter the Account Number:");
searchAccount=sc.nextLong();
try {
System.out.println("Enter the amount to deposite:");
int depositeAmount=sc.nextInt();
if(depositeAmount<0) {
throw amountException;
}
else {
for(int i=0;i<noOfCustomer;i++) {
if(customer[i].accountNumber==searchAccount) {
customer[i].accountBalance=customer[i].accountBalance+depositeAmount;
customer[i].printCustomerdetails();
}
}
}
}
catch( InvalidAmountException e) {
System.out.println(e.getMessage());
}
break;
case 4:
System.out.println("Enter the Account Number:");
searchAccount=sc.nextLong();
try {
System.out.println("Enter the amount to Withedraw:");
int withdrawAmount=sc.nextInt();
if(withdrawAmount<=0) {
throw amountException;
}
else {
for(int i=0;i<noOfCustomer;i++) {
if(customer[i].accountNumber==searchAccount) {
if(withdrawAmount>customer[i].accountBalance) {
throw fundsException;
}
else {
customer[i].accountBalance=customer[i].accountBalance;
customer[i].accountBalance=customer[i].accountBalance-withdrawAmount;
customer[i].printCustomerdetails();
}
}
}
}
}
catch(InvalidAmountException e) {
System.out.println(e.getMessage());
}
catch(InsufficentFundsException e) {
System.out.println(e.getMessage());
}
break;
}
}
while(choice<5);
}
}
class Customer{
Scanner sc=new Scanner(System.in);
long accountNumber;
String accountType;
String customerName;
int accountBalance;
public void getCustomerdetails() {
System.out.println("Enter the Account Number:");
accountNumber=sc.nextLong();
System.out.println("Enter the Account Type");
accountType=sc.next();
System.out.println("Enter the name:");sc.nextLine();
customerName=sc.nextLine();
System.out.println("Enter the Account Balance:");
accountBalance=sc.nextInt();
}
public void printCustomerdetails() {
System.out.println("_________________________________");
System.out.println("Customer Details are:");
System.out.println("Account Number:"+accountNumber);
System.out.println("Account Type:"+accountType);
System.out.println("Customer Name:"+customerName);
System.out.println("Acoount Balance:"+accountBalance);
System.out.println("_________________________________");
}
}