blob: 45aae852fc35dcb638fdd053487dc64f50cfc293 (
plain)
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
53
54
55
56
|
/* Listing0915.java */
class MathExp
implements DoubleMethod
{
public double compute(double value)
{
return Math.exp(value);
}
}
class MathSqrt
implements DoubleMethod
{
public double compute(double value)
{
return Math.sqrt(value);
}
}
class Times2
implements DoubleMethod
{
public double compute(double value)
{
return 2 * value;
}
}
class Sqr
implements DoubleMethod
{
public double compute(double value)
{
return value * value;
}
}
public class Listing0915
{
public static void printTable(DoubleMethod meth)
{
System.out.println("Wertetabelle " + meth.toString());
for (double x = 0.0; x <= 5.0; x += 1) {
System.out.println(" " + x + "->" + meth.compute(x));
}
}
public static void main(String[] args)
{
printTable(new Times2());
printTable(new MathExp());
printTable(new Sqr());
printTable(new MathSqrt());
}
}
|