diff --git a/Sd1/P/math/V0_5/.gitignore b/Sd1/P/math/V0_5/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..4e247eee2103b4d4a35eba38166587fee1391f0e --- /dev/null +++ b/Sd1/P/math/V0_5/.gitignore @@ -0,0 +1,4 @@ +/.settings +/target +/.classpath +/.project diff --git a/Sd1/P/math/V0_5/pom.xml b/Sd1/P/math/V0_5/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..3bb2ff32bae9e91c28a9d65311eba46f349ab7eb --- /dev/null +++ b/Sd1/P/math/V0_5/pom.xml @@ -0,0 +1,69 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>de.hdm-stuttgart.de.sd1</groupId> + <artifactId>math</artifactId> + <version>0.5</version> + <packaging>jar</packaging> + + <name>math</name> + <url>http://maven.apache.org</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <javadocDestdir>~/tmp</javadocDestdir> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.3.2</version> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>2.9.1</version> + <configuration> + <linksource>true</linksource> + <!-- Setting destDir interferes with taglet class --> + <additionalJOptions> + <additionalJOption>-d ${javadocDestdir}</additionalJOption> + </additionalJOptions> + + <taglets> + <taglet> + <tagletClass>de.hdm_stuttgart.de.sd1.taglet.HtmlExtensionTaglet</tagletClass> + </taglet> + </taglets> + <tagletpath>../../../../../../../ws/eclipse/HtmlExtensionTaglet/target/classes</tagletpath> + </configuration> + </plugin> + </plugins> + + <resources> + <resource> + <directory>src/main/java</directory> + <includes> + <include> **/*.properties</include> + </includes> + </resource> + </resources> + </build> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> diff --git a/Sd1/P/math/V0_5/src/main/java/de/hdm_stuttgart/de/sd1/math/Driver.java b/Sd1/P/math/V0_5/src/main/java/de/hdm_stuttgart/de/sd1/math/Driver.java new file mode 100644 index 0000000000000000000000000000000000000000..9610c8ca81650641873456b718a750921bc4850e --- /dev/null +++ b/Sd1/P/math/V0_5/src/main/java/de/hdm_stuttgart/de/sd1/math/Driver.java @@ -0,0 +1,18 @@ +package de.hdm_stuttgart.de.sd1.math; + +/** + * Testing {@link Math#exp(double)}in + * + */ +public class Driver { + + /** + * @param args Unused + */ + public static void main(String[] args) { + + System.out.println("max (1, 7, 2)=" + Math.max(1, 7, 2)); + + } + +} diff --git a/Sd1/P/math/V0_5/src/main/java/de/hdm_stuttgart/de/sd1/math/Math.java b/Sd1/P/math/V0_5/src/main/java/de/hdm_stuttgart/de/sd1/math/Math.java new file mode 100644 index 0000000000000000000000000000000000000000..6b9a4505eb73fce3d594f1e17b9d71e95a54c19e --- /dev/null +++ b/Sd1/P/math/V0_5/src/main/java/de/hdm_stuttgart/de/sd1/math/Math.java @@ -0,0 +1,53 @@ +package de.hdm_stuttgart.de.sd1.math; + +/** + * Some class methods. + */ +public class Math { + + /** + * Return the absolute value of a given argument + * @param value The argument to be considered + * @return the argument's absolute (positive) value. + */ + public static double abs(double value) { + if (value < 0) { + return -value; + } else { + return value; + } + } + + /** + * The maximum of two arguments + * @param a First argument + * @param b Second argument + * @return The maximum of a and b + */ + public static double max(double a, double b) { + return a < b ? b : a; // very compact, avoiding "if". Readability?? + } + + /** + * The maximum of three arguments + * + * @param a First argument + * @param b Second argument + * @param c Third argument + * @return The maximum of a, b and c + */ + public static double max(double a, double b, double c) { + final double max_A_B; + if (a < b) { + max_A_B = b; + } else { + max_A_B = a; + } + + if (c < max_A_B) { + return max_A_B; + } else { + return c; + } + } +} diff --git a/Sd1/P/math/V0_5/src/test/java/de/hdm_stuttgart/de/sd1/math/ExpTest.java b/Sd1/P/math/V0_5/src/test/java/de/hdm_stuttgart/de/sd1/math/ExpTest.java new file mode 100644 index 0000000000000000000000000000000000000000..1476e3091562039cbbd1485c324d771361106772 --- /dev/null +++ b/Sd1/P/math/V0_5/src/test/java/de/hdm_stuttgart/de/sd1/math/ExpTest.java @@ -0,0 +1,25 @@ +package de.hdm_stuttgart.de.sd1.math; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Testing exponential implementation + * + */ +public class ExpTest extends TestCase { + /** + * @return the suite of tests being tested + */ + public static Test suite() { + final TestSuite testsuite = new TestSuite("Testing exponential"); + testsuite.addTestSuite(ExpTest.class); + return testsuite; } + + /** + * Sums and products of fractions + */ + public void testApp() { + } +} diff --git a/Sd1/swd1.xml b/Sd1/swd1.xml index b4d476280238b86fc946a5cd051a3d7e456b8a87..c680617d21afd8c3f43bba85955714f7e2e2d5a1 100644 --- a/Sd1/swd1.xml +++ b/Sd1/swd1.xml @@ -3237,9 +3237,77 @@ Is 2016 a leap year? true</programlisting> </qandaset> </section> - <section xml:id="sd1SecExp"> + <section xml:id="sd1MathMaxAbs"> <title>Building a private library of mathematical functions.</title> + <para>The following sections provide exercises on implementing + mathematical functions. We start with an easy one.</para> + + <qandaset defaultlabel="qanda" xml:id="sd1QandaMaxAbs"> + <title>Maximum and absolute value</title> + + <qandadiv> + <qandaentry> + <question> + <para>Implement two class methods double abs(double) and double + max(double, double, double) in a class math living in a package + of your choice:</para> + + <programlisting language="java">package de.hdm_stuttgart.de.sd1.math; + +/** + * Some class methods. + */ +public class Math { + + /** + * Return the absolute value of a given argument + * @param value The argument to be considered + * @return the argument's absolute (positive) value. + */ + public static double abs(double value) { + ... return ??; + } + + /** + * The maximum of two arguments + * @param a First argument + * @param b Second argument + * @return The maximum of a and b + */ + public static double max(double a, double b) { + ... return ??; + } + + /** + * The maximum of three arguments + * + * @param a First argument + * @param b Second argument + * @param c Third argument + * @return The maximum of a, b and c + */ + public static double max(double a, double b, double c) { + ... return ??; + } +}</programlisting> + + <para>Test these functions using appropriate data.</para> + </question> + + <answer> + <para>See <link + xlink:href="Ref/api/P/math/V0_5/src-html/de/hdm_stuttgart/de/sd1/math/Math.html">implementation + here.</link></para> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + </section> + + <section xml:id="sd1SecExp"> + <title>Implementing the exponential function.</title> + <qandaset defaultlabel="qanda" xml:id="sd1QandaMath"> <title>The exponential <inlineequation> <m:math display="inline">