If you have a Range thats inclusive (all ints between low and high)...which will have a simple constructor...an isEmpty() method that returns true if a range is empty and false otherwise ([0,0] is valid, so a way is needed to represent an empty range), and an intersection(Range other) method that returns a new range equal to the intersection between this range and the other, or empty if they don't intersect. Its a question for a class which I dont understand...Don't even know where to begin because I dont understand this whole range and intersection concept. Any help or a nudge in the right direction would be appreciated.

and some examples...if you have [3,6] & [4,10] intersection = [4,6] and if you have [10,20] & [30,40] intersection = empty

Do you mean that you don't understand what intersection means?

In one of your examples, [3,6] & [4,10] = [4,6].

What that means is that if you look at the numbers between 3 and 6, 3,4,5,6, and the numbers between 4 and 10, 4,5,6,7,8,9,10, then which numbers are in common to the two ranges? In this case, the numbers between 4 and 6.

John Lockheart
Ranch Hand

Joined: Oct 13, 2006
Posts: 115

posted

0

haha, i guess i'm a little slow sometimes. When i see questions like that I immediately think "lines, so i need 4 points, 2 ranges only gives me two points". So than i guess the code i'm looking for is going to be pretty simple. i'll give it a try and maybe post it if i have problems

John Lockheart
Ranch Hand

Joined: Oct 13, 2006
Posts: 115

posted

0

but which what range should i specify to indicate it's an empty range. Like if they don't intersect, instead of returning the empty range i.e [30,20], returning a preset empty range like [0,0]. But thats a valid entry...any thoughts??

You have an isEmpty() method. So I don't see any point in fiddling with Ranges like [30,20] just because they are empty. Just return that and make sure its isEmpty() method returns true.

Hi all, I was wondering if this (Range) could be considered as an extenstion of a Set.

I was thinking that set A could be the Range of numbers between [x,y] and set B could be the Range numbers betwen [w,z].

Conceptually I think its quite neat. Practically, you would have to extend Set to Range providing a constructor that took your begin and end range values, this would have to use brute force to file the Range with the numbers in the range. Its a bit messy from the practical stand point.

Of course it dosnt help with understanding the problem of what an intersection is.

Just that intersection shouts Sets in bright pink neon, I am sure they wouldnt like you just Extending/Implementing the Set interface. But looking up Sets (and Venn Diagrams)in a Maths book, or checking out the Java trail on the collections frame work over on Sun Java Site might help you out.