This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
Joined: Oct 13, 2006
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
Joined: Oct 13, 2006
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??
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.