import java.io.*; import java.util.Arrays; public class Lab3 { /* edit and compile this, then run the program using the command line java Lab3 filename.filetype where filename.filetype is the name of your input file */ private ByteCount[] counters = new ByteCount[256]; public static void main(String[] args) { // create 256 ByteCount objects, initialize them, and store their addresses in the counters array // get filename, open file for input, try to read the first byte of data /* // put this in a try block, followed by a catch block to catch IOExceptions while (not EOF) process the input byte try to read the next byte of data endwhile */ // output the results, in order by byte value (0-255) // sort the data by frequency ... use Arrays.sort( ) // output the results again, sorted by frequency with highest frequency first } } class ByteCount implements Comparable { public int final charbyte; public int frequency; public ByteCount(int i) { if (i >= 0 && i < 256 ) charbyte=i; else charbyte=0; frequency=0; } public int increment() { return ++frequency; } public int compareTo(ByteCount b) { if (this.frequency < b.frequency) return -1; else if (this.frequency > b.frequency) return 1; else return 0; } public String toString() { return "byte=" + ((Integer) charbyte).byteValue() + ":freq=" + frequency+"\t"; } }