From fe9c5978f33b3ffcc62c24a28c3f89ca4b1e2e24 Mon Sep 17 00:00:00 2001 From: Martin Goik <goik@hdm-stuttgart.de> Date: Thu, 24 Apr 2014 17:23:28 +0200 Subject: [PATCH] Loop + rounding source code --- .../de/sd1/loop/LoopExample.java | 50 ++++++++++++++++ .../de/hdm_stuttgart/de/sd1/loop/AppTest.java | 38 +++++++++++++ .../hdm_stuttgart/de/sd1/loop/LoopSolve.java | 23 ++++++++ .../de/hdm_stuttgart/de/sd1/loop/AppTest.java | 38 +++++++++++++ Sd1/P/rounding/pom.xml | 57 +++++++++++++++++++ .../de/sd1/rounding/MathTable.java | 17 ++++++ .../de/sd1/rounding/AppTest.java | 38 +++++++++++++ 7 files changed, 261 insertions(+) create mode 100644 Sd1/P/loop/answer/src/main/java/de/hdm_stuttgart/de/sd1/loop/LoopExample.java create mode 100644 Sd1/P/loop/answer/src/test/java/de/hdm_stuttgart/de/sd1/loop/AppTest.java create mode 100644 Sd1/P/loop/question/src/main/java/de/hdm_stuttgart/de/sd1/loop/LoopSolve.java create mode 100644 Sd1/P/loop/question/src/test/java/de/hdm_stuttgart/de/sd1/loop/AppTest.java create mode 100644 Sd1/P/rounding/pom.xml create mode 100644 Sd1/P/rounding/src/main/java/de/hdm_stuttgart/de/sd1/rounding/MathTable.java create mode 100644 Sd1/P/rounding/src/test/java/de/hdm_stuttgart/de/sd1/rounding/AppTest.java diff --git a/Sd1/P/loop/answer/src/main/java/de/hdm_stuttgart/de/sd1/loop/LoopExample.java b/Sd1/P/loop/answer/src/main/java/de/hdm_stuttgart/de/sd1/loop/LoopExample.java new file mode 100644 index 000000000..2df8bcea9 --- /dev/null +++ b/Sd1/P/loop/answer/src/main/java/de/hdm_stuttgart/de/sd1/loop/LoopExample.java @@ -0,0 +1,50 @@ +package de.hdm_stuttgart.de.sd1.loop; + +public class LoopExample { + + public static void main(String [] args) { + + final int upperLimit = 14; + while_squareNumbers(upperLimit); + doWhile_squareNumbers(upperLimit); + } + + /** + * Compute all square numbers starting from 4 in steps of 3 + * being smaller than a given limit. The results are being written to standard output. + * Implemented by a while -loop. + * + * @param limit An upper exclusive bound for the highest number to be squared.. + */ + public static void while_squareNumbers(final int limit) { + System.out.println("Computing square numbers"); + int i = 4; + while (i < limit) { + System.out.println("i = " + i + ", i * i = " + i * i); + i += 3; + } + System.out.println("Finished computing square numbers"); + } + + + /** + * Compute all square numbers starting from 4 in steps of 3 + * being smaller than a given limit. The results are being written to standard output. + * Implemented by a do ... while -loop. + * + * @param limit An upper exclusive bound for the highest number to be squared.. + */ + public static void doWhile_squareNumbers(final int limit) { + System.out.println("Computing square numbers"); + int i = 4; + if (i < limit) { // Needed !!! + do { + System.out.println("i = " + i + ", i * i = " + i * i); + i += 3; + } while (i < limit); + } + + System.out.println("Finished computing square numbers"); + } + +} diff --git a/Sd1/P/loop/answer/src/test/java/de/hdm_stuttgart/de/sd1/loop/AppTest.java b/Sd1/P/loop/answer/src/test/java/de/hdm_stuttgart/de/sd1/loop/AppTest.java new file mode 100644 index 000000000..494099cab --- /dev/null +++ b/Sd1/P/loop/answer/src/test/java/de/hdm_stuttgart/de/sd1/loop/AppTest.java @@ -0,0 +1,38 @@ +package de.hdm_stuttgart.de.sd1.loop; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/Sd1/P/loop/question/src/main/java/de/hdm_stuttgart/de/sd1/loop/LoopSolve.java b/Sd1/P/loop/question/src/main/java/de/hdm_stuttgart/de/sd1/loop/LoopSolve.java new file mode 100644 index 000000000..40e429b7b --- /dev/null +++ b/Sd1/P/loop/question/src/main/java/de/hdm_stuttgart/de/sd1/loop/LoopSolve.java @@ -0,0 +1,23 @@ +package de.hdm_stuttgart.de.sd1.loop; + +public class LoopSolve { + + public static void main(String [] args) { + squareNumbers(14); + } + + /** + * Compute all square numbers starting from 4 in steps of 3 + * being smaller than a given limit. The results are being written to standard output. + * Implemented by a for -loop. + * + * @param limit An upper exclusive bound for the highest number to be squared.. + */ + public static void squareNumbers(final int limit) { + System.out.println("Computing square numbers"); + for (int i = 4; i < limit; i += 3) { + System.out.println("i = " + i + ", i * i = " + i * i); + } + System.out.println("Finished computing square numbers"); + } +} diff --git a/Sd1/P/loop/question/src/test/java/de/hdm_stuttgart/de/sd1/loop/AppTest.java b/Sd1/P/loop/question/src/test/java/de/hdm_stuttgart/de/sd1/loop/AppTest.java new file mode 100644 index 000000000..494099cab --- /dev/null +++ b/Sd1/P/loop/question/src/test/java/de/hdm_stuttgart/de/sd1/loop/AppTest.java @@ -0,0 +1,38 @@ +package de.hdm_stuttgart.de.sd1.loop; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/Sd1/P/rounding/pom.xml b/Sd1/P/rounding/pom.xml new file mode 100644 index 000000000..a78338126 --- /dev/null +++ b/Sd1/P/rounding/pom.xml @@ -0,0 +1,57 @@ +<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>loop</artifactId> + <version>0.0.1-SNAPSHOT</version> + <packaging>jar</packaging> + + <name>loop</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> + <links> + <link>http://www.greenfoot.org/files/javadoc/</link> + </links> + <!-- Setting destDir interferes with taglet class --> + <additionalJOptions> + <additionalJOption>-d ${javadocDestdir}</additionalJOption> + </additionalJOptions> + + </configuration> + </plugin> + </plugins> + </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/rounding/src/main/java/de/hdm_stuttgart/de/sd1/rounding/MathTable.java b/Sd1/P/rounding/src/main/java/de/hdm_stuttgart/de/sd1/rounding/MathTable.java new file mode 100644 index 000000000..b63ef1cde --- /dev/null +++ b/Sd1/P/rounding/src/main/java/de/hdm_stuttgart/de/sd1/rounding/MathTable.java @@ -0,0 +1,17 @@ +package de.hdm_stuttgart.de.sd1.rounding; + +/** + * Hello world! + * + */ +public class MathTable +{ + public static void main( String[] args ) + { + + for (int i = 0; i < 360; i += 5) { + double sinValue = Math.sin(i * Math.PI / 180); + System.out.println(i + ": " + Math.round(100 * sinValue)); + } + } +} diff --git a/Sd1/P/rounding/src/test/java/de/hdm_stuttgart/de/sd1/rounding/AppTest.java b/Sd1/P/rounding/src/test/java/de/hdm_stuttgart/de/sd1/rounding/AppTest.java new file mode 100644 index 000000000..0c83c06c5 --- /dev/null +++ b/Sd1/P/rounding/src/test/java/de/hdm_stuttgart/de/sd1/rounding/AppTest.java @@ -0,0 +1,38 @@ +package de.hdm_stuttgart.de.sd1.rounding; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} -- GitLab