// Marty Stepp, CSE 142, Autumn 2008 // This program processes a file full of midterm scores and // outputs a histogram of how many students got each score. import java.awt.*; // for Graphics import java.io.*; // for File import java.util.*; // for Scanner public class Midterm { public static void main(String[] args) throws FileNotFoundException { int[] scores = new int[102]; // scores range from 0 - 101 // tally all scores into an array Scanner input = new Scanner(new File("scores.txt")); while (input.hasNextInt()) { int student = input.nextInt(); scores[student]++; } DrawingPanel panel = new DrawingPanel(350, 250); Graphics g = panel.getGraphics(); // draw the histogram as text and graphics for (int i = 0; i < scores.length; i++) { // 85: ***** means scores[85] equals 5 if (scores[i] > 0) { System.out.print(i + ": "); for (int j = 0; j < scores[i]; j++) { System.out.print("*"); } System.out.println(); g.drawLine(3 * i, 250 - 10 * scores[i], 3 * i, 250); } } } }