Question
Design a hit counter (class HitCounter) by using the Queue ADT: Assume you are designing a website; your boss asks you to design a program
Design a hit counter (class HitCounter) by using the Queue ADT: Assume you are designing a website; your boss asks you to design a program that can count how many hits received in the past minute. You may assume that each hit comes with a timestamp, hits are received in a chronological order, i.e., the timestamp is monotonically increasing, the earliest timestamp starts at 1, and no hits arrive at the same time. In java.
/*Using the following queue interface*/
/** * Interface for a queue: a collection of elements that are inserted * and removed according to the first-in first-out principle. Although * similar in purpose, this interface differs from java.util.Queue. */
public interface Queue
/**method: size * returns the number of elements in the queue * @return number of elements in the queue */ int size();
/**method: isEmpty * tests whether the queue is empty * @return true if the queue is empty, false otherwise */ boolean isEmpty();
/**method: first * returns, but does not remove, the first element of the queue * @return the first element of the queue (or null if empty) */ T first(); /**method: enqueue * inserts an element at the rear of the queue * @param e the element to be inserted */ void enqueue(T e);
/**method: dequeue * removes and returns the first element of the queue * @return element removed (or null if empty) */ T dequeue(); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started