Leaky Bucket
Leaky Bucket
import java.util.Scanner; // Importing the Scanner class to take input from the user.
import java.lang.*; // Importing the default Java language package (not strictly needed as it's
imported automatically).
// Now checking how much data can be sent from the bucket.
if (buck_rem != 0) {
// If the remaining data is less than the transmission rate, send all of it.
if (buck_rem < rate) {
sent = buck_rem; // Send whatever is left.
buck_rem = 0; // After sending, the bucket becomes empty.
} else {
// Otherwise, send data at the fixed rate.
sent = rate;
buck_rem = buck_rem - rate; // Reduce the remaining data by the rate.
}
}
else {
sent = 0; // If bucket is empty, nothing is sent.
}