Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Transactions On Large Scale Data And Knowledge Centered Systems Iv Special Issue On Database Systems For Biomedical Applications Lncs 6990

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Christian Bohm ,Johann Eder ,Claudia Plant

2011th Edition

3642237398, 978-3642237393

More Books

Students also viewed these Databases questions