Solving the Exercise using oops approach