Final implementation of Lab3Main.java, supports all queries mentioned.