Question
Write a class named Range. The class will have two constructors and two methods: next and hasNext. The first constructor for Range takes two integers
Write a class named Range. The class will have two constructors and two methods: next and hasNext. The first constructor for Range takes two integers as input: a starting number and an increment number. This will produce an infinite sequence, which should be represented by a boolean instance variable
The second constructor for Range takes three integers as input: a starting number, an increment number, and an ending number. This will produce a finite sequence.
The next method should return the next integer value in the sequence. The first call to next should return the first value in the sequence. The hasNext method should return true if there are more values yet to return in the sequence and false otherwise. Your code should throw an IllegalArgumentException in the following circumstances ( Note that you will need to import java.lang.IllegalArgumentException; ): - A start and end are given, but the increment is zero. If zero is the increment for an infinite sequence, it's no problem. - The start is less than the end, but the increment is negative. - The start is greater than the end, but the increment is positive.
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