public class StudentPoll
1: // Fig. 7.8: StudentPoll.java
2: // Poll analysis program.
3:
4: public class StudentPoll
5: {
6: public static void main( String args[] )
7: {
8: // array of survey responses
9: int responses[] = { 1, 2, 6, 4, 8, 5, 9, 7, 8, 10, 1, 6, 3, 8, 6,
10: 10, 3, 8, 2, 7, 6, 5, 7, 6, 8, 6, 7, 5, 6, 6, 5, 6, 7, 5, 6,
11: 4, 8, 6, 8, 10 };
12: int frequency[] = new int[ 11 ]; // array of frequency counters
13:
14: // for each answer, select responses element and use that value
15: // as frequency index to determine element to increment
16: for ( int answer = 0; answer < responses.length; answer++ )
17: ++frequency[ responses[ answer ] ];
18:
19: System.out.printf( "%s%10s\n", "Rating", "Frequency" );
20:
21: // output each array element's value
22: for ( int rating = 1; rating < frequency.length; rating++ )
23: System.out.printf( "%6d%10d\n", rating, frequency[ rating ] );
24: } // end main
25: } // end class StudentPoll
26:
27:
28: /**************************************************************************
29: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
30: * Pearson Education, Inc. All Rights Reserved. *
31: * *
32: * DISCLAIMER: The authors and publisher of this book have used their *
33: * best efforts in preparing the book. These efforts include the *
34: * development, research, and testing of the theories and programs *
35: * to determine their effectiveness. The authors and publisher make *
36: * no warranty of any kind, expressed or implied, with regard to these *
37: * programs or to the documentation contained in these books. The authors *
38: * and publisher shall not be liable in any event for incidental or *
39: * consequential damages in connection with, or arising out of, the *
40: * furnishing, performance, or use of these programs. *
41: *************************************************************************/