Commit 0c9c52a5 authored by Dr. Martin Goik's avatar Dr. Martin Goik

Exam Sd1 2020

parent d4e1ed12
<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_2020summer_exam</artifactId>
<version>0.9</version>
<packaging>jar</packaging>
<name>sd1_2020summer_exam</name>
<url>https://freedocs.mi.hdm-stuttgart.de/sd1_sect_mavenCli.html</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mathjax.home><![CDATA['<script type="text/javascript" src="https://freedocs.mi.hdm-stuttgart.de/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>']]></mathjax.home>
</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.1.1</version>
<configuration>
<javaApiLinks>
<property>
<name>api_11</name>
<value>https://klausur.mi.hdm-stuttgart.de/doc/openjdk-11-doc/api/</value>
</property>
</javaApiLinks>
<stylesheetfile>localstyles.css</stylesheetfile>
<additionalOptions>
<additionalOption>-html5 --allow-script-in-comments -header ${mathjax.home}</additionalOption>
</additionalOptions>
<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>
<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
package de.hdm_stuttgart.mi.sd1.task1;
public class _1_EqualValues {
/**
* <p>Check if three values are mutually equal to each other. Examples:</p>
*
* <ul>
* <li>a = 3, b = 3, c = 3: result is <code>true</code>.</li>
* <li>a = 2, b = 2, c = 6: b differs from c, result is thus false.</li>
* </ul>
*
* @param a First value
* @param b Second value
* @param c Third value
* @return true if all three arguments share the same value, false otherwise
*/
static public boolean equal(int a, int b, int c) {
return false; // TODO: Implement me correctly
}
private _1_EqualValues(){/* Ignore me: Suppressing default constructor javadoc generation:
javadoc does not include private constructors by default */}
}
package de.hdm_stuttgart.mi.sd1.task1;
public class _2_DifferentValues {
/**
* <p>Check if three values are mutually different from each other. Examples:</p>
*
* <ul>
* <li>a = 3, b = 4, c = 5: All three values are different, result is <code>true</code>.</li>
* <li>a = 2, b = 5, c = 2: a is equal to c, result is thus false.</li>
* </ul>
*
* @param a First value
* @param b Second value
* @param c Third value
* @return false, if two or all arguments are equal, true otherwise
*/
static public boolean different(int a, int b, int c) {
return false; // TODO: Implement me correctly
}
private _2_DifferentValues(){/* Ignore me: Suppressing default constructor javadoc generation:
javadoc does not include private constructors by default */}
}
package de.hdm_stuttgart.mi.sd1.task1;
public class _3_Number {
/**
* Compute a new number from a given positive one by adding a value of one to each of its digits.
* The »9« digit will be replaced by a »10« (no carry over, just shifting neighbouring digits around).
*
* Examples:
* <ul>
* <li>123 becomes 234</li>
* <li>91293 becomes 1023104</li>
* </ul>
*
* @param n The input to be enlarged digit wise.
* @return The raised value.
*
* <section class="implementationHints">
* <h3 class="implementationHints">Possible implementation idea (»brute force« wise):</h3>
* <ol>
* <li>Transform the given value into a {@link String} i.e. an <code>int</code> 1234 becomes
* <code>"1234"</code>.</li>
* <li>Iterate over all digits applying the given substitution rules.</li>
* <li>Turn the resulting {@link String} back into an <code>int</code>.</li>
* </ol>
* </section>
*/
static public int raiseDigitsByOne(int n) {
return -1; // TODO: Implement me correctly
}
private _3_Number(){/* Ignore me: Suppressing default constructor javadoc generation:
javadoc does not include private constructors by default */}
}
package de.hdm_stuttgart.mi.sd1.task1;
/**
* Providing a single helper method.
*/
public class _4_ArrayHelper {
/**
* Eliminate all array values being equal to a given one. The resulting array may be shorter than the original one.
* Examples:
*
* <ul>
* <li><code>input = {<span style="color:red;">1</span>, 2, 3, <span style="color:red;">1</span>}</code>,
* <code>excludedValue = <span style="color:red;">1</span></code> yields <code>{2, 3}</code></li>
*
* <li><code>input = {5, 4, 3, 5}, excludedValue = <span style="color:red;">0</span></code> yields the unchanged
* original values <code>{5, 4, 3, 5}</code></li>
*
* </ul>
*
* @param input An array or <code>null</code> the latter being treated as an empty array.
* @param excludedValue This value will be eliminated from the input array.
* @return A <b>new</b> array containing only those original array's values being different from <code>excludedValue</code>.
*
* <section class="implementationHints">
* <h3 class="implementationHints">Implementation idea:</h3>
* <ol>
* <li>Create a new array of same size.</li>
*
* <li>Loop over the original array copying only differing values. Keep a record of the number of values
* copied.</li>
*
* <li>Create a third array of limited size depending on the previous step's number of copies and
* fill in the desired values.</li>
* </ol>
* </section>
*/
public static int[] eliminate(final int[] input, int excludedValue) {
return null; // TODO: Implement me correctly
}
private _4_ArrayHelper(){/* Ignore me: Suppressing default constructor javadoc generation:
javadoc does not include private constructors by default */}
}
package de.hdm_stuttgart.mi.sd1.task1;
/**
* Zipping up two arrays into one.
*/
public class _5_ArrayZipper {
/**
*
* <p>“zipping up” two arrays into a single one. If present the “left” array's first value serves as the starting
* point. Examples:</p>
*
* <table>
* <tr>
* <td>
* <pre>{<span style="color:red;">3</span>, <span
* style="color:red;">6</span>, <span style="color:red;">1</span>, <span
* style="color:red;">5</span>}
* ➘➚ ➘➚ ➘➚ ➘ ==&gt; {<span style="color:red;">3</span>, <span
* style="color:green;">9</span>, <span style="color:red;">6</span>, <span
* style="color:green;">0</span>, <span style="color:red;">1</span>, <span
* style="color:green;">4</span>, <span style="color:red;">5</span>, <span
* style="color:green;">7</span>}
* {<span style="color:green;">9</span>, <span style="color:green;">0</span>, <span
* style="color:green;">4</span>, <span style="color:green;">7</span>}</pre>
* </td>
* <td> like </td>
* <td>
* <object data="doc-files/zipper.svg" type="image/svg+xml" width="150" ></object>
* </td>
*
* </tr>
*
* </table>
*
* <p>The following example shows two arrays of different lengths. The longer array's excess values (printed in
* <span style="color:blue;">blue</span>)
* will be appended to the result:</p>
*
* <table border="1" style="border-collapse: collapse;">
* <tr>
* <td><pre>{<span style="color:red;">3</span>, <span style="color:red;">6</span>}
* ➘➚ ➘ ↷ ↷ ==&gt; {<span style="color:red;">3</span>, <span
* style="color:green;">9</span>, <span style="color:red;">6</span>, <span
* style="color:green;">0</span>, <span style="color:blue;">4</span>, <span
* style="color:blue;">7</span>}
* {<span style="color:green;">9</span>, <span style="color:green;">0</span>, <span
* style="color:blue;">4</span>, <span style="color:blue;">7</span>}</pre></td>
*
* <td><pre>{<span style="color:red;">3</span>, <span style="color:red;">6</span>, <span
* style="color:red;">1</span>, <span style="color:blue;">5</span>}
* ➘➚ ➘➚ ⤻ ==&gt; {<span style="color:red;">3</span>, <span
* style="color:green;">9</span>, <span style="color:red;">6</span>, <span
* style="color:green;">0</span>, <span style="color:red;">1</span>, <span
* style="color:blue;">5</span>}
* {<span style="color:green;">9</span>, <span style="color:green;">0</span>}</pre></td>
* </tr>
* </table>
*
* <p><code>null</code> values will be treated like empty arrays:</p>
*
* <table border="1" style="border-collapse: collapse;">
* <tr>
* <td><pre><code>null</code> or {}
* ↷ ↷ ↷ ==&gt; {<span style="color:green;">9</span>, <span
* style="color:blue;">0</span>, <span style="color:blue;">4</span>, <span
* style="color:blue;">7</span>}
*{<span style="color:green;">9</span>, <span style="color:blue;">0</span>, <span
* style="color:blue;">4</span>, <span style="color:blue;">7</span>}</pre></td>
*
* <td><pre>{<span style="color:red;">3</span>, <span style="color:blue;">6</span>, <span
* style="color:blue;">1</span>, <span style="color:blue;">5</span>}
* ⤻ ⤻ ⤻ ==&gt; {<span style="color:red;">3</span>, <span
* style="color:blue;">6</span>, <span style="color:blue;">1</span>, <span
* style="color:blue;">5</span>}
*<code>null</code> or {}</pre></td>
*
* <td><pre><code>null</code> or {}
* ==&gt; {}
*<code>null</code> or {}</pre></td>
* </tr>
* </table>
*
* @param left First array or <code>null</code>. The zipping process will start with this array's first value if present.
* @param right Second array or <code>null</code>.
* @return Both arrays' combined values according to the zipping description. The resulting array's length
* equals the sum of lengths of both contributors.
*
* <section class="implementationHints">
* <h3 class="implementationHints">Possible implementation idea:</h3>
* <ol>
* <li>Handle <code>null</code> array argument values beforehand.</li>
* <li>Create a new array having the combined length of both input arrays.</li>
* <li>Get the minimum length of both input arrays.</li>
* <li>Use a loop till minimum length to combine both arrays</li>
* <li>Add the longer array's excess values.</li>
* </ol>
* </section>
*/
static public int[] zipper(int[] left, final int[] right) {
return null; // TODO: Implement me correctly
}
private _5_ArrayZipper(){/* Ignore me: Suppressing default constructor javadoc generation:
javadoc does not include private constructors by default */}
}
/**
* 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
package de.hdm_stuttgart.mi.sd1.task2;
/**
* Square Matrix representations. See the {@link de.hdm_stuttgart.mi.sd1.task2.demo.DemoDriver} example.
*/
public class Matrix {
/**
* Initializing a square matrix.
*
* The two dimensional values array must define a square matrix having equal row and column counts like e.g.:
*
* <pre>m = new Matrix(new int[][]
* {
* {1, 2},
* {3, 4}
* })</pre>
*
* <code>m</code> will then represent a 2 x 2 matrix:
*
* \[
* \begin{bmatrix}
* 1 &amp; 2 \\
* 3 &amp; 4 \\
* \end{bmatrix}
* \]
*
* On contrary the following argument will cause an {@link ArithmeticException}:
*
* <pre>m = new Matrix(new int[][]
* {
* {1, 2, 3},
* {4, 5}, // does not suit size 3 x 3 square matrix
* {6, 7, 8}
* })</pre>
*
* @param values A two dimensional array holding the intended matrix values in a row/column fashion.
* @throws ArithmeticException Raised if the input array does not represent a (n x n) square matrix.
*/
public Matrix(final int[][] values) throws ArithmeticException {
// TODO: Implement me!
}
/**
* The usual component wise matrix addition.
*
* Example:
*
* \[
* \begin{bmatrix}
* 1 &amp; 2 &amp; 3 \\
* 4 &amp; 5 &amp; 6 \\
* 7 &amp; 8 &amp; 9 \\
* \end{bmatrix}
* +
* \begin{bmatrix}
* 1 &amp; 1 &amp; 1 \\
* 1 &amp; 1 &amp; 1 \\
* 1 &amp; 1 &amp; 1 \\
* \end{bmatrix}
* =
* \begin{bmatrix}
* 2 &amp; 3 &amp; 4 \\
* 5 &amp; 6 &amp; 7 \\
* 8 &amp; 9 &amp; 10 \\
* \end{bmatrix}
* \]
*
* @param other Another matrix to be added to the current instance.
* @return The component wise sum of both matrix instances
* @throws ArithmeticException In case the size of both matrix instances differs.
*
*/
public Matrix add(final Matrix other) throws ArithmeticException {
return null; // TODO: Implement me correctly!
}
/**
* Access matrix element by row and column.
*
* We consider an example matrix:
*
* \[
* \begin{bmatrix}
* 1 &amp; 2 &amp; 3 \\
* 4 &amp; 5 &amp; 6 \\
* 7 &amp; 8 &amp; 9 \\
* \end{bmatrix}
* \]
*
* The above matrix has got size 3 x 3. Rows and column index values range from 0 to 2. So when <code>m</code>
* represents the above matrix executing <code>m.get(1, 2)</code> will select the second row and the third column
* thus returning 6.
*
* @param row Row index ranging from 0 to the matrix size-1
* @param col Column index ranging from 0 to the matrix size-1
* @return The matrix value pointed to by row and column specification.
*/
public int get(int row, int col) {
return -1; // TODO: Implement me correctly!
}
/**
* Two square matrices are equal if:
*
* <ol>
* <li>The sizes of both instances are equal</li>
* <li>All corresponding values (same row and column) are equal</li>
* </ol>
*
* @param obj Instance to be compared.
* @return true if object is a matrix being equal to the current instance.
*/
@Override
public boolean equals(Object obj) {
return true; // TODO: Implement me correctly!
}
}
package de.hdm_stuttgart.mi.sd1.task2.demo;
import de.hdm_stuttgart.mi.sd1.task2.Matrix;
/**
* Sample usage demo. Watch my sourcecode in your IDE, not in Javadoc!
*/
public class DemoDriver {
public static void main(String[] args) {
// Creating two instances.
final Matrix
m1 = new Matrix(new int[][]
{
{1, 2},
{3, 4}
}),
m2 = new Matrix(new int[][]
{
{5, 6},
{7, 8}
});
// Building the sum of both instances
final Matrix sum = m1.add(m2);
// the expected result
final Matrix expectedSum = new Matrix(new int[][]
{
{6, 8},
{10, 12}
});
// Comparing result and expectation
if (sum.equals(expectedSum)) {
System.out.println("Looks good");
} else {
System.out.println("You should not see this!");
}
}
}
/**
* Dealing with matrix operations.
*
*/
package de.hdm_stuttgart.mi.sd1.task2;
\ No newline at end of file
This diff is collapsed.
<?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