Arrays reconsidered
Combining array allocation and value assignment:
|
|
No. 142
Converting string arrays to HTML.
|
Q: |
Consider an array of strings. As an example we provide a list of country names: An application is supposed to generate the following output: Implement A class method Do not forget to provide appropriate Javadoc™ method and class documentation. You may
want to reconsider Figure 328, “Maven
Generating Javadoc™ HTML documentation from your project should yield a result like: ![]() Provide appropriate unit tests covering at least:
|
|
A: |
|
No. 143
Pangram checker
|
Q: |
A pangram is a string containing all
letters of a given alphabet at least once. As an example we
consider the alphabet of ASCII letters
Tip
|
|
A: |
In addition to the above “regular” solution we also provide an approach featuring Java™ streams with respect to the upcoming “Software development 2” lecture: |
No. 145
Examinations and mark frequencies
|
Q: |
Consider an examination resulting in the following list of marks:
You may represent this examination result by: Lecturers and participants may be interested in the distribution of marks i.e. their frequencies. Thus having marks in a range from 1 to 5 in the given example we'd like to create the following overview of marks:
Write a 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: Mark|frequency ————+————————— 1|3 2|4 3|6 4|3 5|2 Your application shall work for other marking schemes (i.e. marks ranging from -2 to 10) as well. Define a suitable class like: The constructor assigning values to both Provide appropriate unit tests beforehand. Tip
After implementing your method extend your application to allow for being called from the command line like: marking> mvn package .... marking> java -jar target/marking-0.9.jar 2 1 3 3 5 4 1 2 2 4 3 2 3 3 1 5 3 4 Mark|frequency ————+————————— 1|3 2|4 3|6 4|3 5|2 This requires evaluating the args parameter from your
Tip
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
A: |
The method |
No. 146
External string exercises
|
Q: |
Try solving as many examples as possible from the String-3 sections. |
...println(" String: " + "".getClass().getTypeName());
...println(" int[]: " + new int[]{}.getClass().getTypeName());
...println(" double[]: " + new double[]{}.getClass().getTypeName());
...println(" boolean[]: " + new boolean[]{}.getClass().getTypeName());
...println("StringBuffer[]: " + new StringBuffer[]{}.getClass().getTypeName()); String: java.lang.String
int[]: int[]
double[]: double[]
boolean[]: boolean[]
String[]: java.lang.String[]
StringBuffer[]: java.lang.StringBuffer[]static void main() {
final int [] lectures = new int[3]; // Three lectures
fill(lectures, 25); // Default lecture having 25 participants
IO.println("Second lecture has got " + lectures[1] +
" participants");
}
/**
* Initialize array with default value.
*
* @param values Array to be initialized.
* @param common New value for all array elements.
*/
static void fill(final int[] values, final int common) {
for (int i = 0; i < values.length; i++) {
values[i] = common;
}
}Second lecture has got 25 participants
// Value type
final boolean values[] = {true, true, false, true};
// Reference type
final String shapes[] = {"Triangle", "Circle"};

