scala exercises (P14-P17)