// StudentPoll.java // Adapted from Array chapter Fig. 7.7 import javax.swing.*; public class StudentPoll { public static void main( String args[ ] ) { int res[ ] = { 1, 2, 6, 4, 8, 5, 9, 7, 8, 10, 1, 6 , 3, 8, 6, 10, 3, 8, 2, 7, 6, 5, 7 }; // hard-coded data int freq[ ] = new int [ 11 ]; // array of frequencies String output = ""; for ( int a = 0; a < res.length; a++ ) freq[ res[ a ] ]++; // increment appropriate frequency output += "Rating\tFrequency\n"; for ( int r = 1; r < freq.length; r++ ) output += r + "\t" + freq[ r ] +"\n"; // build output table displayTable( output ); // call helper method System.exit( 0 ); } // need to declare displayTable static to make static method call public static void displayTable( String results ) { JTextArea resultsArea = new JTextArea( 11, 10 ); resultsArea.setText( results ); JOptionPane.showMessageDialog( null, resultsArea, "Cafeteria Survey Results", JOptionPane.INFORMATION_MESSAGE ); } }