The question is, can you solve it, given that it's your homework? We can help you but getting other people to do your homework for you is cheating, which is not appreciated here. Make your best attempt and tell us where you're stuck if you need help. Remember that you are allowed to think about the problem. You don't have to just pluck code out of thin air. Think about the logic first, which has nothing specifically to do with programming, and then try to come up with code to implement that logic.