Hello, I am fairly new at Java and just have a couple of questions to help me understand exactly what kind of program, class I am supposed to write.
Create an Interval class that represents an interval of numeric values. For example, it could represent the interval [1,2].
This class will be used to perform computations on uncertain quantities. For example, if you have a number in the range [1, 2] and another number in the range [0.1, 0.3], then their sum must be in the range [1.1, 2.3]. This can be used to answer questions like "If you have between 1000 and 2000 people, and between 10% and 15% of them have a pet goat, what are the most and least people that could have a pet goat?"
From what I understand so far is I have to ask the user to input two intervals one the range of people next the range of percentages.
Ensure that instances of your class are immutable (you can't change the interval that an object represents after you create it), and support the following operations:
add: add two intervals, returning the interval in which the sum must lie.
I do not understand what I need to add. The only operations I see necessary is multiplying the percentages by the range of people. This part of the assignment confuses me the most.
multiply: multiply two intervals, returning the interval in which the product must lie.
equals: test if two Interval objects represent the same numeric interval.
This is the second part of the assignment that confuses me as well. Why do I need to test two intervals to have the same numeric interval? I don't see the point in this.
Implement a toString method that provides a nice representation of the interval.
Include a main method that tests your class's functionality. It should test the operations using a variety of intervals, including the following cases:
0-width intervals (like [1, 1])
Intervals that lie in (0, +∞)
Intervals that lie in (-∞, 0)
Intervals containing 0.
Optional: support unbounded intervals, like (-∞, 3], [-3, ∞), or (-∞, ∞).
And finally, I am having trouble finding out how to get the user to enter the value for infinity.
Thank you, for any helpful hints.