P03, P04 in scala