You are given the class called Spectrum intented to keep spectrum measurement data. Your task is to apply the Iterator pattern and write the SpectrumIteratorImpl class implementing the SpectrumIterator interface to iterate over the elements of the underlying array.
Iterator
Array iterator
Report a typo
Write a program in Java 17
import java.util.*;
interface SpectrumIterator {
boolean hasNext();
double next();
}
class Spectrum {
private static final int START = 0;
private static final int END = 1000;
private final double[] array;
public Spectrum(double[] array) {
this.array = array.clone();
}
public double getStep() {
return (double) (END - START) / array.length;
}
public SpectrumIterator iterator() {
// TODO
}
private class SpectrumIteratorImpl implements SpectrumIterator {
// TODO
}
}
// do not change the code below
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double[] data = Arrays.stream(scanner.nextLine().split(" "))
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.