scala exercises (P31-P34)