Solution 2 using classes.