Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 and Iterator)

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, Iterator {

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions