Is this a homework question? JavaRanch is not a code mill.
So, what have you tried yourself and where do you get stuck? With assignments like these, it helps to first think about the problem itself - describe in normal language how you would solve this. When you're clear about how you're going to do it, you can start thinking about writing Java code.