degree of difficulty: 2
The goal of this exercise is, to measure and compare the performance of if-lese, switch and a map of values.
The following abstract data type
HexadecimalDigit that encapsulates one hexadecimal digit is given:
public void setDigit(char digit): set the digit to a new digit from the value range '0'-'9', 'a'-'f', or 'A'-'F'
public int getDecimalValue(): returns the decimal value of the digit: 0 to 15. The digits are not case sensitive. If the digit is not in the correct range, -1 is returned.
Implement three different variants of this interface: The method getDecimalValue() must be implemented efficiently
For the performance measurement the implementation have to recalculate the decimal value for each call. The array should be declared and initialized static in the implementation class. Its size is 65536 (maximum number of unicode characters in Java). Implement all three variants efficiently without sacrifycing readability.
Implement a Java class to measure the average running time of the getDecimalValue() method for random digits. Use System.nanoTime() for this. Make sure that object creation and initialization is not part of the time measuring.
degree of difficulty: 2
Before starting this exercises, please design and implement chemical elements first.
The chemical elements are arranged as a two dimensional matrix in the periodic system of chemical elements: The horizontal rows (periods 1 to 7) are alle chemical elements with identical numbers of atomic orbits in the electron sheath. The vertical columns classifies chemical elements into groups (1 to 18) with identical chemical properties.
Design and implement a Java-class
PeriodicTable with a method,
that returns the chemical element for a given period and group.
In case of lanthanoids or actinoids, only the first chemical element of this group must be returned.
In reality the periodic system exists only once. Therefore, only one object of this class may exist. Classes for which only one object can be constructed are singletons. Make every constructor of your class private. Implement a static method that returns the single instance of the class.
The data of the periodic system have to be read from this text file. It has to be copied to the root folder of your Java project. The data in this file have been taken from the english Wikipedia. The text file is ASCII encoded (and therefore UTF-8, too).
Use FileReader and BufferedReader to read in the text line by line. The data in each line is seperated by a comma (CSV, comma seperated values). Use the String method split(). Use try-catch-finally for IOExceptions and make sure that in any case the file is closed.