From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../hjp5/examples/FloatTables.java | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/FloatTables.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/FloatTables.java') 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 -- cgit v1.2.3