// By Haw-ren Fang, TA of cmsc420-0401, Spring 2002 import java.io.*; import java.lang.*; // Class ColumnCompare is for grading purpose HashTablePlotData. // Basically it compares 2 text outputs as tables of values on column basis. // If you got a column of first output the same as the corresponding // column of second column, you got the points of that column. // Thus, if you can only do some columns correct, you need to fill the other // columns numbers (such as 0s) to get the credits of the columns you can do. // For example of successful search, if you can do longest probe length but // you cannot do average search cost. You need to fill the column of average // search cost by 0s. public class ColumnCompare { public int longest = 0; public int longestCount[]; static public void printUsage() { System.out.println("Usage: java [-Dall=true] ColumnCompare file1 file2 value1 value2 ... valuen"); System.out.println("Compare 2 tables in file1 and file2 with n columns."); System.out.println("The i-th column is worth of valuei."); System.out.println("If -Dall=true is set, then two tables must be the same to get credits (value1)."); System.exit(1); } static public void main(String args[]) { if (args.length <= 2) printUsage(); boolean isToCompareAll = Boolean.getBoolean("all"); try { StreamTokenizer tokenizer0 = new StreamTokenizer(new FileReader(args[0])); StreamTokenizer tokenizer1 = new StreamTokenizer(new FileReader(args[1])); if (isToCompareAll == true) { int total = Integer.parseInt(args[2]); while (tokenizer0.nextToken() != StreamTokenizer.TT_EOF) { if (tokenizer1.nextToken() == StreamTokenizer.TT_EOF) { System.out.println("Tables dismatch."); System.out.println("Total: 0/" + total); System.exit(0); } else if ((float)tokenizer0.nval != (float)tokenizer1.nval) { System.out.println("Tables dismatch."); System.out.println("Total: 0/" + total); System.exit(0); } } System.out.println("Tables completely match."); System.out.println("Total: " + total +"/" + total); System.exit(0); } int columns = args.length-2; int points[] = new int[columns]; int max[] = new int[columns]; int maxTotal = 0; for (int i=0; i