Added an alternate solution to problem 1 using a constructor pattern