Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Sum of intervals

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Sum of intervals

    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.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sum of intervals

    I have looked at that and I have written it in English and have provided an answer to the question asked. I am not throwing you a code and asking what's wrong with it I am simply asking for a clue or a step into the right direction because I understand how to answer the question but don't understand why I need to add intervals or check to see if they're the same "numerical interval." I by no means want someone to do my homework for me.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Sum of intervals

    Do you have any specific java programming questions?

    how to get the user to enter the value for infinity.
    If all integer values are valid, then you might have to change the input method to read Strings where you can have the user enter a non-numeric value of your choosing for infinity. Then use the parseInt method to convert the Strings to int values.
    Last edited by Norm; February 21st, 2012 at 04:11 PM.