Here is some Java code.

Here is some Java code.  I changed the code a little, adding some
features.