finished code and console output. todo: javadocs