Give a boolean expression for the definition of a metropolis

degree of difficulty: 3

Let three variables be given containing information for a city:

boolean isCapitalCity;
int numberOfCitizen;
double taxPerCitizen;
with the following meaning: We define a Metropolis to be a city, that is either a capital city with more than 100 000 citizens or more than 200 000 citizens and an average income of 720 000 000 per year.

Give a boolean expression with all three variables that is true if and only if the city is a metropolis.

Solution

Convert 16 bit Unicode into UTF-8

degreee of difficulty: 1

Give one (!) arithmetic expression that converts the value of a char-variable (16 bit unicode) into the corresponding UTF-8 encoding. The result should be an int-value.

For this exercise you need the tenary operator boolean-expression ? expression-1 : expression-2, the bitwise operators &, |, and the shift operators >> and <<

Implement the expression stepwise: first given an expression for converting char-values with 7 bit unicodes into its UTF-8 encoding, then for 11 bit unicodes and finally for 16 bit unicode values.

The resulting expression will be large and hard to read: comment and format it for readability. In practise this programming task should be implemented with addtional variables for intermediate results and if-else-statements (see the solution for examples).

Use the method Integer.toBinaryString() for debugging and testing your expression.

Solution

Calculate the electrical resistance of a wire

degreee of difficulty: 3

Three coated copper wires.

The electricalv resistance R of a cylindrical wire with length l (in meter) and diameter d (in meter) can be computed from the area A of its diameter (m2) and the und the resistivity Ρ of the material (rho, meter times Ohm). The formula:

R = Ρ( l / A )

Compute the electrical resistance of a wire with length 1m and a diameter of 1mm for copper (Ρ = 1,78*10-8) and for silicon (Ρ = 2300)

Ohm's law states the current (I) is proportional to the potential difference (U). As a formula: U = R * I.

What is the resistance of the wire if 25 Ampere current pass through it?

Solution