diff --git a/Doc/Sd1/Exam/2020/Winter_1/exam.xml b/Doc/Sd1/Exam/2020/Winter_1/exam.xml index 978d128fe65ba2d51efdd40052e47a369cafc86a..cdf4d4586cff07e18a04b76b9a76b0991a3a3911 100644 --- a/Doc/Sd1/Exam/2020/Winter_1/exam.xml +++ b/Doc/Sd1/Exam/2020/Winter_1/exam.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<section version="5.0" xml:id="sd1_exam_2020_winter" xml:lang="en" +<section version="5.0" xml:id="sd1_exam_2020_winter_1" xml:lang="en" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xila="http://www.w3.org/2001/XInclude/local-attributes" @@ -11,10 +11,10 @@ xmlns:db="http://docbook.org/ns/docbook"> <title>SD1 examination winter 2020/1</title> - <section xml:id="sd1_exam_2020_winter_task1"> + <section xml:id="sd1_exam_2020_winter_1_task1"> <title>Implementing tasks</title> - <section xml:id="sd1_exam_2020_winter_task1_preparation"> + <section xml:id="sd1_exam_2020_winter_1_task1_preparation"> <title>Preparation</title> <para>Download and unzip the above file <filename>exam.zip</filename>. @@ -24,7 +24,7 @@ file.</para> </section> - <section xml:id="sd1_exam_2020_winter_task1_description"> + <section xml:id="sd1_exam_2020_winter_1_task1_description"> <title>Description</title> <para>Your imported project contains:</para> @@ -46,7 +46,7 @@ </itemizedlist> </section> - <section xml:id="sd1_exam_2020_winter_task1_tasks"> + <section xml:id="sd1_exam_2020_winter_1_task1_tasks"> <title>Tasks</title> <para>Complete the implementation of classes and methods in both @@ -57,7 +57,7 @@ implemented.</para> </section> - <section xml:id="sd1_exam_2020_winter_task1_hints"> + <section xml:id="sd1_exam_2020_winter_1_task1_hints"> <title>Hints</title> <itemizedlist> @@ -102,7 +102,7 @@ </itemizedlist> </section> - <section version="5.1" xml:id="sd1_exam_2020_winter_uploadFirst"> + <section version="5.1" xml:id="sd1_exam_2020_winter_1_uploadFirst"> <title>Project upload</title> <para>Export your project by hitting »File« --> »Export to Zip File« @@ -132,7 +132,7 @@ </itemizedlist> </section> - <section xml:id="sd1_exam_2020_winter_examCaveats"> + <section xml:id="sd1_exam_2020_winter_1_examCaveats"> <title>Caveats</title> <itemizedlist> @@ -149,10 +149,10 @@ </section> </section> - <section xml:id="sd1_exam_2020_winter_task2"> + <section xml:id="sd1_exam_2020_winter_1_task2"> <title>Type conflict</title> - <qandaset defaultlabel="qanda" xml:id="sd1_exam_2020_winter_task2Qanda"> + <qandaset defaultlabel="qanda" xml:id="sd1_exam_2020_winter_1_task2Qanda"> <qandadiv> <qandaentry> <question> @@ -215,10 +215,10 @@ </qandaset> </section> - <section xml:id="sd1_exam_2020_winter_task3"> + <section xml:id="sd1_exam_2020_winter_1_task3"> <title>Weird subtraction</title> - <qandaset defaultlabel="qanda" xml:id="sd1_exam_2020_winter_task3Qanda"> + <qandaset defaultlabel="qanda" xml:id="sd1_exam_2020_winter_1_task3Qanda"> <qandadiv> <qandaentry> <question> diff --git a/Doc/Sd1/Exam/2020/Winter_2/exam.xml b/Doc/Sd1/Exam/2020/Winter_2/exam.xml new file mode 100644 index 0000000000000000000000000000000000000000..d95f10bcb9a29c994cb14b1fecbd789f88752b42 --- /dev/null +++ b/Doc/Sd1/Exam/2020/Winter_2/exam.xml @@ -0,0 +1,252 @@ +<?xml version="1.0" encoding="UTF-8"?> +<section version="5.0" xml:id="sd1_exam_2020_winter_2" xml:lang="en" + xmlns="http://docbook.org/ns/docbook" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:xila="http://www.w3.org/2001/XInclude/local-attributes" + xmlns:xi="http://www.w3.org/2001/XInclude" + xmlns:trans="http://docbook.org/ns/transclusion" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns:m="http://www.w3.org/1998/Math/MathML" + xmlns:html="http://www.w3.org/1999/xhtml" + xmlns:db="http://docbook.org/ns/docbook"> + <title>SD1 examination winter 2020/2</title> + + <section xml:id="sd1_exam_2020_winter_2_task1"> + <title>Implementing tasks</title> + + <section xml:id="sd1_exam_2020_winter_2_task1_preparation"> + <title>Preparation</title> + + <para>Download and unzip the above file <filename>exam.zip</filename>. + Then import the resulting <filename>Exam</filename> Project into your + <productname>IDEA</productname> IDE by choosing »File --> Open...« + subsequently selecting the <filename>Exam/pom.xml</filename> + file.</para> + </section> + + <section xml:id="sd1_exam_2020_winter_2_task1_description"> + <title>Description</title> + + <para>Your imported project contains:</para> + + <itemizedlist> + <listitem> + <para>Partial implementations of classes and methods.</para> + </listitem> + + <listitem> + <para><productname>Javadoc</productname> comments describing the + desired behaviour</para> + </listitem> + + <listitem> + <para><productname>Junit</productname> tests for testing the desired + (not yet implemented) behaviour.</para> + </listitem> + </itemizedlist> + </section> + + <section xml:id="sd1_exam_2020_winter_2_task1_tasks"> + <title>Tasks</title> + + <para>Complete the implementation of classes and methods in both + packages <package>de.hdm_stuttgart.mi.sd1.task1</package> and + <package>de.hdm_stuttgart.mi.sd1.task2</package>. Your project's + <filename>test</filename> branch contains corresponding + <productname>Junit</productname> tests for each class / method to be + implemented.</para> + </section> + + <section xml:id="sd1_exam_2020_winter_2_task1_hints"> + <title>Hints</title> + + <itemizedlist> + <listitem> + <para>Your score solely depends on the number of successfully + executing unit tests. A »nearly correct« implementation failing with + respect to a given unit tests will contribute no points at + all.</para> + + <para>General advice: Implement less but correctly.</para> + </listitem> + + <listitem> + <para>Mind special cases <abbrev>i.e.</abbrev> <code>null</code> + variable values or <code>null</code> values being contained in + arrays.</para> + </listitem> + + <listitem> + <para>In case of test failures both the + <productname>IDEA</productname> debugger and logging statements are + your friend.</para> + </listitem> + + <listitem> + <para>Executing + <package>de.hdm_stuttgart.mi.sd1.test</package>.<classname>ShowReachedPoints</classname> + in your project's <filename>test</filename> branch as a + <productname>Java</productname> application (not as + <productname>Junit</productname> test!) shows your number of points + reached so far.</para> + </listitem> + + <listitem> + <para>Do not model your implementations along unit test definitions + i.e avoid <link + xlink:href="https://freedocs.mi.hdm-stuttgart.de/__slidesd1_appendix.html#/sd1_fig_testDontCheat">cheating + this way</link>! Such behaviour will be regarded as an attempt at + deception (<foreignphrase + xml:lang="de">Täuschungsversuch</foreignphrase>).</para> + </listitem> + </itemizedlist> + </section> + + <section version="5.1" xml:id="sd1_exam_2020_winter_2_uploadFirst"> + <title>Project upload</title> + + <para>Export your project by hitting »File« --> »Export to Zip File« + in IDEA creating an <abbrev>e.g.</abbrev> + <filename>solution-1.zip</filename> file. Hit the <quote> choose + file</quote> button in your <productname>ILIAS</productname> browser tab + and select <filename>solution-1.zip</filename>. Subsequently click + <quote>upload</quote>. Do not forget to advance to the next question for + actually saving your upload. Common pitfalls:</para> + + <itemizedlist> + <listitem> + <para>Do not select the wrong archive! In particular avoid choosing + the original <filename>exam.zip</filename> skeleton.</para> + </listitem> + + <listitem> + <para>After uploading check for <filename>solution_1.zip</filename> + being visible in the examination system.</para> + </listitem> + + <listitem> + <para>You may upload multiple versions i.e. + <filename>solution_2.zip</filename> etc. . Only your least uploaded + archive will become subject to marking.</para> + </listitem> + </itemizedlist> + </section> + + <section xml:id="sd1_exam_2020_winter_2_examCaveats"> + <title>Caveats</title> + + <itemizedlist> + <listitem> + <para>When approaching examination ending time check your input for + completeness.</para> + </listitem> + + <listitem> + <para>Projects residing just on your local workstation cannot be + recovered after exam termination.</para> + </listitem> + </itemizedlist> + </section> + </section> + + <section xml:id="sd1_exam_2020_winter_2_task2"> + <title>Surprising difference</title> + + <qandaset defaultlabel="qanda" xml:id="sd1_exam_2020_winter_2_task2Qanda"> + <qandadiv> + <qandaentry> + <question> + <para>You have learned to replace expressions like e.g. <code + language="java">b = b * 4</code> by <code language="java">b *= + 4</code>. The following two code snippets should thus be + equivalent:</para> + + <informaltable border="1"> + <colgroup width="66%"/> + + <colgroup width="34%"/> + + <tr> + <th>Code</th> + + <th>Output</th> + </tr> + + <tr> + <td valign="top"><programlisting language="java">int a = 3, b = 6; +b = b * a / 2; +System.out.println("b = " + b);</programlisting></td> + + <td valign="top">b = 9</td> + </tr> + + <tr> + <td valign="top"><programlisting language="java">int a = 3, b = 6; +b *= a / 2; +System.out.println("b = " + b);</programlisting></td> + + <td valign="top">b = 6</td> + </tr> + </informaltable> + + <para>Explain the different outcome.</para> + </question> + + <answer> + <para>The difference is being caused by the *= operator's + behaviour with respect to the order of evaluation. The first + expression b = b * a / 2 containing two left-associative operators + <code>*</code> and <code>/</code> may be rewritten as <code + language="java">b = ((b * a) / 2)</code>. We thus get 18 / 2 being + equal to 9.</para> + + <para>The second expression <code language="java">b *= a / + 2</code> is equivalent to <code language="java">b = (b * (a / + 2</code>)). Since the integer division 3 / 2 results in 1 we get + the final result 6.</para> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + </section> + + <section xml:id="sd1_exam_2020_winter_2_task3"> + <title>Type assignment problem</title> + + <qandaset defaultlabel="qanda" xml:id="sd1_exam_2020_winter_2_task3Qanda"> + <qandadiv> + <qandaentry> + <question> + <para>Consider the following code snippet:</para> + + <programlisting language="java">byte a, b; +... +byte average = (a + b) / 2;</programlisting> + + <para>The compiler complains <quote>Required type: byte Provided: + int</quote> with respect to the second line. Why is that although + only <code>byte</code> values are being involved?</para> + + <para>Propose a solution solving the issue at the same preserving + the <code>byte</code> result type. Is your solution susceptible to + overflow errors?</para> + </question> + + <answer> + <para>An expression <quote>byte + byte</quote> is of type + <code>int</code>, see <link + xlink:href="https://freedocs.mi.hdm-stuttgart.de/__slidesw1LanguageFundamental.html#/sd1_fig_genericBinaryTypeExamples">Binary + operator type examples</link>. We thus require a type cast:</para> + + <programlisting language="java">... +byte average = (byte) ((a + b) / 2);</programlisting> + + <para>The expression a + b of type int may range from -2 * 128 to + 2 * 127. Dividing by 2 leaves us with a <code>byte</code>'s range. + Thus there is no arithmetic overflow to occur.</para> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + </section> +</section> diff --git a/Doc/Sd1/appendix.xml b/Doc/Sd1/appendix.xml index 7f37287dc3ad2a3bf5cc38a350aee68796b07563..329014f1b76c616914ff95f9e682daf63516a653 100644 --- a/Doc/Sd1/appendix.xml +++ b/Doc/Sd1/appendix.xml @@ -3100,6 +3100,9 @@ Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.372 sec</scree <xi:include href="Exam/2020/Winter_1/exam.xml" xpointer="element(/1)" ns:idfixup="auto"/> + <xi:include href="Exam/2020/Winter_2/exam.xml" xpointer="element(/1)" + ns:idfixup="auto"/> + <xi:include href="Exam/2020/Summer/exam.xml" xpointer="element(/1)" ns:idfixup="auto"/> diff --git a/Klausuren/Sd1/2020winter/Second/Exam/pom.xml b/Klausuren/Sd1/2020winter/Second/Exam/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..9a95680774bd6d88bc7a1556fa808b4f567c4fe4 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/pom.xml @@ -0,0 +1,120 @@ +<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.mi.sd1</groupId> + <artifactId>sd1_2020winter_exam2</artifactId> + <version>0.9</version> + <packaging>jar</packaging> + + <name>sd1_2020winter_exam2</name> + + <url>https://freedocs.mi.hdm-stuttgart.de/sd1_sect_mavenCli.html</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <repositories> + <repository> + <id>hdm-mi-internal-maven-repo</id> + <url>https://maven.mi.hdm-stuttgart.de/nexus/repository/mi-maven</url> + </repository> + </repositories> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.13</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <version>2.13.3</version> + </dependency> + + <dependency> + <groupId>de.hdm_stuttgart.mi.exam</groupId> + <artifactId>unitmarking</artifactId> + <version>1.1</version> + </dependency> + + </dependencies> + + <build> + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.1</version> + <configuration> + <source>11</source> + <target>11</target> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>3.2.0</version> + <configuration> + <doclint>none</doclint> + <show>public</show> + <javaApiLinks> + <property> + <name>api_11</name> + <value>https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-15-doc/api/</value> + </property> + </javaApiLinks> + + <additionalOptions> + <additionalOption>-html5 --allow-script-in-comments</additionalOption> + </additionalOptions> + <nohelp>true</nohelp> + <header><![CDATA[ + <script type="text/javascript" + src="https://freedocs.mi.hdm-stuttgart.de/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> + <script type="text/javascript" + src="https://freedocs.mi.hdm-stuttgart.de/lib/mi/jdocSupplement.js"></script> + <link rel="stylesheet" href="https://freedocs.mi.hdm-stuttgart.de/lib/mi/jdocSupplement.css"> + <link rel="stylesheet" href="https://freedocs.mi.hdm-stuttgart.de/lib/highlight.js/styles/idea.css"> + <script src="https://freedocs.mi.hdm-stuttgart.de/lib/highlight.js/highlight.js"></script> + <script type="text/javascript">hljs.initHighlightingOnLoad();</script>]]> + </header> + <javadocExecutable>${java.home}/bin/javadoc</javadocExecutable> + </configuration> + </plugin> + + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <version>3.3.0</version> + + <configuration> + <descriptors> + <descriptor>src/main/assembly/assembly.xml</descriptor> + </descriptors> + </configuration> + <executions> + <execution> + <id>make-assembly</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <archive> + <manifest> + <mainClass>de.hdm_stuttgart.mi.sd1.test.ShowReachedPoints</mainClass> + </manifest> + </archive> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/main/assembly/assembly.xml b/Klausuren/Sd1/2020winter/Second/Exam/src/main/assembly/assembly.xml new file mode 100644 index 0000000000000000000000000000000000000000..85268e2965620878373d76337f524d8785fd0e1f --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/main/assembly/assembly.xml @@ -0,0 +1,36 @@ +<assembly + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> + <id>fat-tests</id> + <formats> + <format>jar</format> + </formats> + <includeBaseDirectory>false</includeBaseDirectory> + <dependencySets> + <dependencySet> + <outputDirectory/> + <useProjectArtifact>true</useProjectArtifact> + <unpack>true</unpack> + <scope>test</scope> + </dependencySet> + </dependencySets> + <fileSets> + <fileSet> + <directory>${project.build.directory}/test-classes</directory> + <outputDirectory/> + <includes> + <include>**/*.class</include> + </includes> + <useDefaultExcludes>true</useDefaultExcludes> + </fileSet> + <fileSet> + <directory>${project.build.directory}/classes</directory> + <outputDirectory/> + <includes> + <include>**/*.class</include> + </includes> + <useDefaultExcludes>true</useDefaultExcludes> + </fileSet> + </fileSets> +</assembly> \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_1_Grade.java b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_1_Grade.java new file mode 100644 index 0000000000000000000000000000000000000000..ec9eed2eee291b5cefd2604445bf57a1d948f99f --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_1_Grade.java @@ -0,0 +1,69 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +import de.hdm_stuttgart.mi.sd1.task1.model.Employee; + +/** + * <p>Student grade and overall status.</p> + */ +public class _1_Grade { + + /** + * <p>Create an individual student's overall success exam status message.</p> + * + * <p>First year students are supposed to take three exams e.g. Geometry, Algebra, and Physics. Each possible + * grade outcome ranges from 1 (very good) to 6 (insufficient).</p> + * + * <p>This method creates an overall message describing the student's performance based on + * the three grades' average:</p> + * + * <table class="goikTableDefaults"> + * <tbody> + * <tr> + * <th>Grade average</th> + * <th>Status text</th> + * </tr> + * <tr> + * <td>2 (inclusive) or better</td> + * <td><code>"Your average score is 2 or better, good job!"</code></td> + * </tr> + * + * <tr> + * <td>In between 2 (exclusive) and 3 (inclusive)</td> + * <td><code>"Your average score is 3 or better, you need to work harder!"</code></td> + * </tr> + * + * <tr> + * <td>Otherwise</td> + * <td><code>"You really need to work harder!"</code></td> + * </tr> + * + * </tbody> + * + * </table> + * + * <p>Example: A student having grades 1, 4 and 3 has got an average of 2.66... being within + * ]2, 3] thus receiving <code>"Your average score is 3 or better, you need to work harder!"</code>.</p> + * + * @param grade1 First exam's marking + * @param grade2 Second exam's marking + * @param grade3 Third exam's marking + * @return An informal status message as being described above. + * + * <section class="implementationHints"> + * <h3 class="implementationHints">Caution:</h3> + * + * <p>With respect to unit tests really copy the desired messages: Using e.g. + * <code style="font-weight: bold">"... better,good ..."</code> rather than + * <code style="font-weight: bold">"... better, good ..."</code> + * (missing space character after comma) will cause + * all unit tests to fail.</p> + * </section> + */ + static public String describePersonalSuccess(final int grade1, final int grade2, final int grade3) { + + return "Garbage"; // TODO: Implement me correctly + } + + private _1_Grade(){/* Ignore me: Suppressing default constructor javadoc generation: + javadoc does not include private constructors by default */} +} diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_2_Email.java b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_2_Email.java new file mode 100644 index 0000000000000000000000000000000000000000..ecba32aab5b9fbb5a9ad0453d062304406fc069e --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_2_Email.java @@ -0,0 +1,30 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +import de.hdm_stuttgart.mi.sd1.task2.Sentence; + +/** + * <p>Email helper method.</p> + */ +public class _2_Email { + /** + * <p>Get the username part of an email address.</p> + * + * <p>Example: Given the email <code>Sally@domus.com</code> this method will return <code>Sally</code></p> + * + * @param email A fully qualified valid email address containing exactly one inner <code>@</code> character. + * @return The username part as being described above. + * + * <section class="implementationHints"> + * <h3 class="implementationHints">Hints:</h3> + * + * <p>The {@link String#split(String)} method providing the argument <code>"@"</code> allows for decomposing + * an e-mail address accordingly.</p> + * </section> + */ + static public String getUsername(final String email) { + return "NoIdeaWhoIam"; // TODO: Implement me correctly + } + + private _2_Email(){/* Ignore me: Suppressing default constructor javadoc generation: + javadoc does not include private constructors by default */} +} diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_3_Triangle.java b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_3_Triangle.java new file mode 100644 index 0000000000000000000000000000000000000000..520c10d618d29d4044d4b3e82ecebee353327d28 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_3_Triangle.java @@ -0,0 +1,41 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +/** + * <p>Estimating triangle edge lengths.</p> + */ +public class _3_Triangle { + /** + * <p>Decide whether three straight lines of given positive length values can possibly be arranged + * into a triangle.</p> + * + * <p>Consider the following example triangle:</p> + * + * <object data="doc-files/triangle.svg" type="image/svg+xml"></object> + * + * <p>In this example the three lines' lengths <code style="color:red">a</code>, <code style="color:green">b</code> + * and <code style="color:blue">c</code> may form a triangle. On contrary we consider:</p> + * + * <object data="doc-files/noTriangle.svg" type="image/svg+xml"></object> + * + * <p>In this second example however <code style="color:green">b</code> is larger than + * <code style="color:red">a</code> + <code style="color:blue">c</code>. The three lines thus cannot be + * arranged into a triangle.</p> + * + * <p>Remark: Even if <code style="color:green">b</code> = <code style="color:red">a</code> + + * <code style="color:blue">c</code> holds the result would just be a straight line rather than a proper + * triangle.</p> + * + * @param a First length of a possible triangle + * @param b Second length of a possible triangle + * @param c Third length of a possible triangle + * @return <code>true</code> if the three lines' lengths may be arranged into a triangle, + * <code>false</code> otherwise. + * + */ + static public boolean isTriangleCompatible(final int a, final int b, final int c) { + return true; // TODO: Implement me correctly + } + + private _3_Triangle(){/* Ignore me: Suppressing default constructor javadoc generation: + javadoc does not include private constructors by default */} +} diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Salary.java b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Salary.java new file mode 100644 index 0000000000000000000000000000000000000000..5edfd6a8f686a5a40a403474f26749a7ee21b62c --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Salary.java @@ -0,0 +1,67 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +import de.hdm_stuttgart.mi.sd1.task1.model.Employee; + +/** + * <p>A company's salaries.</p> + */ +public class _4_Salary { + /** + * <p>Compute an employee's salary.</p> + * + * <p>A company pays its employees according to the following rule:</p> + * + * <p>2000€ + 200€ * numberOfKids + 50€ * numberOfYearsEmployed</p> + * + * <p>An employee for example being employed for 10 years and having two kids will earn + * 2000€ + 200€ * 2 + 50€ * 10 = 2900€.</p> + * + * @param numberOfKids The employee's number of kids. + * @param yearsEmployed The number of years being employed. + * @return The salary according to the above stated rule. + */ + static public int getSalary(final int numberOfKids, final int yearsEmployed) { + return 42; // TODO: Implement me correctly + } + + static private int getSalary(final Employee employee) { + return 42; // TODO: Implement me correctly + } + + /** + * <p>Limiting salaries in case of bad financial times.</p> + * + * <p>An employee's regular salary is being defined by {@link #getSalary(int, int)}. Unfortunately sometimes + * the summ of all salaries exceeds the company's financial capabilities.</p> + * + * <p>We consider an example of two employees having salaries of 2000€ and 4000€ respectively. The sum of their + * salaries being 6000 is supposed to exceed the company's limit of 3000 for all salaries. Both salaries will + * be cut by the same fraction of <code style="color:red">3000. / 6000</code> using {@link Math#round(double)} + * if so required. The employees' + * effective salaries will thus be cut to <code>2000 * <span style="color:red">3000. / 6000</span> == 1000</code> and + * <code>4000 * <span style="color:red">3000. / 6000</span> == 2000</code> respectively. In the given example + * rounding is not being required.</p> + * + * @param overallSalaryLimit The company's limit for the sum of all salary payments. + * @param employees An array of employees. Depending on <code>limit</code> their effective salaries may be reduced. + * + * <section class="implementationHints"> + * <h3 class="implementationHints">Hints:</h3> + * <ol> + * <li>You more than likely want to implement {@link #getSalary(int, int)} before working on this one.</li> + * + * <li>As you notice this method does not return anything. Your solution is supposed to modify the + * {@link Employee} instances' salaries being passed by the <code>Employee[]</code> array.</li> + * + * <li>Regarding both fractions and type conversions ({@link Math#round(double)} returns <code>long</code>) + * your solution may require casts.</li> + * </ol> + * </section> + */ + static public void setSalaries(final int overallSalaryLimit, final Employee[] employees) { + // TODO: Implement me correctly + } + + private _4_Salary(){/* Ignore me: Suppressing default constructor javadoc generation: + javadoc does not include private constructors by default */} +} diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/model/Employee.java b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/model/Employee.java new file mode 100644 index 0000000000000000000000000000000000000000..11865fea1f1efdf495a27c54c45329d70e94f11d --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/model/Employee.java @@ -0,0 +1,40 @@ +package de.hdm_stuttgart.mi.sd1.task1.model; + +import de.hdm_stuttgart.mi.sd1.task1._4_Salary; + +/** + * <p><span style="color:red;font-weight: bold">Nothing to be done here!</span> This class is part of + * implementing {@link _4_Salary}.</p> + */ +public class Employee { + + /** + * An employee's number of kids. + */ + public int numberOfKids; + + /** + * The number of years an employee has been employed. + */ + public int yearsEmployed; + + /** + * An employee's salary. + */ + public int salary; + + /** + * <p>Creating an employee computing his/her salary by means of {@link _4_Salary#getSalary(int, int)}.</p> + * + * <p><span style="color:red;font-weight: bold">Nothing to be done here!</span> This class is part of + * implementing {@link _4_Salary}.</p> + * + * @param numberOfKids See {@link #numberOfKids} + * @param yearsEmployed See {@link #yearsEmployed} + */ + public Employee(final int numberOfKids, final int yearsEmployed) { + this.numberOfKids = numberOfKids; + this.yearsEmployed = yearsEmployed; + salary = _4_Salary.getSalary(numberOfKids, yearsEmployed); + } +} diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/model/package-info.java b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/model/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..abae0003c298cbe021835100e345b4a5a271a8c0 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/model/package-info.java @@ -0,0 +1,5 @@ +/** + * This package contains just oe class + */ +package de.hdm_stuttgart.mi.sd1.task1.model; + diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..93c08f78c6484ddc6191c665cb6db085beab36a6 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java @@ -0,0 +1,16 @@ +/** + * This package mostly (if not completely) contains static method skeletons. + * + * <p>The ordering being implied by class names reflects the author's opinion with respect to ascending implementation + * difficulty. Hints:</p> + * + * <ul> + * <li>Run <code>mvn javadoc:javadoc</code> and open the generated index.html in your browser of choice.</li> + * + * <li>Use the corresponding unit tests to check your implementation's consistency and class + * <code>de.hdm_stuttgart.mi.sd1.test.ShowReachedPoints</code> from your project's “unit test†branch.</li> + * + * </ul> + * + */ +package de.hdm_stuttgart.mi.sd1.task1; \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/Sentence.java b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/Sentence.java new file mode 100644 index 0000000000000000000000000000000000000000..9994a144fe94e67dac557b86a98237e74d1003d9 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/Sentence.java @@ -0,0 +1,66 @@ +package de.hdm_stuttgart.mi.sd1.task2; + +/** + * <p>This class provides information about a given sentence.</p> + * + * <p>The following example computes a sentence's:</p> + * + * <ul> + * <li>Number of digits</li> + * <li>Number of letters</li> + * <li>Number of uppercase letters</li> + * <li>Number of lowercase letters</li> + * </ul> + * + * <table class="goikTableDefaults"> + * <tbody> + * <tr> + * <th>Code</th> + * <th>Result</th> + * </tr> + * <tr> + * <td> + * <pre><code class="java"> final Sentence sentence = new Sentence("99 Java exercises."); + * + * System.out.println("Number of digits: " + sentence.getNumberOfDigits()); + * System.out.println("Number of letters: " + sentence.getNumberOfLetters()); + * + * // true and false distinguishes between upper- ond lowercase letter count. + * System.out.println("Number of uppercase letters: " + sentence.getNumberOfLetters(true)); + * System.out.println("Number of lowercase letters: " + sentence.getNumberOfLetters(false));</code></pre> + * </td> + * <td> + * <pre><code class="nohighlight"> Number of digits: 2 + * Number of letters: 13 + * Number of uppercase letters: 1 + * Number of lowercase letters: 12</code></pre> + * </td> + * </tr> + * </tbody> + * + * </table> + * + * <section class="implementationHints"> + * <h3 class="implementationHints">Hints:</h3> + * + * <ul> + * <li><p>The class is yet unimplemented. The above code snippet provides a clue how implement {@link Sentence} + * to satisfy the corresponding unit tests.</p></li> + * <li> + * <p>The following methods / variables may be helpful:</p> + * <ul> + * <li>{@link Character#isDigit(char)}</li> + * <li>{@link Character#isLetter(char)}</li> + * <li>{@link Character#isUpperCase(char)}</li> + * <li>{@link Character#isLowerCase(char)}</li> + * <li>{@link Character#getType(char)}</li> + * <li>{@link Character#DECIMAL_DIGIT_NUMBER} and friends</li> + * </ul> + * </li> + * </ul> + * + * </section> + */ +public class Sentence { + // TODO: Implement me +} diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..86d4b88702a1847400ef0a816c3d174b568dd9ff --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java @@ -0,0 +1,5 @@ +/** + * Years, weeks and days. + * + */ +package de.hdm_stuttgart.mi.sd1.task2; diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/noTriangle.svg b/Klausuren/Sd1/2020winter/Second/Exam/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/noTriangle.svg new file mode 100644 index 0000000000000000000000000000000000000000..381e46300618d6ff2a8da3195045657084f74eba --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/noTriangle.svg @@ -0,0 +1,251 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="99.069183mm" + height="14.752208mm" + viewBox="0 0 99.069176 14.752208" + version="1.1" + id="svg8" + inkscape:version="1.0.2 (1.0.2+r75+1)" + sodipodi:docname="noTriangle.svg"> + <defs + id="defs2"> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend" + style="overflow:visible" + inkscape:isstock="true"> + <path + id="path1448" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" + inkscape:connector-curvature="0" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-9" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-1" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-7" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-0" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-7-3" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-0-6" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-6" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-2" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-1" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-8" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-2" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-02" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="2.8" + inkscape:cx="31.744715" + inkscape:cy="74.697004" + inkscape:document-units="mm" + inkscape:current-layer="layer1" + showgrid="true" + inkscape:window-width="3840" + inkscape:window-height="2096" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:snap-global="true" + inkscape:snap-nodes="true" + inkscape:snap-intersection-paths="true" + inkscape:snap-smooth-nodes="true" + inkscape:snap-midpoints="true" + inkscape:snap-others="true" + inkscape:snap-grids="true" + inkscape:snap-to-guides="true" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" + showguides="false" + inkscape:snap-bbox="true" + inkscape:document-rotation="0"> + <inkscape:grid + type="xygrid" + id="grid10" + units="mm" + spacingx="4.5" + spacingy="4.5" + originx="207.06912" + originy="9.5163878" /> + </sodipodi:namedview> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(207.06921,-159.19822)"> + <path + style="fill:none;stroke:#ff0000;stroke-width:0.705556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m -207.00002,168.71462 22.49998,-4.5" + id="path985" + sodipodi:nodetypes="cc" /> + <path + style="fill:none;stroke:#008000;stroke-width:0.705556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m -207.00002,168.71462 h 99" + id="path985-3" + sodipodi:nodetypes="cc" /> + <path + style="fill:none;stroke:#0000ff;stroke-width:0.705556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m -153.00004,164.21462 h -31.5" + id="path985-6" + sodipodi:nodetypes="cc" /> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';letter-spacing:0px;word-spacing:0px;fill:#ff0000;stroke-width:0.264583" + x="-223.80217" + y="123.95586" + id="text1018" + transform="rotate(-11.097935)" + inkscape:transform-center-x="1.549882" + inkscape:transform-center-y="-1.3353411"><tspan + sodipodi:role="line" + id="tspan1016" + x="-223.80217" + y="123.95586" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';fill:#ff0000;stroke-width:0.264583">a</tspan></text> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';letter-spacing:0px;word-spacing:0px;fill:#008000;stroke-width:0.264583" + x="-157.50922" + y="173.89049" + id="text1022"><tspan + sodipodi:role="line" + id="tspan1020" + x="-157.50922" + y="173.89049" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';fill:#008000;stroke-width:0.264583">b</tspan></text> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';letter-spacing:0px;word-spacing:0px;fill:#0000ff;stroke-width:0.264583" + x="-169.40326" + y="161.56914" + id="text1022-7"><tspan + sodipodi:role="line" + id="tspan1020-5" + x="-169.40326" + y="161.56914" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';fill:#0000ff;stroke-width:0.264583">c</tspan></text> + </g> +</svg> diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/triangle.svg b/Klausuren/Sd1/2020winter/Second/Exam/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/triangle.svg new file mode 100644 index 0000000000000000000000000000000000000000..c339961d160dd589efd1d0e0fe02dda0cd220a5f --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/triangle.svg @@ -0,0 +1,249 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="99.409248mm" + height="37.059013mm" + viewBox="0 0 99.409242 37.059013" + version="1.1" + id="svg8" + inkscape:version="1.0.2 (1.0.2+r75+1)" + sodipodi:docname="triangle.svg"> + <defs + id="defs2"> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend" + style="overflow:visible" + inkscape:isstock="true"> + <path + id="path1448" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" + inkscape:connector-curvature="0" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-9" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-1" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-7" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-0" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-7-3" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-0-6" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-6" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-2" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-1" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-8" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-2" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-02" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="2.8" + inkscape:cx="32.495582" + inkscape:cy="159.00621" + inkscape:document-units="mm" + inkscape:current-layer="layer1" + showgrid="true" + inkscape:window-width="3840" + inkscape:window-height="2096" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:snap-global="true" + inkscape:snap-nodes="true" + inkscape:snap-intersection-paths="true" + inkscape:snap-smooth-nodes="true" + inkscape:snap-midpoints="true" + inkscape:snap-others="true" + inkscape:snap-grids="true" + inkscape:snap-to-guides="true" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" + showguides="false" + inkscape:snap-bbox="true" + inkscape:document-rotation="0"> + <inkscape:grid + type="xygrid" + id="grid10" + units="mm" + spacingx="4.5" + spacingy="4.5" + originx="207.26783" + originy="31.823197" /> + </sodipodi:namedview> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(207.26787,-136.89142)"> + <path + style="fill:none;stroke:#ff0000;stroke-width:0.705556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m -207.00002,168.71462 27,-31.5" + id="path985" /> + <path + style="fill:none;stroke:#008000;stroke-width:0.705556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m -207.00002,168.71462 h 99" + id="path985-3" + sodipodi:nodetypes="cc" /> + <path + style="fill:none;stroke:#0000ff;stroke-width:0.705556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m -108.00002,168.71462 -72,-31.5" + id="path985-6" + sodipodi:nodetypes="cc" /> + <text + xml:space="preserve" + style="font-size:4.23333px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';letter-spacing:0px;word-spacing:0px;fill:#ff0000;stroke-width:0.264583;font-weight:bold;font-style:normal;font-stretch:normal;font-variant:normal;" + x="-241.67957" + y="-48.575127" + id="text1018" + transform="rotate(-48.988314)"><tspan + sodipodi:role="line" + id="tspan1016" + x="-241.67957" + y="-48.575127" + style="fill:#ff0000;stroke-width:0.264583;-inkscape-font-specification:'DejaVu Sans Bold';font-family:'DejaVu Sans';font-weight:bold;font-style:normal;font-stretch:normal;font-variant:normal;">a</tspan></text> + <text + xml:space="preserve" + style="font-size:4.23333px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';letter-spacing:0px;word-spacing:0px;fill:#008000;stroke-width:0.264583;font-weight:bold;font-style:normal;font-stretch:normal;font-variant:normal;" + x="-157.50922" + y="173.89049" + id="text1022"><tspan + sodipodi:role="line" + id="tspan1020" + x="-157.50922" + y="173.89049" + style="fill:#008000;stroke-width:0.264583;-inkscape-font-specification:'DejaVu Sans Bold';font-family:'DejaVu Sans';font-weight:bold;font-style:normal;font-stretch:normal;font-variant:normal;">b</tspan></text> + <text + xml:space="preserve" + style="font-size:4.23333px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';letter-spacing:0px;word-spacing:0px;fill:#0000ff;stroke-width:0.264583;font-weight:bold;font-style:normal;font-stretch:normal;font-variant:normal;" + x="-75.193306" + y="194.02628" + id="text1026" + transform="rotate(23.503858)"><tspan + sodipodi:role="line" + id="tspan1024" + x="-75.193306" + y="194.02628" + style="fill:#0000ff;stroke-width:0.264583;-inkscape-font-specification:'DejaVu Sans Bold';font-family:'DejaVu Sans';font-weight:bold;font-style:normal;font-stretch:normal;font-variant:normal;">c</tspan></text> + </g> +</svg> diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/main/resources/log4j2.xml b/Klausuren/Sd1/2020winter/Second/Exam/src/main/resources/log4j2.xml new file mode 100644 index 0000000000000000000000000000000000000000..130f87a144c4eb0107a846e580c8fa7f5e819fc1 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/main/resources/log4j2.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration> + <Appenders> + <File name="A1" fileName="A1.log" append="false"> + <PatternLayout pattern="%t %-5p %c{2} - %m%n"/> + </File> + <Console name="STDOUT" target="SYSTEM_OUT"> + <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/> + </Console> + </Appenders> + <Loggers> + + <!-- You my want to define class or package level per-logger rules --> + <Logger name="de.hdm_stuttgart.mi.sd1.App" level="debug"> + <AppenderRef ref="A1"/> + </Logger> + <Root level="info"> + <AppenderRef ref="STDOUT"/> + </Root> + </Loggers> +</Configuration> \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/ShowReachedPoints.java b/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/ShowReachedPoints.java new file mode 100644 index 0000000000000000000000000000000000000000..8197b970b6549b1702ef8022a4c88ff6de8b3198 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/ShowReachedPoints.java @@ -0,0 +1,25 @@ +package de.hdm_stuttgart.mi.sd1.test; + +import de.hdm_stuttgart.mi.exam.unitmarking.RunTests; +import de.hdm_stuttgart.mi.sd1.test.task1.*; +import de.hdm_stuttgart.mi.sd1.test.task2.Test_Sentence; + +public class ShowReachedPoints { + + /** + * Revealing total number of reached points fromm all tasks. + * + * @param args Unused + */ + public static void main(String[] args) { + RunTests.exec( + "Task 1" + , Test_1_Grade.class + , Test_2_Email.class + , Test_3_Triangle.class + , Test_4_Salary.class + ); + + RunTests.exec("Task 2", Test_Sentence.class); + } +} \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/ignore_me/ObjectWrapper.java b/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/ignore_me/ObjectWrapper.java new file mode 100644 index 0000000000000000000000000000000000000000..3ea40e6af61c89a681068a861403ec965fb7f0bc --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/ignore_me/ObjectWrapper.java @@ -0,0 +1,169 @@ +package de.hdm_stuttgart.mi.sd1.test.ignore_me; + +import org.junit.Assert; + +import java.lang.reflect.*; +import java.util.Arrays; +import java.util.stream.Collectors; + +public class ObjectWrapper<T> { + + private final Class classz; + private final T instance; + + static public void assertFinal(final Class classZ, final String fieldName) { + try { + final int modifier = classZ.getDeclaredField(fieldName).getModifiers(); + Assert.assertTrue("»" + fieldName + "« can be modified, no immutable!", Modifier.isFinal(modifier)); + + } catch (NoSuchFieldException e) { + Assert.fail("No such field »" + fieldName + "«"); + } + } + + public ObjectWrapper(final Class<T> classz, final Object ... parameter) { + this.classz = classz; + T tmpInstance = null; + final Constructor<?>[] candidates = Arrays. + stream(classz.getConstructors()). + filter(c -> matchesArgumentList(c, parameter)). + toArray(Constructor<?>[]::new); + if (0 == candidates.length) { + Assert.fail("No suitable constructor in class »" + classz.getName() + "« matching arguments »(" + + Arrays.stream(parameter).map(Object::toString).collect(Collectors.joining(", ")) + + ")«"); + } else if (1 < candidates.length) { + Assert.fail("Multiple constructor matches due to ambiguous signature"); + } else { + try { + tmpInstance = (T) candidates[0].newInstance( + Arrays.stream(parameter).toArray()); + } catch (Exception e) { + Assert.fail("Unable to instantiate instance of class »" + classz.getName() + "«: "+ e); + } + } + instance = tmpInstance; + } + + public <R> void assertFieldExists(final Class<R> valueType, final String name) { + try { + final Field field = classz.getField(name); + if (!valueType.equals(field.getType())) { + Assert.fail("Field »" + name + "« in class »" + classz.getName() + "« is not of type »" + + valueType.getName() + "«"); + } + } catch (final NoSuchFieldException e) { + Assert.fail("No such field »" + name + "« in class »" + classz.getName() + "«"); + } + } + + public <R> R get(final Class<R> valueType, final String name) { + + try { + final Field field = classz.getField(name); + if (valueType.equals(field.getType())) { + return (R) field.get(instance); + } else { + Assert.fail("Field »" + name + "« in class »" + classz.getName() + "« is not of type »" + + valueType.getName() + "«"); + } + } catch (final NoSuchFieldException e) { + Assert.fail("No such field »" + name + "« in class »" + classz.getName() + "«"); + } catch (final IllegalAccessException e) { + Assert.fail("Unable to access field »" + name + "« in class »" + classz.getName() + "«: " + e.getMessage()); + } + return null; + } + public void set(final String name, final Object value) { + + try { + final Field field = classz.getField(name); + final Class argumentType = value.getClass(); + if (field.getType().equals(argumentType) || + field.getType().equals(getPrimitiveType(argumentType))){ + field.set(instance, value); + } else { + Assert.fail("Field »" + name + "« in class »" + classz.getName() + "« is not of type »" + + argumentType.getName() + "«"); + } + } catch (final NoSuchFieldException e) { + Assert.fail("No such field »" + name + "« in class »" + classz.getName() + "«"); + } catch (final IllegalAccessException e) { + Assert.fail("Unable to access field »" + name + "« in class »" + classz.getName() + "«: " + e.getMessage()); + } + } + + public <R> R invoke(final Class<R> returnType, final String name, final Object ... parameter) { + + final Method[] candidates = Arrays. + stream(classz.getMethods()). + filter(m-> m.getName().equals(name) && matchesArgumentList(m, parameter)). + toArray(Method[]::new); + + if (0 == candidates.length) { + Assert.fail("No suitable method found"); + } else if (1 < candidates.length) { + Assert.fail("Multiple method matches due to ambigious signature"); + } else { + final Method method = candidates[0]; + if (method.getReturnType().equals(returnType)) { + try { + return (R) method.invoke(instance, parameter); + } catch (final Exception e) { + Assert.fail("Unable to execute method: " + e); + } + } else { + Assert.fail("Method »" + method.getName() + "« does not have return type »" + returnType.getName() + "«"); + } + } + return null; + } + + /** + * Check for a given array of objects matching an {@link Executable}'s argument list. + * + * @param executable + * @param parameter + * @return <code>true</code> if parameters match the {@link Executable}'s argument list, <code>false</code> + * otherwise. + */ + private boolean matchesArgumentList(final Executable executable, final Object ... parameter) { + + if (executable.getParameterCount() != parameter.length) { + return false; + } else { + final Class<?>[] formalArgumentTypes = executable.getParameterTypes(); + for (int i = 0; i < formalArgumentTypes.length; i++) { + final Class parametersClass = parameter[i].getClass(); + + if (!formalArgumentTypes[i].equals(parametersClass) && + !formalArgumentTypes[i].equals(getPrimitiveType(parametersClass))) { + return false; + } + } + } + return true; + } + + static private Class<?> getPrimitiveType (final Class<?> in) { + if (in.equals(Byte.class)) { + return byte.class; + } else if (in.equals(Short.class)) { + return short.class; + } else if (in.equals(Integer.class)) { + return int.class; + } else if (in.equals(Long.class)) { + return long.class; + } else if (in.equals(Float.class)) { + return float.class; + } else if (in.equals(Double.class)) { + return double.class; + } else if (in.equals(Boolean.class)) { + return boolean.class; + } else if (in.equals(Character.class)) { + return char.class; + } else { + return in; // Type is no primitive + } + } +} diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_1_Grade.java b/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_1_Grade.java new file mode 100644 index 0000000000000000000000000000000000000000..ab83dce66435fa35b0f758a1f319c7d8517b612a --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_1_Grade.java @@ -0,0 +1,46 @@ +package de.hdm_stuttgart.mi.sd1.test.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task1._1_Grade; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@SuppressWarnings({"UnusedDeclaration"}) +public class Test_1_Grade extends ExaminationTestDefaults { + static public final String + TOP = "Your average score is 2 or better, good job!", + MEDIUM = "Your average score is 3 or better, you need to work harder!", + LOW = "You really need to work harder!"; + + @Test @Marking(points = 15) public void test_100() { + Assert.assertEquals(TOP, _1_Grade.describePersonalSuccess(1, 1, 1)); + Assert.assertEquals(TOP, _1_Grade.describePersonalSuccess(1, 3, 2)); + Assert.assertEquals(TOP, _1_Grade.describePersonalSuccess(3, 1, 1)); + Assert.assertEquals(TOP, _1_Grade.describePersonalSuccess(1, 1, 4)); + Assert.assertEquals(TOP, _1_Grade.describePersonalSuccess(2, 2, 2)); + Assert.assertEquals(TOP, _1_Grade.describePersonalSuccess(2, 2, 2)); + Assert.assertEquals(TOP, _1_Grade.describePersonalSuccess(2, 2, 2)); + Assert.assertEquals(TOP, _1_Grade.describePersonalSuccess(2, 2, 2)); + + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(2, 2, 3)); + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(3, 2, 3)); + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(3, 3, 3)); + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(2, 2, 5)); + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(5, 1, 1)); + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(2, 5, 2)); + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(3, 3, 2)); + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(1, 5, 3)); + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(4, 1, 4)); + + Assert.assertEquals(LOW, _1_Grade.describePersonalSuccess(6, 6, 6)); + Assert.assertEquals(LOW, _1_Grade.describePersonalSuccess(5, 5, 5)); + Assert.assertEquals(LOW, _1_Grade.describePersonalSuccess(4, 4, 2)); + Assert.assertEquals(LOW, _1_Grade.describePersonalSuccess(5, 2, 4)); + Assert.assertEquals(LOW, _1_Grade.describePersonalSuccess(6, 1, 3)); + Assert.assertEquals(LOW, _1_Grade.describePersonalSuccess(2, 5, 3)); + } +} diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_2_Email.java b/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_2_Email.java new file mode 100644 index 0000000000000000000000000000000000000000..2deeeb253f5f8acc7afafc8702e561c0c32203ce --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_2_Email.java @@ -0,0 +1,23 @@ +package de.hdm_stuttgart.mi.sd1.test.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task1._2_Email; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static de.hdm_stuttgart.mi.sd1.task1._2_Email.getUsername; +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@SuppressWarnings({"UnusedDeclaration"}) +public class Test_2_Email extends ExaminationTestDefaults { + + @Test @Marking(points = 14) public void test_100() { + + Assert.assertEquals("jim", getUsername("jim@bean.com")); + Assert.assertEquals("eve", getUsername("eve@paradise.de")); + Assert.assertEquals("Jolly", getUsername("Jolly@jumper.com")); + + } +} diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_3_Triangle.java b/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_3_Triangle.java new file mode 100644 index 0000000000000000000000000000000000000000..10629694f8205159a20483857b68e62834c52c94 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_3_Triangle.java @@ -0,0 +1,37 @@ +package de.hdm_stuttgart.mi.sd1.test.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task1._3_Triangle; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class Test_3_Triangle extends ExaminationTestDefaults { + + @Test @Marking(points = 10) + public void test_100_one() { + Assert.assertTrue(_3_Triangle.isTriangleCompatible(3, 4, 5)); + Assert.assertTrue(_3_Triangle.isTriangleCompatible(5, 3, 4)); + Assert.assertTrue(_3_Triangle.isTriangleCompatible(4, 5, 3)); + Assert.assertTrue(_3_Triangle.isTriangleCompatible(4, 3, 5)); + Assert.assertTrue(_3_Triangle.isTriangleCompatible(3, 5, 4)); + Assert.assertTrue(_3_Triangle.isTriangleCompatible(5, 4, 3)); + + Assert.assertFalse(_3_Triangle.isTriangleCompatible(4, 10, 5)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(10, 5, 4)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(5, 4, 10)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(4, 5, 10)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(5, 10, 4)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(10, 4, 5)); + + Assert.assertFalse(_3_Triangle.isTriangleCompatible(1, 2, 3)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(2, 3, 1)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(3, 1, 2)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(1, 3, 2)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(3, 2, 1)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(2, 1, 3)); + } +} \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_4_Salary.java b/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_4_Salary.java new file mode 100644 index 0000000000000000000000000000000000000000..e3a73be810b7c310c2c1f346c46daa1d2fb23218 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_4_Salary.java @@ -0,0 +1,143 @@ +package de.hdm_stuttgart.mi.sd1.test.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task1.model.Employee; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static de.hdm_stuttgart.mi.sd1.task1._4_Salary.getSalary; +import static de.hdm_stuttgart.mi.sd1.task1._4_Salary.setSalaries; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class Test_4_Salary extends ExaminationTestDefaults { + + @Test @Marking(points = 6) + public void test_100() { + Assert.assertEquals(2000, getSalary(0, 0)); + } + + @Test @Marking(points = 1) + public void test_500_empty() { + setSalaries(30000, new Employee[0]); + setSalaries(0, new Employee[0]); + } + + @Test @Marking(points = 2) + public void test_520_single() { + Employee[] employees = {new Employee(2,10)}; + Assert.assertEquals(2900, employees[0].salary); + + {// Companies payment limit is well above sum of all salaries + setSalaries(3000, employees); + Assert.assertEquals(2900, employees[0].salary); + } + + {// Companies payment limit matches sum of all salaries + setSalaries(2900, employees); + Assert.assertEquals(2900, employees[0].salary); + } + + for (short i = 0; i < 2900; i++) {// Companies payment limit beneath sum of all salaries + setSalaries( i, employees); + Assert.assertEquals("Payment limit " + i + ":", i, employees[0].salary); + } + } + + @Test + public void test_540_standard() { + + final Employee[] employees = new Employee[10]; + for (byte i = 0; i < employees.length; i++) { + employees[i] = new Employee(0, 0); + } + + {// Companies payment limit is well above sum of all salaries + setSalaries(30000, employees); + for (final Employee e : employees) { + Assert.assertEquals(2000, e.salary); + } + } + + {// Companies payment limit matches sum of all salaries + setSalaries(20000, employees); + for (final Employee e : employees) { + Assert.assertEquals(2000, e.salary); + } + } + + {// Companies payment limit slightly below sum of all salaries. + setSalaries(19999, employees); + for (final Employee e : employees) { + Assert.assertEquals(2000, e.salary); + } + } + + {// Companies payment limit just half of all salaries' sum + setSalaries(10000, employees); + for (final Employee e : employees) { + Assert.assertEquals(1000, e.salary); + } + } + + {// Companies payment limit just quarter of all salaries' sum + setSalaries(5000, employees); + for (final Employee e : employees) { + Assert.assertEquals(500, e.salary); + } + } + {// Bad year: No salaries + setSalaries(0, employees); + for (final Employee e : employees) { + Assert.assertEquals(0, e.salary); + } + } + } + + @Test + public void test_600_mixed() { + + final Employee[] employees = new Employee[10]; + + for (byte i = 0; i < employees.length; i++) { + employees[i] = new Employee(i, 2 * i); + } + + {// Companies payment limit is well above sum of all salaries + setSalaries(40000, employees); + for (byte i = 0; i < employees.length; i++) { + Assert.assertEquals("Employee index " + i + ":", 2000 + 300 * i, employees[i].salary); + } + } + + {// Companies payment limit matches sum of all salaries + setSalaries(33500, employees); + for (byte i = 0; i < employees.length; i++) { + Assert.assertEquals("Employee index " + i + ":", 2000 + 300 * i, employees[i].salary); + } + } + + {// Companies payment limit just half of sum of all salaries + setSalaries(33500 / 2, employees); + for (byte i = 0; i < employees.length; i++) { + Assert.assertEquals("Employee index " + i + ":", 1000 + 150 * i, employees[i].salary); + } + } + + {// Companies payment limit just 1% of sum of all salaries + setSalaries(33500 / 100, employees); + for (byte i = 0; i < employees.length; i++) { + Assert.assertEquals("Employee index " + i + ":", 20 + 3 * i, employees[i].salary); + } + } + + {// Bad year: No salaries + setSalaries(0, employees); + for (byte i = 0; i < employees.length; i++) { + Assert.assertEquals("Employee index " + i + ":", 0, employees[i].salary); + } + } + } +} diff --git a/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task2/Test_Sentence.java b/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task2/Test_Sentence.java new file mode 100644 index 0000000000000000000000000000000000000000..e8a97ce404c6f622acb809e0d71fcd4aec35fb34 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Exam/src/test/java/de/hdm_stuttgart/mi/sd1/test/task2/Test_Sentence.java @@ -0,0 +1,80 @@ +package de.hdm_stuttgart.mi.sd1.test.task2; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task2.Sentence; + +import de.hdm_stuttgart.mi.sd1.test.ignore_me.ObjectWrapper; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class Test_Sentence extends ExaminationTestDefaults { + + @Test @Marking(points = 5) public void test_100_empty() { + { + final ObjectWrapper<Sentence> s = new ObjectWrapper<>(Sentence.class, ""); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfDigits")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", true)); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", false)); + } + { + final ObjectWrapper<Sentence> s = new ObjectWrapper<>(Sentence.class, " "); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfDigits")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", true)); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", false)); + } + } + @Test @Marking(points = 5) public void test_120_justDigits() { + { + final ObjectWrapper<Sentence> s = new ObjectWrapper<>(Sentence.class, " 3 "); + Assert.assertEquals(1, (int) s.invoke(int.class, "getNumberOfDigits")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", true)); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", false)); + } + { + final ObjectWrapper<Sentence> s = new ObjectWrapper<>(Sentence.class, "425"); + Assert.assertEquals(3, (int) s.invoke(int.class, "getNumberOfDigits")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", true)); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", false)); + } + { + final ObjectWrapper<Sentence> s = new ObjectWrapper<>(Sentence.class, " 3 54 112 "); + Assert.assertEquals(6, (int) s.invoke(int.class, "getNumberOfDigits")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", true)); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", false)); + } + } + @Test @Marking(points = 5) public void test_200_justLetter() { + { + final ObjectWrapper<Sentence> s = new ObjectWrapper<>(Sentence.class, " x "); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfDigits")); + Assert.assertEquals(1, (int) s.invoke(int.class, "getNumberOfLetters")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", true)); + Assert.assertEquals(1, (int) s.invoke(int.class, "getNumberOfLetters", false)); + } + { + final ObjectWrapper<Sentence> s = new ObjectWrapper<>(Sentence.class, "Just another day in Paradise"); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfDigits")); + Assert.assertEquals(24, (int) s.invoke(int.class, "getNumberOfLetters")); + Assert.assertEquals(2, (int) s.invoke(int.class, "getNumberOfLetters", true)); + Assert.assertEquals(22, (int) s.invoke(int.class, "getNumberOfLetters", false)); + } + } + @Test @Marking(points = 5) public void test_300_mixed() { + { + final ObjectWrapper<Sentence> s = new ObjectWrapper<>(Sentence.class, " 50 Ways to leave your lover"); + Assert.assertEquals(2, (int) s.invoke(int.class, "getNumberOfDigits")); + Assert.assertEquals(20, (int) s.invoke(int.class, "getNumberOfLetters")); + Assert.assertEquals(1, (int) s.invoke(int.class, "getNumberOfLetters", true)); + Assert.assertEquals(19, (int) s.invoke(int.class, "getNumberOfLetters", false)); + } + } +} diff --git a/Klausuren/Sd1/2020winter/Second/Solve/pom.xml b/Klausuren/Sd1/2020winter/Second/Solve/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..66e1aa3f25717ddd7afd46002579da8466ce32a3 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/pom.xml @@ -0,0 +1,120 @@ +<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.mi.sd1</groupId> + <artifactId>sd1_2020winter_solve2</artifactId> + <version>0.9</version> + <packaging>jar</packaging> + + <name>sd1_2020winter_solve2</name> + + <url>https://freedocs.mi.hdm-stuttgart.de/sd1_sect_mavenCli.html</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <repositories> + <repository> + <id>hdm-mi-internal-maven-repo</id> + <url>https://maven.mi.hdm-stuttgart.de/nexus/repository/mi-maven</url> + </repository> + </repositories> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.13</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <version>2.13.3</version> + </dependency> + + <dependency> + <groupId>de.hdm_stuttgart.mi.exam</groupId> + <artifactId>unitmarking</artifactId> + <version>1.1</version> + </dependency> + + </dependencies> + + <build> + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.1</version> + <configuration> + <source>11</source> + <target>11</target> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>3.2.0</version> + <configuration> + <doclint>none</doclint> + <show>public</show> + <javaApiLinks> + <property> + <name>api_11</name> + <value>https://freedocs.mi.hdm-stuttgart.de/lib/openjdk-15-doc/api/</value> + </property> + </javaApiLinks> + + <additionalOptions> + <additionalOption>-html5 --allow-script-in-comments</additionalOption> + </additionalOptions> + <nohelp>true</nohelp> + <header><![CDATA[ + <script type="text/javascript" + src="https://freedocs.mi.hdm-stuttgart.de/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> + <script type="text/javascript" + src="https://freedocs.mi.hdm-stuttgart.de/lib/mi/jdocSupplement.js"></script> + <link rel="stylesheet" href="https://freedocs.mi.hdm-stuttgart.de/lib/mi/jdocSupplement.css"> + <link rel="stylesheet" href="https://freedocs.mi.hdm-stuttgart.de/lib/highlight.js/styles/idea.css"> + <script src="https://freedocs.mi.hdm-stuttgart.de/lib/highlight.js/highlight.js"></script> + <script type="text/javascript">hljs.initHighlightingOnLoad();</script>]]> + </header> + <javadocExecutable>${java.home}/bin/javadoc</javadocExecutable> + </configuration> + </plugin> + + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <version>3.3.0</version> + + <configuration> + <descriptors> + <descriptor>src/main/assembly/assembly.xml</descriptor> + </descriptors> + </configuration> + <executions> + <execution> + <id>make-assembly</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <archive> + <manifest> + <mainClass>de.hdm_stuttgart.mi.sd1.test.ShowReachedPoints</mainClass> + </manifest> + </archive> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/main/assembly/assembly.xml b/Klausuren/Sd1/2020winter/Second/Solve/src/main/assembly/assembly.xml new file mode 100644 index 0000000000000000000000000000000000000000..85268e2965620878373d76337f524d8785fd0e1f --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/main/assembly/assembly.xml @@ -0,0 +1,36 @@ +<assembly + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> + <id>fat-tests</id> + <formats> + <format>jar</format> + </formats> + <includeBaseDirectory>false</includeBaseDirectory> + <dependencySets> + <dependencySet> + <outputDirectory/> + <useProjectArtifact>true</useProjectArtifact> + <unpack>true</unpack> + <scope>test</scope> + </dependencySet> + </dependencySets> + <fileSets> + <fileSet> + <directory>${project.build.directory}/test-classes</directory> + <outputDirectory/> + <includes> + <include>**/*.class</include> + </includes> + <useDefaultExcludes>true</useDefaultExcludes> + </fileSet> + <fileSet> + <directory>${project.build.directory}/classes</directory> + <outputDirectory/> + <includes> + <include>**/*.class</include> + </includes> + <useDefaultExcludes>true</useDefaultExcludes> + </fileSet> + </fileSets> +</assembly> \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/SentenceDemo.java b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/SentenceDemo.java new file mode 100644 index 0000000000000000000000000000000000000000..308fa651586f8a43032c40c9c2e2dc054b607e2e --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/SentenceDemo.java @@ -0,0 +1,18 @@ +package de.hdm_stuttgart.mi.sd1.ignore_me; + +import de.hdm_stuttgart.mi.sd1.task2.Sentence; + +public class SentenceDemo { + + public static void main(String[] args) { + + final Sentence sentence = new Sentence("99 Java exercises."); + + System.out.println("Number of digits: " + sentence.getNumberOfDigits()); + System.out.println("Number of letters: " + sentence.getNumberOfLetters()); + + // true and false distinguishes between upper- ond lowercase letter count. + System.out.println("Number of uppercase letters: " + sentence.getNumberOfLetters(true)); + System.out.println("Number of lowercase letters: " + sentence.getNumberOfLetters(false)); + } +} diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/Test.java b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/Test.java new file mode 100644 index 0000000000000000000000000000000000000000..02a6c63b6a416012e8fe189ad4af1c45a23cd2ed --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/ignore_me/Test.java @@ -0,0 +1,20 @@ +package de.hdm_stuttgart.mi.sd1.ignore_me; + +public class Test { + + public static void main(String[] args) { + + int power = 0; + + int digit = 8; + + long product = digit, sum = 0; + int index = 0; + while (sum < Integer.MAX_VALUE) { + sum += product; + product *= digit; + index++; + } + System.out.println(index); + } +} diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_1_Grade.java b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_1_Grade.java new file mode 100644 index 0000000000000000000000000000000000000000..7c10bc76e880414e79363c40ceb0fc72d2f3063a --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_1_Grade.java @@ -0,0 +1,77 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +import de.hdm_stuttgart.mi.sd1.task1.model.Employee; + +/** + * <p>Student grade and overall status.</p> + */ +public class _1_Grade { + + /** + * <p>Create an individual student's overall success exam status message.</p> + * + * <p>First year students are supposed to take three exams e.g. Geometry, Algebra, and Physics. Each possible + * grade outcome ranges from 1 (very good) to 6 (insufficient).</p> + * + * <p>This method creates an overall message describing the student's performance based on + * the three grades' average:</p> + * + * <table class="goikTableDefaults"> + * <tbody> + * <tr> + * <th>Grade average</th> + * <th>Status text</th> + * </tr> + * <tr> + * <td>2 (inclusive) or better</td> + * <td><code>"Your average score is 2 or better, good job!"</code></td> + * </tr> + * + * <tr> + * <td>In between 2 (exclusive) and 3 (inclusive)</td> + * <td><code>"Your average score is 3 or better, you need to work harder!"</code></td> + * </tr> + * + * <tr> + * <td>Otherwise</td> + * <td><code>"You really need to work harder!"</code></td> + * </tr> + * + * </tbody> + * + * </table> + * + * <p>Example: A student having grades 1, 4 and 3 has got an average of 2.66... being within + * ]2, 3] thus receiving <code>"Your average score is 3 or better, you need to work harder!"</code>.</p> + * + * @param grade1 First exam's marking + * @param grade2 Second exam's marking + * @param grade3 Third exam's marking + * @return An informal status message as being described above. + * + * <section class="implementationHints"> + * <h3 class="implementationHints">Caution:</h3> + * + * <p>With respect to unit tests really copy the desired messages: Using e.g. + * <code style="font-weight: bold">"... better,good ..."</code> rather than + * <code style="font-weight: bold">"... better, good ..."</code> + * (missing space character after comma) will cause + * all unit tests to fail.</p> + * </section> + */ + static public String describePersonalSuccess(final int grade1, final int grade2, final int grade3) { + + final int sum = grade1 + grade2 + grade3; + + if (sum <= 6) { + return "Your average score is 2 or better, good job!"; + } else if (sum <= 9) { + return "Your average score is 3 or better, you need to work harder!"; + } else { + return "You really need to work harder!"; + } + } + + private _1_Grade(){/* Ignore me: Suppressing default constructor javadoc generation: + javadoc does not include private constructors by default */} +} diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_2_Email.java b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_2_Email.java new file mode 100644 index 0000000000000000000000000000000000000000..7285c7b72828eb6edeb219e7a54c8452b21621a6 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_2_Email.java @@ -0,0 +1,30 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +import de.hdm_stuttgart.mi.sd1.task2.Sentence; + +/** + * <p>Email helper method.</p> + */ +public class _2_Email { + /** + * <p>Get the username part of an email address.</p> + * + * <p>Example: Given the email <code>Sally@domus.com</code> this method will return <code>Sally</code></p> + * + * @param email A fully qualified valid email address containing exactly one inner <code>@</code> character. + * @return The username part as being described above. + * + * <section class="implementationHints"> + * <h3 class="implementationHints">Hints:</h3> + * + * <p>The {@link String#split(String)} method providing the argument <code>"@"</code> allows for decomposing + * an e-mail address accordingly.</p> + * </section> + */ + static public String getUsername(final String email) { + return email.split("@")[0]; + } + + private _2_Email(){/* Ignore me: Suppressing default constructor javadoc generation: + javadoc does not include private constructors by default */} +} diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_3_Triangle.java b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_3_Triangle.java new file mode 100644 index 0000000000000000000000000000000000000000..1d5c550686a7900ec854e9b9125ef958c44f5bec --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_3_Triangle.java @@ -0,0 +1,41 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +/** + * <p>Estimating triangle edge lengths.</p> + */ +public class _3_Triangle { + /** + * <p>Decide whether three straight lines of given positive length values can possibly be arranged + * into a triangle.</p> + * + * <p>Consider the following example triangle:</p> + * + * <object data="doc-files/triangle.svg" type="image/svg+xml"></object> + * + * <p>In this example the three lines' lengths <code style="color:red">a</code>, <code style="color:green">b</code> + * and <code style="color:blue">c</code> may form a triangle. On contrary we consider:</p> + * + * <object data="doc-files/noTriangle.svg" type="image/svg+xml"></object> + * + * <p>In this second example however <code style="color:green">b</code> is larger than + * <code style="color:red">a</code> + <code style="color:blue">c</code>. The three lines thus cannot be + * arranged into a triangle.</p> + * + * <p>Remark: Even if <code style="color:green">b</code> = <code style="color:red">a</code> + + * <code style="color:blue">c</code> holds the result would just be a straight line rather than a proper + * triangle.</p> + * + * @param a First length of a possible triangle + * @param b Second length of a possible triangle + * @param c Third length of a possible triangle + * @return <code>true</code> if the three lines' lengths may be arranged into a triangle, + * <code>false</code> otherwise. + * + */ + static public boolean isTriangleCompatible(final int a, final int b, final int c) { + return a < b + c && b < a + c && c < a + b; + } + + private _3_Triangle(){/* Ignore me: Suppressing default constructor javadoc generation: + javadoc does not include private constructors by default */} +} diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Salary.java b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Salary.java new file mode 100644 index 0000000000000000000000000000000000000000..d85a6d7108652c39afa77633d8b52cbd80349cb7 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/_4_Salary.java @@ -0,0 +1,77 @@ +package de.hdm_stuttgart.mi.sd1.task1; + +import de.hdm_stuttgart.mi.sd1.task1.model.Employee; + +/** + * <p>A company's salaries.</p> + */ +public class _4_Salary { + /** + * <p>Compute an employee's salary.</p> + * + * <p>A company pays its employees according to the following rule:</p> + * + * <p>2000€ + 200€ * numberOfKids + 50€ * numberOfYearsEmployed</p> + * + * <p>An employee for example being employed for 10 years and having two kids will earn + * 2000€ + 200€ * 2 + 50€ * 10 = 2900€.</p> + * + * @param numberOfKids The employee's number of kids. + * @param yearsEmployed The number of years being employed. + * @return The salary according to the above stated rule. + */ + static public int getSalary(final int numberOfKids, final int yearsEmployed) { + return 2000 + 200 * numberOfKids + yearsEmployed * 50; + } + + static private int getSalary(final Employee employee) { + return getSalary(employee.numberOfKids, employee.yearsEmployed); + } + + /** + * <p>Limiting salaries in case of bad financial times.</p> + * + * <p>An employee's regular salary is being defined by {@link #getSalary(int, int)}. Unfortunately sometimes + * the sum of all salaries exceeds the company's financial capabilities.</p> + * + * <p>We consider an example of two employees having salaries of 2000€ and 4000€ respectively. The sum of their + * salaries being 6000 is supposed to exceed the company's limit of 3000 for all salaries. Both salaries will + * be cut by the same fraction of <code style="color:red">3000. / 6000</code> using {@link Math#round(double)} + * if so required. The employees' + * effective salaries will thus be cut to <code>2000 * <span style="color:red">3000. / 6000</span> == 1000</code> and + * <code>4000 * <span style="color:red">3000. / 6000</span> == 2000</code> respectively. In the given example + * rounding is not being required.</p> + * + * @param overallSalaryLimit The company's limit for the sum of all salary payments. + * @param employees An array of employees. Depending on <code>limit</code> their effective salaries may be reduced. + * + * <section class="implementationHints"> + * <h3 class="implementationHints">Hints:</h3> + * <ol> + * <li>You more than likely want to implement {@link #getSalary(int, int)} before working on this one.</li> + * + * <li>As you notice this method does not return anything. Your solution is supposed to modify the + * {@link Employee} instances' salaries being passed by the <code>Employee[]</code> array.</li> + * + * <li>Regarding both fractions and type conversions ({@link Math#round(double)} returns <code>long</code>) + * your solution may require casts.</li> + * </ol> + * </section> + */ + static public void setSalaries(final int overallSalaryLimit, final Employee[] employees) { + + int salariesSum = 0; + for (final Employee employee: employees) { + salariesSum += employee.salary = getSalary(employee); + } + if (overallSalaryLimit < salariesSum) { + final double factor = ((double)overallSalaryLimit) / salariesSum; + for (final Employee employee: employees) { + employee.salary = (int) Math.round(employee.salary * factor); + } + } + } + + private _4_Salary(){/* Ignore me: Suppressing default constructor javadoc generation: + javadoc does not include private constructors by default */} +} diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/model/Employee.java b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/model/Employee.java new file mode 100644 index 0000000000000000000000000000000000000000..11865fea1f1efdf495a27c54c45329d70e94f11d --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/model/Employee.java @@ -0,0 +1,40 @@ +package de.hdm_stuttgart.mi.sd1.task1.model; + +import de.hdm_stuttgart.mi.sd1.task1._4_Salary; + +/** + * <p><span style="color:red;font-weight: bold">Nothing to be done here!</span> This class is part of + * implementing {@link _4_Salary}.</p> + */ +public class Employee { + + /** + * An employee's number of kids. + */ + public int numberOfKids; + + /** + * The number of years an employee has been employed. + */ + public int yearsEmployed; + + /** + * An employee's salary. + */ + public int salary; + + /** + * <p>Creating an employee computing his/her salary by means of {@link _4_Salary#getSalary(int, int)}.</p> + * + * <p><span style="color:red;font-weight: bold">Nothing to be done here!</span> This class is part of + * implementing {@link _4_Salary}.</p> + * + * @param numberOfKids See {@link #numberOfKids} + * @param yearsEmployed See {@link #yearsEmployed} + */ + public Employee(final int numberOfKids, final int yearsEmployed) { + this.numberOfKids = numberOfKids; + this.yearsEmployed = yearsEmployed; + salary = _4_Salary.getSalary(numberOfKids, yearsEmployed); + } +} diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/model/package-info.java b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/model/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..abae0003c298cbe021835100e345b4a5a271a8c0 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/model/package-info.java @@ -0,0 +1,5 @@ +/** + * This package contains just oe class + */ +package de.hdm_stuttgart.mi.sd1.task1.model; + diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..93c08f78c6484ddc6191c665cb6db085beab36a6 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task1/package-info.java @@ -0,0 +1,16 @@ +/** + * This package mostly (if not completely) contains static method skeletons. + * + * <p>The ordering being implied by class names reflects the author's opinion with respect to ascending implementation + * difficulty. Hints:</p> + * + * <ul> + * <li>Run <code>mvn javadoc:javadoc</code> and open the generated index.html in your browser of choice.</li> + * + * <li>Use the corresponding unit tests to check your implementation's consistency and class + * <code>de.hdm_stuttgart.mi.sd1.test.ShowReachedPoints</code> from your project's “unit test†branch.</li> + * + * </ul> + * + */ +package de.hdm_stuttgart.mi.sd1.task1; \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/Sentence.java b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/Sentence.java new file mode 100644 index 0000000000000000000000000000000000000000..03bd561c9daa07bc02cbb5b30b087be5a3a61442 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/Sentence.java @@ -0,0 +1,100 @@ +package de.hdm_stuttgart.mi.sd1.task2; + +/** + * <p>This class provides information about a given sentence.</p> + * + * <p>The following example computes a sentence's:</p> + * + * <ul> + * <li>Number of digits</li> + * <li>Number of letters</li> + * <li>Number of uppercase letters</li> + * <li>Number of lowercase letters</li> + * </ul> + * + * <table class="goikTableDefaults"> + * <tbody> + * <tr> + * <th>Code</th> + * <th>Result</th> + * </tr> + * <tr> + * <td> + * <pre><code class="java"> final Sentence sentence = new Sentence("99 Java exercises."); + * + * System.out.println("Number of digits: " + sentence.getNumberOfDigits()); + * System.out.println("Number of letters: " + sentence.getNumberOfLetters()); + * + * // true and false distinguishes between upper- ond lowercase letter count. + * System.out.println("Number of uppercase letters: " + sentence.getNumberOfLetters(true)); + * System.out.println("Number of lowercase letters: " + sentence.getNumberOfLetters(false));</code></pre> + * </td> + * <td> + * <pre><code class="nohighlight"> Number of digits: 2 + * Number of letters: 13 + * Number of uppercase letters: 1 + * Number of lowercase letters: 12</code></pre> + * </td> + * </tr> + * </tbody> + * + * </table> + * + * <section class="implementationHints"> + * <h3 class="implementationHints">Hints:</h3> + * + * <ul> + * <li><p>The class is yet unimplemented. The above code snippet provides a clue how implement {@link Sentence} + * to satisfy the corresponding unit tests.</p></li> + * <li> + * <p>The following methods / variables may be helpful:</p> + * <ul> + * <li>{@link Character#isDigit(char)}</li> + * <li>{@link Character#isLetter(char)}</li> + * <li>{@link Character#isUpperCase(char)}</li> + * <li>{@link Character#isLowerCase(char)}</li> + * <li>{@link Character#getType(char)}</li> + * <li>{@link Character#DECIMAL_DIGIT_NUMBER} and friends</li> + * </ul> + * </li> + * </ul> + * + * </section> + */ +public class Sentence { + + final private int numberOfUppercaseLetters, numberOfLowercaseLetters, numberOfDigits; + + public Sentence(final String sentence) { + + int numberOfUppercaseLetters = 0, numberOfLowercaseLetters = 0, numberOfDigits = 0; + + for (final char c: sentence.toCharArray()) { + switch (Character.getType(c)) { + case Character.DECIMAL_DIGIT_NUMBER: + numberOfDigits++; + break; + case Character.UPPERCASE_LETTER: + numberOfUppercaseLetters++; + break; + case Character.LOWERCASE_LETTER: + numberOfLowercaseLetters++; + break; + } + } + this.numberOfUppercaseLetters = numberOfUppercaseLetters; + this.numberOfLowercaseLetters = numberOfLowercaseLetters; + this.numberOfDigits = numberOfDigits; + } + + public int getNumberOfLetters() { + return numberOfUppercaseLetters + numberOfLowercaseLetters; + } + public int getNumberOfLetters(final boolean uppercase) { + return uppercase? numberOfUppercaseLetters : numberOfLowercaseLetters; + } + + public int getNumberOfDigits() { + return numberOfDigits; + } +} diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..86d4b88702a1847400ef0a816c3d174b568dd9ff --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/main/java/de/hdm_stuttgart/mi/sd1/task2/package-info.java @@ -0,0 +1,5 @@ +/** + * Years, weeks and days. + * + */ +package de.hdm_stuttgart.mi.sd1.task2; diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/noTriangle.svg b/Klausuren/Sd1/2020winter/Second/Solve/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/noTriangle.svg new file mode 100644 index 0000000000000000000000000000000000000000..381e46300618d6ff2a8da3195045657084f74eba --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/noTriangle.svg @@ -0,0 +1,251 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="99.069183mm" + height="14.752208mm" + viewBox="0 0 99.069176 14.752208" + version="1.1" + id="svg8" + inkscape:version="1.0.2 (1.0.2+r75+1)" + sodipodi:docname="noTriangle.svg"> + <defs + id="defs2"> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend" + style="overflow:visible" + inkscape:isstock="true"> + <path + id="path1448" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" + inkscape:connector-curvature="0" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-9" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-1" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-7" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-0" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-7-3" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-0-6" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-6" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-2" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-1" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-8" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-2" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-02" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="2.8" + inkscape:cx="31.744715" + inkscape:cy="74.697004" + inkscape:document-units="mm" + inkscape:current-layer="layer1" + showgrid="true" + inkscape:window-width="3840" + inkscape:window-height="2096" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:snap-global="true" + inkscape:snap-nodes="true" + inkscape:snap-intersection-paths="true" + inkscape:snap-smooth-nodes="true" + inkscape:snap-midpoints="true" + inkscape:snap-others="true" + inkscape:snap-grids="true" + inkscape:snap-to-guides="true" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" + showguides="false" + inkscape:snap-bbox="true" + inkscape:document-rotation="0"> + <inkscape:grid + type="xygrid" + id="grid10" + units="mm" + spacingx="4.5" + spacingy="4.5" + originx="207.06912" + originy="9.5163878" /> + </sodipodi:namedview> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(207.06921,-159.19822)"> + <path + style="fill:none;stroke:#ff0000;stroke-width:0.705556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m -207.00002,168.71462 22.49998,-4.5" + id="path985" + sodipodi:nodetypes="cc" /> + <path + style="fill:none;stroke:#008000;stroke-width:0.705556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m -207.00002,168.71462 h 99" + id="path985-3" + sodipodi:nodetypes="cc" /> + <path + style="fill:none;stroke:#0000ff;stroke-width:0.705556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m -153.00004,164.21462 h -31.5" + id="path985-6" + sodipodi:nodetypes="cc" /> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';letter-spacing:0px;word-spacing:0px;fill:#ff0000;stroke-width:0.264583" + x="-223.80217" + y="123.95586" + id="text1018" + transform="rotate(-11.097935)" + inkscape:transform-center-x="1.549882" + inkscape:transform-center-y="-1.3353411"><tspan + sodipodi:role="line" + id="tspan1016" + x="-223.80217" + y="123.95586" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';fill:#ff0000;stroke-width:0.264583">a</tspan></text> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';letter-spacing:0px;word-spacing:0px;fill:#008000;stroke-width:0.264583" + x="-157.50922" + y="173.89049" + id="text1022"><tspan + sodipodi:role="line" + id="tspan1020" + x="-157.50922" + y="173.89049" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';fill:#008000;stroke-width:0.264583">b</tspan></text> + <text + xml:space="preserve" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';letter-spacing:0px;word-spacing:0px;fill:#0000ff;stroke-width:0.264583" + x="-169.40326" + y="161.56914" + id="text1022-7"><tspan + sodipodi:role="line" + id="tspan1020-5" + x="-169.40326" + y="161.56914" + style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';fill:#0000ff;stroke-width:0.264583">c</tspan></text> + </g> +</svg> diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/triangle.svg b/Klausuren/Sd1/2020winter/Second/Solve/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/triangle.svg new file mode 100644 index 0000000000000000000000000000000000000000..c339961d160dd589efd1d0e0fe02dda0cd220a5f --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/main/javadoc/de/hdm_stuttgart/mi/sd1/task1/doc-files/triangle.svg @@ -0,0 +1,249 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="99.409248mm" + height="37.059013mm" + viewBox="0 0 99.409242 37.059013" + version="1.1" + id="svg8" + inkscape:version="1.0.2 (1.0.2+r75+1)" + sodipodi:docname="triangle.svg"> + <defs + id="defs2"> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend" + style="overflow:visible" + inkscape:isstock="true"> + <path + id="path1448" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" + inkscape:connector-curvature="0" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-9" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-1" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-7" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-0" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-5-7-3" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-0-0-6" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-6" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-2" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-1" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-8" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-2" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path1448-02" + style="fill:#ff0000;fill-opacity:1;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="2.8" + inkscape:cx="32.495582" + inkscape:cy="159.00621" + inkscape:document-units="mm" + inkscape:current-layer="layer1" + showgrid="true" + inkscape:window-width="3840" + inkscape:window-height="2096" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:snap-global="true" + inkscape:snap-nodes="true" + inkscape:snap-intersection-paths="true" + inkscape:snap-smooth-nodes="true" + inkscape:snap-midpoints="true" + inkscape:snap-others="true" + inkscape:snap-grids="true" + inkscape:snap-to-guides="true" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" + showguides="false" + inkscape:snap-bbox="true" + inkscape:document-rotation="0"> + <inkscape:grid + type="xygrid" + id="grid10" + units="mm" + spacingx="4.5" + spacingy="4.5" + originx="207.26783" + originy="31.823197" /> + </sodipodi:namedview> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(207.26787,-136.89142)"> + <path + style="fill:none;stroke:#ff0000;stroke-width:0.705556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m -207.00002,168.71462 27,-31.5" + id="path985" /> + <path + style="fill:none;stroke:#008000;stroke-width:0.705556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m -207.00002,168.71462 h 99" + id="path985-3" + sodipodi:nodetypes="cc" /> + <path + style="fill:none;stroke:#0000ff;stroke-width:0.705556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m -108.00002,168.71462 -72,-31.5" + id="path985-6" + sodipodi:nodetypes="cc" /> + <text + xml:space="preserve" + style="font-size:4.23333px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';letter-spacing:0px;word-spacing:0px;fill:#ff0000;stroke-width:0.264583;font-weight:bold;font-style:normal;font-stretch:normal;font-variant:normal;" + x="-241.67957" + y="-48.575127" + id="text1018" + transform="rotate(-48.988314)"><tspan + sodipodi:role="line" + id="tspan1016" + x="-241.67957" + y="-48.575127" + style="fill:#ff0000;stroke-width:0.264583;-inkscape-font-specification:'DejaVu Sans Bold';font-family:'DejaVu Sans';font-weight:bold;font-style:normal;font-stretch:normal;font-variant:normal;">a</tspan></text> + <text + xml:space="preserve" + style="font-size:4.23333px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';letter-spacing:0px;word-spacing:0px;fill:#008000;stroke-width:0.264583;font-weight:bold;font-style:normal;font-stretch:normal;font-variant:normal;" + x="-157.50922" + y="173.89049" + id="text1022"><tspan + sodipodi:role="line" + id="tspan1020" + x="-157.50922" + y="173.89049" + style="fill:#008000;stroke-width:0.264583;-inkscape-font-specification:'DejaVu Sans Bold';font-family:'DejaVu Sans';font-weight:bold;font-style:normal;font-stretch:normal;font-variant:normal;">b</tspan></text> + <text + xml:space="preserve" + style="font-size:4.23333px;line-height:1.25;font-family:'DejaVu Sans';-inkscape-font-specification:'DejaVu Sans Bold';letter-spacing:0px;word-spacing:0px;fill:#0000ff;stroke-width:0.264583;font-weight:bold;font-style:normal;font-stretch:normal;font-variant:normal;" + x="-75.193306" + y="194.02628" + id="text1026" + transform="rotate(23.503858)"><tspan + sodipodi:role="line" + id="tspan1024" + x="-75.193306" + y="194.02628" + style="fill:#0000ff;stroke-width:0.264583;-inkscape-font-specification:'DejaVu Sans Bold';font-family:'DejaVu Sans';font-weight:bold;font-style:normal;font-stretch:normal;font-variant:normal;">c</tspan></text> + </g> +</svg> diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/main/resources/log4j2.xml b/Klausuren/Sd1/2020winter/Second/Solve/src/main/resources/log4j2.xml new file mode 100644 index 0000000000000000000000000000000000000000..130f87a144c4eb0107a846e580c8fa7f5e819fc1 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/main/resources/log4j2.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration> + <Appenders> + <File name="A1" fileName="A1.log" append="false"> + <PatternLayout pattern="%t %-5p %c{2} - %m%n"/> + </File> + <Console name="STDOUT" target="SYSTEM_OUT"> + <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/> + </Console> + </Appenders> + <Loggers> + + <!-- You my want to define class or package level per-logger rules --> + <Logger name="de.hdm_stuttgart.mi.sd1.App" level="debug"> + <AppenderRef ref="A1"/> + </Logger> + <Root level="info"> + <AppenderRef ref="STDOUT"/> + </Root> + </Loggers> +</Configuration> \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/ShowReachedPoints.java b/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/ShowReachedPoints.java new file mode 100644 index 0000000000000000000000000000000000000000..8197b970b6549b1702ef8022a4c88ff6de8b3198 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/ShowReachedPoints.java @@ -0,0 +1,25 @@ +package de.hdm_stuttgart.mi.sd1.test; + +import de.hdm_stuttgart.mi.exam.unitmarking.RunTests; +import de.hdm_stuttgart.mi.sd1.test.task1.*; +import de.hdm_stuttgart.mi.sd1.test.task2.Test_Sentence; + +public class ShowReachedPoints { + + /** + * Revealing total number of reached points fromm all tasks. + * + * @param args Unused + */ + public static void main(String[] args) { + RunTests.exec( + "Task 1" + , Test_1_Grade.class + , Test_2_Email.class + , Test_3_Triangle.class + , Test_4_Salary.class + ); + + RunTests.exec("Task 2", Test_Sentence.class); + } +} \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/ignore_me/ObjectWrapper.java b/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/ignore_me/ObjectWrapper.java new file mode 100644 index 0000000000000000000000000000000000000000..3ea40e6af61c89a681068a861403ec965fb7f0bc --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/ignore_me/ObjectWrapper.java @@ -0,0 +1,169 @@ +package de.hdm_stuttgart.mi.sd1.test.ignore_me; + +import org.junit.Assert; + +import java.lang.reflect.*; +import java.util.Arrays; +import java.util.stream.Collectors; + +public class ObjectWrapper<T> { + + private final Class classz; + private final T instance; + + static public void assertFinal(final Class classZ, final String fieldName) { + try { + final int modifier = classZ.getDeclaredField(fieldName).getModifiers(); + Assert.assertTrue("»" + fieldName + "« can be modified, no immutable!", Modifier.isFinal(modifier)); + + } catch (NoSuchFieldException e) { + Assert.fail("No such field »" + fieldName + "«"); + } + } + + public ObjectWrapper(final Class<T> classz, final Object ... parameter) { + this.classz = classz; + T tmpInstance = null; + final Constructor<?>[] candidates = Arrays. + stream(classz.getConstructors()). + filter(c -> matchesArgumentList(c, parameter)). + toArray(Constructor<?>[]::new); + if (0 == candidates.length) { + Assert.fail("No suitable constructor in class »" + classz.getName() + "« matching arguments »(" + + Arrays.stream(parameter).map(Object::toString).collect(Collectors.joining(", ")) + + ")«"); + } else if (1 < candidates.length) { + Assert.fail("Multiple constructor matches due to ambiguous signature"); + } else { + try { + tmpInstance = (T) candidates[0].newInstance( + Arrays.stream(parameter).toArray()); + } catch (Exception e) { + Assert.fail("Unable to instantiate instance of class »" + classz.getName() + "«: "+ e); + } + } + instance = tmpInstance; + } + + public <R> void assertFieldExists(final Class<R> valueType, final String name) { + try { + final Field field = classz.getField(name); + if (!valueType.equals(field.getType())) { + Assert.fail("Field »" + name + "« in class »" + classz.getName() + "« is not of type »" + + valueType.getName() + "«"); + } + } catch (final NoSuchFieldException e) { + Assert.fail("No such field »" + name + "« in class »" + classz.getName() + "«"); + } + } + + public <R> R get(final Class<R> valueType, final String name) { + + try { + final Field field = classz.getField(name); + if (valueType.equals(field.getType())) { + return (R) field.get(instance); + } else { + Assert.fail("Field »" + name + "« in class »" + classz.getName() + "« is not of type »" + + valueType.getName() + "«"); + } + } catch (final NoSuchFieldException e) { + Assert.fail("No such field »" + name + "« in class »" + classz.getName() + "«"); + } catch (final IllegalAccessException e) { + Assert.fail("Unable to access field »" + name + "« in class »" + classz.getName() + "«: " + e.getMessage()); + } + return null; + } + public void set(final String name, final Object value) { + + try { + final Field field = classz.getField(name); + final Class argumentType = value.getClass(); + if (field.getType().equals(argumentType) || + field.getType().equals(getPrimitiveType(argumentType))){ + field.set(instance, value); + } else { + Assert.fail("Field »" + name + "« in class »" + classz.getName() + "« is not of type »" + + argumentType.getName() + "«"); + } + } catch (final NoSuchFieldException e) { + Assert.fail("No such field »" + name + "« in class »" + classz.getName() + "«"); + } catch (final IllegalAccessException e) { + Assert.fail("Unable to access field »" + name + "« in class »" + classz.getName() + "«: " + e.getMessage()); + } + } + + public <R> R invoke(final Class<R> returnType, final String name, final Object ... parameter) { + + final Method[] candidates = Arrays. + stream(classz.getMethods()). + filter(m-> m.getName().equals(name) && matchesArgumentList(m, parameter)). + toArray(Method[]::new); + + if (0 == candidates.length) { + Assert.fail("No suitable method found"); + } else if (1 < candidates.length) { + Assert.fail("Multiple method matches due to ambigious signature"); + } else { + final Method method = candidates[0]; + if (method.getReturnType().equals(returnType)) { + try { + return (R) method.invoke(instance, parameter); + } catch (final Exception e) { + Assert.fail("Unable to execute method: " + e); + } + } else { + Assert.fail("Method »" + method.getName() + "« does not have return type »" + returnType.getName() + "«"); + } + } + return null; + } + + /** + * Check for a given array of objects matching an {@link Executable}'s argument list. + * + * @param executable + * @param parameter + * @return <code>true</code> if parameters match the {@link Executable}'s argument list, <code>false</code> + * otherwise. + */ + private boolean matchesArgumentList(final Executable executable, final Object ... parameter) { + + if (executable.getParameterCount() != parameter.length) { + return false; + } else { + final Class<?>[] formalArgumentTypes = executable.getParameterTypes(); + for (int i = 0; i < formalArgumentTypes.length; i++) { + final Class parametersClass = parameter[i].getClass(); + + if (!formalArgumentTypes[i].equals(parametersClass) && + !formalArgumentTypes[i].equals(getPrimitiveType(parametersClass))) { + return false; + } + } + } + return true; + } + + static private Class<?> getPrimitiveType (final Class<?> in) { + if (in.equals(Byte.class)) { + return byte.class; + } else if (in.equals(Short.class)) { + return short.class; + } else if (in.equals(Integer.class)) { + return int.class; + } else if (in.equals(Long.class)) { + return long.class; + } else if (in.equals(Float.class)) { + return float.class; + } else if (in.equals(Double.class)) { + return double.class; + } else if (in.equals(Boolean.class)) { + return boolean.class; + } else if (in.equals(Character.class)) { + return char.class; + } else { + return in; // Type is no primitive + } + } +} diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_1_Grade.java b/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_1_Grade.java new file mode 100644 index 0000000000000000000000000000000000000000..ab83dce66435fa35b0f758a1f319c7d8517b612a --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_1_Grade.java @@ -0,0 +1,46 @@ +package de.hdm_stuttgart.mi.sd1.test.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task1._1_Grade; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@SuppressWarnings({"UnusedDeclaration"}) +public class Test_1_Grade extends ExaminationTestDefaults { + static public final String + TOP = "Your average score is 2 or better, good job!", + MEDIUM = "Your average score is 3 or better, you need to work harder!", + LOW = "You really need to work harder!"; + + @Test @Marking(points = 15) public void test_100() { + Assert.assertEquals(TOP, _1_Grade.describePersonalSuccess(1, 1, 1)); + Assert.assertEquals(TOP, _1_Grade.describePersonalSuccess(1, 3, 2)); + Assert.assertEquals(TOP, _1_Grade.describePersonalSuccess(3, 1, 1)); + Assert.assertEquals(TOP, _1_Grade.describePersonalSuccess(1, 1, 4)); + Assert.assertEquals(TOP, _1_Grade.describePersonalSuccess(2, 2, 2)); + Assert.assertEquals(TOP, _1_Grade.describePersonalSuccess(2, 2, 2)); + Assert.assertEquals(TOP, _1_Grade.describePersonalSuccess(2, 2, 2)); + Assert.assertEquals(TOP, _1_Grade.describePersonalSuccess(2, 2, 2)); + + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(2, 2, 3)); + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(3, 2, 3)); + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(3, 3, 3)); + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(2, 2, 5)); + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(5, 1, 1)); + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(2, 5, 2)); + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(3, 3, 2)); + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(1, 5, 3)); + Assert.assertEquals(MEDIUM, _1_Grade.describePersonalSuccess(4, 1, 4)); + + Assert.assertEquals(LOW, _1_Grade.describePersonalSuccess(6, 6, 6)); + Assert.assertEquals(LOW, _1_Grade.describePersonalSuccess(5, 5, 5)); + Assert.assertEquals(LOW, _1_Grade.describePersonalSuccess(4, 4, 2)); + Assert.assertEquals(LOW, _1_Grade.describePersonalSuccess(5, 2, 4)); + Assert.assertEquals(LOW, _1_Grade.describePersonalSuccess(6, 1, 3)); + Assert.assertEquals(LOW, _1_Grade.describePersonalSuccess(2, 5, 3)); + } +} diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_2_Email.java b/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_2_Email.java new file mode 100644 index 0000000000000000000000000000000000000000..2deeeb253f5f8acc7afafc8702e561c0c32203ce --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_2_Email.java @@ -0,0 +1,23 @@ +package de.hdm_stuttgart.mi.sd1.test.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task1._2_Email; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static de.hdm_stuttgart.mi.sd1.task1._2_Email.getUsername; +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@SuppressWarnings({"UnusedDeclaration"}) +public class Test_2_Email extends ExaminationTestDefaults { + + @Test @Marking(points = 14) public void test_100() { + + Assert.assertEquals("jim", getUsername("jim@bean.com")); + Assert.assertEquals("eve", getUsername("eve@paradise.de")); + Assert.assertEquals("Jolly", getUsername("Jolly@jumper.com")); + + } +} diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_3_Triangle.java b/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_3_Triangle.java new file mode 100644 index 0000000000000000000000000000000000000000..10629694f8205159a20483857b68e62834c52c94 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_3_Triangle.java @@ -0,0 +1,37 @@ +package de.hdm_stuttgart.mi.sd1.test.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task1._3_Triangle; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class Test_3_Triangle extends ExaminationTestDefaults { + + @Test @Marking(points = 10) + public void test_100_one() { + Assert.assertTrue(_3_Triangle.isTriangleCompatible(3, 4, 5)); + Assert.assertTrue(_3_Triangle.isTriangleCompatible(5, 3, 4)); + Assert.assertTrue(_3_Triangle.isTriangleCompatible(4, 5, 3)); + Assert.assertTrue(_3_Triangle.isTriangleCompatible(4, 3, 5)); + Assert.assertTrue(_3_Triangle.isTriangleCompatible(3, 5, 4)); + Assert.assertTrue(_3_Triangle.isTriangleCompatible(5, 4, 3)); + + Assert.assertFalse(_3_Triangle.isTriangleCompatible(4, 10, 5)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(10, 5, 4)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(5, 4, 10)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(4, 5, 10)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(5, 10, 4)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(10, 4, 5)); + + Assert.assertFalse(_3_Triangle.isTriangleCompatible(1, 2, 3)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(2, 3, 1)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(3, 1, 2)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(1, 3, 2)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(3, 2, 1)); + Assert.assertFalse(_3_Triangle.isTriangleCompatible(2, 1, 3)); + } +} \ No newline at end of file diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_4_Salary.java b/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_4_Salary.java new file mode 100644 index 0000000000000000000000000000000000000000..abd4fa0e1dc35de3925e43380a634857e5275778 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task1/Test_4_Salary.java @@ -0,0 +1,143 @@ +package de.hdm_stuttgart.mi.sd1.test.task1; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task1.model.Employee; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import static de.hdm_stuttgart.mi.sd1.task1._4_Salary.getSalary; +import static de.hdm_stuttgart.mi.sd1.task1._4_Salary.setSalaries; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class Test_4_Salary extends ExaminationTestDefaults { + + @Test @Marking(points = 4) + public void test_100() { + Assert.assertEquals(2000, getSalary(0, 0)); + } + + @Test @Marking(points = 4) + public void test_500_empty() { + setSalaries(30000, new Employee[0]); + setSalaries(0, new Employee[0]); + } + + @Test + public void test_520_single() { + Employee[] employees = {new Employee(2,10)}; + Assert.assertEquals(2900, employees[0].salary); + + {// Companies payment limit is well above sum of all salaries + setSalaries(3000, employees); + Assert.assertEquals(2900, employees[0].salary); + } + + {// Companies payment limit matches sum of all salaries + setSalaries(2900, employees); + Assert.assertEquals(2900, employees[0].salary); + } + + for (short i = 0; i < 2900; i++) {// Companies payment limit beneath sum of all salaries + setSalaries( i, employees); + Assert.assertEquals("Payment limit " + i + ":", i, employees[0].salary); + } + } + + @Test + public void test_540_standard() { + + final Employee[] employees = new Employee[10]; + for (byte i = 0; i < employees.length; i++) { + employees[i] = new Employee(0, 0); + } + + {// Companies payment limit is well above sum of all salaries + setSalaries(30000, employees); + for (final Employee e : employees) { + Assert.assertEquals(2000, e.salary); + } + } + + {// Companies payment limit matches sum of all salaries + setSalaries(20000, employees); + for (final Employee e : employees) { + Assert.assertEquals(2000, e.salary); + } + } + + {// Companies payment limit slightly below sum of all salaries. + setSalaries(19999, employees); + for (final Employee e : employees) { + Assert.assertEquals(2000, e.salary); + } + } + + {// Companies payment limit just half of all salaries' sum + setSalaries(10000, employees); + for (final Employee e : employees) { + Assert.assertEquals(1000, e.salary); + } + } + + {// Companies payment limit just quarter of all salaries' sum + setSalaries(5000, employees); + for (final Employee e : employees) { + Assert.assertEquals(500, e.salary); + } + } + {// Bad year: No salaries + setSalaries(0, employees); + for (final Employee e : employees) { + Assert.assertEquals(0, e.salary); + } + } + } + + @Test + public void test_600_mixed() { + + final Employee[] employees = new Employee[10]; + + for (byte i = 0; i < employees.length; i++) { + employees[i] = new Employee(i, 2 * i); + } + + {// Companies payment limit is well above sum of all salaries + setSalaries(40000, employees); + for (byte i = 0; i < employees.length; i++) { + Assert.assertEquals("Employee index " + i + ":", 2000 + 300 * i, employees[i].salary); + } + } + + {// Companies payment limit matches sum of all salaries + setSalaries(33500, employees); + for (byte i = 0; i < employees.length; i++) { + Assert.assertEquals("Employee index " + i + ":", 2000 + 300 * i, employees[i].salary); + } + } + + {// Companies payment limit just half of sum of all salaries + setSalaries(33500 / 2, employees); + for (byte i = 0; i < employees.length; i++) { + Assert.assertEquals("Employee index " + i + ":", 1000 + 150 * i, employees[i].salary); + } + } + + {// Companies payment limit just 1% of sum of all salaries + setSalaries(33500 / 100, employees); + for (byte i = 0; i < employees.length; i++) { + Assert.assertEquals("Employee index " + i + ":", 20 + 3 * i, employees[i].salary); + } + } + + {// Bad year: No salaries + setSalaries(0, employees); + for (byte i = 0; i < employees.length; i++) { + Assert.assertEquals("Employee index " + i + ":", 0, employees[i].salary); + } + } + } +} diff --git a/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task2/Test_Sentence.java b/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task2/Test_Sentence.java new file mode 100644 index 0000000000000000000000000000000000000000..e8a97ce404c6f622acb809e0d71fcd4aec35fb34 --- /dev/null +++ b/Klausuren/Sd1/2020winter/Second/Solve/src/test/java/de/hdm_stuttgart/mi/sd1/test/task2/Test_Sentence.java @@ -0,0 +1,80 @@ +package de.hdm_stuttgart.mi.sd1.test.task2; + +import de.hdm_stuttgart.mi.exam.unitmarking.ExaminationTestDefaults; +import de.hdm_stuttgart.mi.exam.unitmarking.Marking; +import de.hdm_stuttgart.mi.sd1.task2.Sentence; + +import de.hdm_stuttgart.mi.sd1.test.ignore_me.ObjectWrapper; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class Test_Sentence extends ExaminationTestDefaults { + + @Test @Marking(points = 5) public void test_100_empty() { + { + final ObjectWrapper<Sentence> s = new ObjectWrapper<>(Sentence.class, ""); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfDigits")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", true)); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", false)); + } + { + final ObjectWrapper<Sentence> s = new ObjectWrapper<>(Sentence.class, " "); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfDigits")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", true)); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", false)); + } + } + @Test @Marking(points = 5) public void test_120_justDigits() { + { + final ObjectWrapper<Sentence> s = new ObjectWrapper<>(Sentence.class, " 3 "); + Assert.assertEquals(1, (int) s.invoke(int.class, "getNumberOfDigits")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", true)); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", false)); + } + { + final ObjectWrapper<Sentence> s = new ObjectWrapper<>(Sentence.class, "425"); + Assert.assertEquals(3, (int) s.invoke(int.class, "getNumberOfDigits")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", true)); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", false)); + } + { + final ObjectWrapper<Sentence> s = new ObjectWrapper<>(Sentence.class, " 3 54 112 "); + Assert.assertEquals(6, (int) s.invoke(int.class, "getNumberOfDigits")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", true)); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", false)); + } + } + @Test @Marking(points = 5) public void test_200_justLetter() { + { + final ObjectWrapper<Sentence> s = new ObjectWrapper<>(Sentence.class, " x "); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfDigits")); + Assert.assertEquals(1, (int) s.invoke(int.class, "getNumberOfLetters")); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfLetters", true)); + Assert.assertEquals(1, (int) s.invoke(int.class, "getNumberOfLetters", false)); + } + { + final ObjectWrapper<Sentence> s = new ObjectWrapper<>(Sentence.class, "Just another day in Paradise"); + Assert.assertEquals(0, (int) s.invoke(int.class, "getNumberOfDigits")); + Assert.assertEquals(24, (int) s.invoke(int.class, "getNumberOfLetters")); + Assert.assertEquals(2, (int) s.invoke(int.class, "getNumberOfLetters", true)); + Assert.assertEquals(22, (int) s.invoke(int.class, "getNumberOfLetters", false)); + } + } + @Test @Marking(points = 5) public void test_300_mixed() { + { + final ObjectWrapper<Sentence> s = new ObjectWrapper<>(Sentence.class, " 50 Ways to leave your lover"); + Assert.assertEquals(2, (int) s.invoke(int.class, "getNumberOfDigits")); + Assert.assertEquals(20, (int) s.invoke(int.class, "getNumberOfLetters")); + Assert.assertEquals(1, (int) s.invoke(int.class, "getNumberOfLetters", true)); + Assert.assertEquals(19, (int) s.invoke(int.class, "getNumberOfLetters", false)); + } + } +}