final version of query.java