Commit a0282707 authored by Dr. Martin Goik's avatar Dr. Martin Goik

Array ex. overhaul

parent ce84357f
......@@ -630,9 +630,10 @@ static public long duration(Segment[] route, int personalSpeedLimit) {
</tr>
</informaltable>
<para>Write a <xref linkend="glo_Java"/> application which turning
an array of participants' marks into a table of mark frequencies.
For the given example the intended terminal output reads:</para>
<para>Write a <xref linkend="glo_Java"/> application turning an
array of participants' marks into the above table of marks among
with their respective frequencies. For the given example the
intended terminal output reads:</para>
<screen>Mark|frequency
----+---------
......@@ -649,50 +650,74 @@ static public long duration(Segment[] route, int personalSpeedLimit) {
<programlisting language="java">public class MarkFrequencies {
public final int[] frequencyByMark;
public final int lowestMark;
public final int lowestMarkValue;
public MarkFrequencies(final int[] markValues) {
...
}
}</programlisting>
<para>The constructor is yet not implemented. Upon completion you
may use class <classname>MarkFrequencies</classname> producing the
previously detailed terminal output:</para>
<para>The constructor assigning values to both <code
language="java">lowestMarkValue</code> and <code
language="java">frequencyByMark</code> and is not yet implemented.
Upon completion you may use class
<classname>MarkFrequencies</classname> for producing the previously
detailed terminal output:</para>
<programlisting language="java">public static void main(String[] args) {
final MarkFrequencies markFrequencies =
<programlisting language="java">final MarkFrequencies markFrequencies =
new MarkFrequencies(new int[]{2,1,3,3,5,4,1,2,2,4,3,2,3,3,1,5,3,4});
// Create overview of marks:
//
System.out.println("Mark|frequency");
System.out.println("----+---------");
// Create overview of marks:
//
System.out.println("Mark|frequency");
System.out.println("----+---------");
for (int i = 0; i &lt; markFrequencies.frequencyByMark.length ; i++) {
System.out.println(" " + (markFrequencies.lowestMark + i) + "|" +
markFrequencies.frequencyByMark[i]);
for (int i = 0; i &lt; markFrequencies.frequencyByMark.length ; i++) {
System.out.println(" " + (markFrequencies.lowestMark + i) + "|" +
markFrequencies.frequencyByMark[i]);
}
}</programlisting>
<para>providing appropriate unit tests beforehand.</para>
<para>Provide appropriate unit tests beforehand.</para>
<tip>
<orderedlist>
<listitem>
<para>Get the maximum and minimum mark of all
participants.</para>
<para>Get the minimum and maximum mark of all participants
beforehand.</para>
</listitem>
<listitem>
<para>Create the <code language="java">int[]
frequencyByMark</code> array. Regard each mark value as an
index value. So if the mark value range is
<abbrev>e.g.</abbrev> {-2, -1, 0, 1, 2, 3} map these to index
values {0, 1, 2, 3, 4, 5}. Then use each element from the list
of marks as an index to this array and increment the
respective index position accordingly.</para>
frequencyByMark</code> array. Since you already know both your
mark list's minimum and maximum the frequencies array's size
is thus determined. Shift each mark by the mark list's minimum
and regard each mark as an index value. Example:</para>
<itemizedlist>
<listitem>
<para>The list of marks is {-2, -1, 0, 1, 2, 3}.</para>
</listitem>
<listitem>
<para>The minimum mark is -2 and the maximum equals
3.</para>
</listitem>
<listitem>
<para>The list of marks shifted by -2 will start with
0:</para>
</listitem>
<listitem>
<para>{0, 1, 2, 3, 4, 5}</para>
</listitem>
<listitem>
<para>The array of mark frequencies thus contains 6
elements.</para>
</listitem>
</itemizedlist>
</listitem>
</orderedlist>
</tip>
......@@ -728,15 +753,15 @@ Mark|frequency
</listitem>
<listitem>
<para>The <productname>maven-shade-plugin</productname>
already being configured inside your project's
<filename>pom.xml</filename> allows for creating executable
jar archives. Suppose a <methodname>main(...)</methodname>
method exists in a class
<package>de.hdm_stuttgart.mi.marking</package>.<classname>Marks:
</classname> Your project's <filename>pom.xml</filename>
allows for defining this class to become the archive's
executable method:</para>
<para>The <productname>maven-shade-plugin</productname> inside
your project's <filename>pom.xml</filename> allows for
creating executable jar archives. If your
<methodname>main(...)</methodname> method is being defined in
a class
<package>de.hdm_stuttgart.mi.marking</package>.<classname>Marks</classname>
. You may define this class to become the overall execution
entry point by virtue of a corresponding
<filename>pom.xml</filename> entry:</para>
<programlisting language="none">...
&lt;plugin&gt;
......@@ -763,9 +788,9 @@ Mark|frequency
&lt;/plugin&gt;
...</programlisting>
<para>Executing the <command>mvn</command> <option
<para>Executing <command>mvn</command> <option
xlink:href="https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#A_Build_Lifecycle_is_Made_Up_of_Phases">package</option>
phase will then create an executable jar archive as outlined
will then create an executable jar archive as outlined
above.</para>
</listitem>
</orderedlist>
......
......@@ -37,12 +37,6 @@
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>de.hdm_stuttgart.mi.exam</groupId>
<artifactId>unitmarking</artifactId>
......
......@@ -37,12 +37,6 @@
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>de.hdm_stuttgart.mi.exam</groupId>
<artifactId>unitmarking</artifactId>
......
......@@ -7,7 +7,6 @@ import de.hdm_stuttgart.mi.marking.implement.MarkFrequencies;
*/
public class SimpleExample {
/**
* <p>This is **not** the desired terminal application.</p>
*
......
......@@ -2,7 +2,7 @@ package de.hdm_stuttgart.mi.marking.implement;
/**
* Creating mark overviews.
* Creating an overview of marks.
*/
public class MarkFrequencies {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment