Source:

Note: This example was adapted from How to Program in Java, Deitel and Deitel