import java.util.*;
public class LBA {
public static void main(String[] args) {
// TODO Auto-generated method stub
int op;
Scanner s=new Scanner(System.in);
int bktcap=0;
int remain=0;
int pkt[]=new int[10];
System.out.println("Enter Bucket size");
bktcap=s.nextInt();
System.out.println("Enter value n");
int n=s.nextInt();
System.out.println("Enter datarate");
int dr=s.nextInt();
System.out.println("Enter input values");
for(int i=0;i<n;i++){
int val=s.nextInt();
pkt[i]=val;
}
for(int i=0;i<=n;i++){
int total=pkt[i]+remain;
if(total>bktcap) {
if(pkt[i]>bktcap) {
System.out.println("incomming packet size is:"+pkt[i]+"bytes
greater than capacity of "+bktcap+"bytes");
System.out.println("REJECTED");
}
else {
System.out.println("REJECTED");
}
}
else {
remain+=pkt[i];
System.out.println("incomming packet size is:"+pkt[i]);
}
if(remain<=dr) {
op=remain;
remain=0;
}
else {
op=dr;
remain-=dr;
}
System.out.println("packet size is:"+op+"is
transmitted");
System.out.println("remain capacity is:"+remain);
System.out.println();
}
}
}
Super
ReplyDelete