Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Fill in the BOLD ?n? marks The generic Sequence interface declares two methods t

ID: 3770560 • Letter: F

Question

Fill in the BOLD ?n? marks The generic Sequence interface declares two methods to implement. The next method should return the next element in the sequence. The first call to the next method should return the first element of the sequnce. The reset method should ensure that the next call to the next method returns the first element of the sequence. // A Sequence provides a series of values by repeatedly calling next, public interface Sequence { // Return the next value in the sequence public ?1? next(); // Reset the sequence to start from the beginning, public void reset(); } The generic AbstractSequence class implements the next and reset methods of the Sequence interface by two abstract methods. The firstValue method should return the first value of the seqeuence. The computeValue method should return the next value of the sequence given the current value of the sequence // An AbstractSequence uses getFirst and computeNext to implement next and reset public abstract class AbstractSequence?2? implements Sequence { // The next value to be returned by the next method, private ?3? nextValue; public ?4? next() { ?5? current = nextValue; ?6? = computeNext(?7?); return current; } public void reset() { ?8? = getFirst();} // Return the first value of the sequence public abstract ?9? getFirst(); // Return the next value of the sequence, public abstract ?10? computeNext(?10? current);}

Explanation / Answer

public interface Sequence<T>{

public T next();

public void reset();

}


public abstract class AbstractSequence<T> implements Sequence<T> {

private T nextValue;


public T next(){

   T current = nextValue;
  
   nextValue = computeNext(current);
  
   return current;

}

public void reset() { nextValue = getFirst(); }

public abstract T getFirst();

public abstract T computeNext( T current);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote