How far have you got and where are you stuck? We won't write the program for you but we will help you figure it out.

Have you figured out an algorithm for the two programs yet?
Have you figured out a class definition for the second?