CJCoding With Joseph
15free / daySign inCreate account

Write a generic class that represents a range between a low value and a high value. It should work for any type whose values can be compared, such as Integer, String or Double, so the type parameter needs a bound.

Requirements: 1. Change the class header so the class is generic with a bounded type parameter: Range<T extends Comparable<T>>. 2. Store two private fields of type T, low and high, set by the constructor Range(T low, T high). 3. boolean contains(T value) returns true when value is not below low and not above high. Both ends count as inside. Compare with compareTo, because < and > do not work on a T. 4. toString() returns the two ends inside square brackets with two dots between them. A range from 13 to 19 gives [13..19].

Do NOT write a main method.

Expected output

[13..19]
true
true
false
false

= newline. The output ends with a newline, so print one after the last line.

Hints4 available
Topics
GenericsClasses
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.