public class SlidingWindowReceiver { /* Buffer for packet data. */ Object[] buf; /* Range of sequence numbers: Sequence numbers s * with 0 <= s < seqNrRange are valid. */ int seqNrRange; /* Sequence number of the next frame expected. */ int nfe = 0; /* Buffer index at which the nfe-Paket is (or will be) stored. */ int nfeIndex = 0; /* Create a sliding window receiver with the specified window size * and sequence number range. */ public SlidingWindowReceiver(int windowSize, int snr) { buf = new Object[windowSize]; seqNrRange = snr; } private int nextBufferIndex(int index) { // ... implement this method return 0; // ... change this as necessary } private int nextSeqNr(int seqNr) { // ... implement this method return 0; // ... change this as necessary } /* Return the next packet in the sequence. If no packet is * available, null will be returned. This method is called by the * layer above. */ public Object getNextPacket() { // ... implement this method return null; // ... change this as necessary } /* Handle a packet delivered by the layer below. Return the * sequence number of the acknowledgement to be sent back. If no * acknowledgement is to be sent, return -1. */ public int handlePacket(int seqNr, Object data) { if (seqNr < 0 || seqNr >= seqNrRange) { // Sequence number out of range. Do not send an ACK. return -1; } // ... implement this method return -1; // change this as necessary } private int step = 0; public String show() { // ... implement this method return ""; } }