-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcounter_restaurant.java
More file actions
46 lines (45 loc) · 1.3 KB
/
counter_restaurant.java
File metadata and controls
46 lines (45 loc) · 1.3 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
import java.util.*;
class counter extends Thread{
static int customer[]=new int[5];
static int i=0;
String name;
int count,finalamt=0;
Scanner sc=new Scanner(System.in);
public counter(String name){
this.name=name;
for(int i=0;i<customer.length;i++){
customer[i]=i+1;
}
count=0;
}
public void run(){
while(i<customer.length){
synchronized(customer){
if(i<customer.length){
System.out.println(name+" serving "+customer[i]);
int x=sc.nextInt();
finalamt=finalamt+x;
i++;
count++;
try{
Thread.sleep(10);
}
catch(InterruptedException e){
System.out.println(e);
}
}
}
}
System.out.println(name+" has served "+count+" coustomer total sales are :"+finalamt);
}
}
public class counter_restaurant {
public static void main(String[] args) {
counter c1=new counter("qwe");
counter c2=new counter("asd");
counter c3=new counter("zxc");
c1.start();
c2.start();
c3.start();
}
}