Skip to content

Commit ba4da3b

Browse files
Initial Commit
1 parent 839f056 commit ba4da3b

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

FATANSWERKEY/src/Main.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
*
3+
*/
4+
import java.util.*;
5+
/**
6+
* @author M.NAVEEN
7+
* RANDOM CODER'S
8+
* Tech/Project Lead Android Club
9+
*/
10+
public class Main {
11+
12+
public static void main(String[] args)
13+
{
14+
bank customer1=new bank(1000);
15+
Customer c1=new Customer(customer1);
16+
Customer c2=new Customer(customer1);
17+
Thread t1=new Thread(c1);
18+
Thread t2=new Thread(c2);
19+
t1.start();
20+
t2.start();
21+
}
22+
23+
}
24+
25+
26+
class Customer implements Runnable{
27+
bank b;
28+
Scanner nav=new Scanner (System.in);
29+
public Customer(bank b)
30+
{
31+
this.b=b;
32+
}
33+
34+
public void run() {
35+
System.out.println("Enter the Amount to Withdraw :");
36+
b.withdraw(nav.nextInt());
37+
}
38+
39+
}
40+
41+
class bank
42+
{ int balances;
43+
Scanner nav=new Scanner (System.in);
44+
bank(int amount)
45+
{
46+
balances=amount;
47+
}
48+
49+
public synchronized void withdraw(int amount)
50+
{ if(amount>balances) {
51+
System.out.println("Money not Sufficent !! Deposit Money to Withdraw Money!!");
52+
deposit(amount);
53+
54+
55+
56+
}
57+
balances=balances-amount;
58+
59+
System.out.println("Amount Balance"+Thread.currentThread().getName()+" :"+balances);
60+
}
61+
62+
public synchronized void deposit(int needmoney)
63+
{ System.out.println("Enter the Amount to Your Account :");
64+
int newamount=nav.nextInt();
65+
balances=balances+newamount;
66+
67+
if(balances<needmoney) {deposit(needmoney);System.out.println("Add more moeny!!");}
68+
// notifyAll();
69+
}
70+
}
71+

0 commit comments

Comments
 (0)