-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcase4.java
More file actions
95 lines (82 loc) · 1.98 KB
/
case4.java
File metadata and controls
95 lines (82 loc) · 1.98 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
class InsufficientFundsException extends Exception
{
public InsufficientFundsException(String message)
{
super(message);
}
}
class Account
{
String accNum;
String accName;
double balance;
Account(String num, String name, double initbal)
{
accNum = num;
accName = name;
balance = initbal;
}
void deposit(double amt)
{
balance = balance + amt;
System.out.println("New Balance: " + balance);
}
void withdraw(double amt)
{
try
{
balance = balance - amt;
if(balance == 0)
{
throw new InsufficientFundsException("Insufficient balance");
}
else
{
System.out.println("Amount Withdrawn Successfully");
}
}
catch(InsufficientFundsException e)
{
System.out.println();
}
@SuppressWarnings("unused")
void transfer(Account target, double amt)
{
target.deposit(amt);
withdraw(amt);
}
void display()
{
System.out.println("Account Number: " + accNum);
System.out.println("Account Holder: " + accName);
System.out.println("Account balance: " + balance);
System.out.println("--------------------------------------");
}
}
class Bank
{
Account[] arr = new Account[1000];
int curr = 0;
void createAcc(String accNum, String accName, double initbal)
{
arr[curr] = new Account(accNum, accName, initbal);
curr = curr + 1;
}
void getAcc(String num)
{
for(int b = 0; b < curr; b++)
{
if(arr[b].accNum.equals(num))
{
arr[b].display();
}
}
}
void displayAll()
{
for(int b = 0; b < curr; b++)
{
arr[b].display();
}
}
}