-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInterval.java
More file actions
executable file
·56 lines (44 loc) · 913 Bytes
/
Copy pathInterval.java
File metadata and controls
executable file
·56 lines (44 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
public class Interval
{
private double left_bound;
private double right_bound;
public Interval(double left, double right)
{
left_bound = left;
right_bound = right;
}
public boolean doesContain(double x)
{
if ( left_bound < x && x < right_bound )
{
return true;
}
else return false;
}
public boolean intersects(Interval b)
{
if (left_bound < right_bound)
{
if (left_bound <= b.left_bound && right_bound <= b.right_bound && b.left_bound <= right_bound)
{
return true;
}
else if (left_bound >= b.left_bound && right_bound >= b.right_bound && b.right_bound >= left_bound)
{
return true;
}
else return false;
}
else return false;
}
public String toString()
{
String s = "";
if ( left_bound > right_bound )
{
s = "Interval: (EMPTY)";
}
else s = "Interval: (" + left_bound + "," + right_bound + ")";
return s;
}
}