diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/hjp5/examples/FloatTables.java | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/FloatTables.java')
| -rw-r--r-- | Master/Reference Architectures and Patterns/hjp5/examples/FloatTables.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/FloatTables.java b/Master/Reference Architectures and Patterns/hjp5/examples/FloatTables.java new file mode 100644 index 0000000..25ea516 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/FloatTables.java @@ -0,0 +1,54 @@ +/* FloatTables.java */
+
+import java.lang.reflect.*;
+
+public class FloatTables
+{
+ public static double times2(double value)
+ {
+ return 2 * value;
+ }
+
+ public static double sqr(double value)
+ {
+ return value * value;
+ }
+
+ public static void printTable(String methname)
+ {
+ try {
+ System.out.println("Wertetabelle fuer " + methname);
+ int pos = methname.lastIndexOf('.');
+ Class clazz;
+ if (pos == -1) {
+ clazz = FloatTables.class;
+ } else {
+ clazz = Class.forName(methname.substring(0, pos));
+ methname = methname.substring(pos + 1);
+ }
+ Class[] formparas = new Class[1];
+ formparas[0] = Double.TYPE;
+ Method meth = clazz.getMethod(methname, formparas);
+ if (!Modifier.isStatic(meth.getModifiers())) {
+ throw new Exception(methname + " ist nicht static");
+ }
+ Object[] actargs = new Object[1];
+ for (double x = 0.0; x <= 5.0; x += 1) {
+ actargs[0] = new Double(x);
+ Double ret = (Double)meth.invoke(null, actargs);
+ double result = ret.doubleValue();
+ System.out.println(" " + x + " -> " + result);
+ }
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ printTable("times2");
+ printTable("java.lang.Math.exp");
+ printTable("sqr");
+ printTable("java.lang.Math.sqrt");
+ }
+}
\ No newline at end of file |
