-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatmMachine.java
More file actions
57 lines (47 loc) · 1.24 KB
/
atmMachine.java
File metadata and controls
57 lines (47 loc) · 1.24 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
class ATM
{
synchronized public void checkbalance(String name)
{
System.out.print(name+" Checking");// prints name checking
try{Thread.sleep(1000);} catch(Exception e){} //sleeps for 1000millisec
System.out.println("balance"); //and then prints the balance
}
synchronized public void withdraw(String name, int amount)
{
System.out.print(name + "withdrawing");
try{Thread.sleep(1000);} catch(Exception e){}
System.out.println(" "+amount);
}
}
class customer extends Thread
{
String name;
int amount;
ATM atm; //reference to ATM
customer(String n,ATM a,int amt)
{
name = n;
atm = a;
amount = amt;
}
public void useATM()
{
atm.checkbalance(name);
atm.withdraw(name, amount);
}
public void run() //must be overrided
{
useATM();
}
}
public class atmMachine {
public static void main(String arg [])
{
ATM atm=new ATM();
customer c1 = new customer("Sarthak",atm,500000000);
customer c2 = new customer("Ayush",atm,900000000);
// c1.useATM();
c1.start();
c2.start();
}
}