-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoundsDemo.java
More file actions
43 lines (35 loc) · 1.2 KB
/
BoundsDemo.java
File metadata and controls
43 lines (35 loc) · 1.2 KB
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
class NumericFns<T extends Number> {
T num;
NumericFns(T n) {
num = n;
}
double reciprosal() {
return 1 / num.doubleValue();
}
double fraction() {
return num.doubleValue() - num.intValue();
}
boolean absEqual(NumericFns<?> ob) {
if(Math.abs(num.doubleValue()) == Math.abs(ob.num.doubleValue())) return true;
return false;
}
}
class BoundsDemo {
public static void main(String ... args) {
NumericFns<Integer> iOb = new NumericFns<Integer>(6);
NumericFns<Double> dOb = new NumericFns<Double>(-6.0);
NumericFns<Long> lOb = new NumericFns<Long>(5L);
System.out.println("reciprosal dOb:" + dOb.reciprosal());
System.out.println("fraction dOb:" + dOb.fraction());
System.out.println("iOb & dOb comparing:");
if(iOb.absEqual(dOb))
System.out.println("Abs is equal.");
else
System.out.println("Abs is not equal.");
System.out.println("iOb & lOb comparing:");
if(iOb.absEqual(lOb))
System.out.println("Abs is equal.");
else
System.out.println("Abs is not equal.");
}
}