Question
JAVA. Okay, I have been just a bit behind on my coursework and would love to have someone help explain so I know what I
JAVA. Okay, I have been just a bit behind on my coursework and would love to have someone help explain so I know what I am trying to do. I think I just need help setting this up and a quick explanation on implements, iterator, and iterable within JAVA. Thanks!
So I have set up my Main class and EvensGenerator class (which will implement Iterable
With the EvensGenerator class, constructor initializes a new EvensGenerator, which will return one even number when it's next() method is called. The first even number returned is firstEven. Following even numbers returned in this way will be the smallest even number that is larger than the previous.
After numberOfEvens numbers have been generated and returned from this next() method, the generator will end: its hasNext() method will return false, and its next() method will throw a NoSuchElementException when called after this point.
So we have:
public class EvensGenerator implements Iterable
public EvensGenerator(int numberOfEvens, Integer firstEven) throws IllegalArgumentException {
//numberOfEvens (number of evens that can be generated)
//firstEven (first and smallest even that will be generated)
//IllegalArgumentException (when numberOfEvens is negative, or when firstEven is not an even number)
//Implement constructor along with each of the required methods associated with the interfaces implemented by this class: hasNext(), next(), and iterator().
}
}
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