-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram 12 (Bank Application)
58 lines (56 loc) · 1.28 KB
/
Program 12 (Bank Application)
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
Question: 4) Assume that two
brothers, Joe and John,
share a
common bank account.
They both can,
independently,
read the balance, make a
deposit, and withdraw
some
money. Implement
java application
demonstrate how
the transaction in a bank
can be carried out
concurrently.
Code:
class Bank {
int total = 10000;
void withdrawn(String name, int withdrawal)
{ if (total >= withdrawal) {
System.out.println(name + " withdrawn "
+ withdrawal);
total = total - withdrawal;
System.out.println("Balance after withdrawal: "
+ total);
try {
Thread.sleep(1000);}
catch (InterruptedException e) {
e.printStackTrace();}
}
else {
System.out.println(name
+ " you can not withdraw "
+ withdrawal); System.out.println("your balance is: " + total);
try {
Thread.sleep(1000);}
catch (InterruptedException e) {
e.printStackTrace();
} } }
void deposit(String name, int deposit) {
System.out.println(name + " deposited " + deposit); total = total + deposit;
System.out.println("Balance after deposit: "
+ total);
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
e.printStackTrace(); } } }
class Main{
public static void main(String[] args){
System.out.println("Sarvadnya_Awaghad_D10A_05");
System.out.println("");
System.out.println(""); Bank obj = new Bank();
obj.withdrawn("Joe", 200);
obj.withdrawn("John", 360);
}}