import java.io.*;
import java.util.*;
class buffer
{ int count=0;
int flag=0;
int id[]=new int[10];
int value[]=new int[10];
class producer
{ int pid=0;
producer(int id)
{ pid=id; }
void putvalue()throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
if(flag==0)
{ flag=1;
System.out.println("enter the value to be put in buffer by producer with id "+pid +" :");
int v=Integer.parseInt(b.readLine());
id[count]=pid;
value[count]=v;
count++;
flag=0;
}
}
}
class consumer
{ int cid=0;
consumer(int id)
{ cid=id; }
void getvalue()throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
if(flag==0)
{ flag=1;
int j;
System.out.println("enter the id of producer whose value u want to access ");
int i=Integer.parseInt(b.readLine());
for(j=0;j
{ System.out.println(" required value is "+value[j]);
break;
}
}
if(j==count)
{System.out.println(" id not found "); }
else
{
while(j<(count-1))
{ id[j]=id[j+1];
value[j]=value[j+1];
j++;
}
count--;
}
flag=0;
}
}
}
void display()throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i
System.out.println(" value ="+value[i]);
}
}
void access()throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int i,j;
producer p1=new producer(10);
producer p2=new producer(20);
consumer c1=new consumer(30);
p1.putvalue();
p2.putvalue();
display();
p1.putvalue();
c1.getvalue();
display();
p1.putvalue();
p2.putvalue();
display();
}
}
class procon
{ public static void main(String []arg)throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
buffer b1=new buffer();
b1.access();
}
}
waste
ReplyDelete