">

HI.java


Below is the syntax highlighted version of HI.java from §3.3 Modular Programming.

/*************************************************************************
 *  Compilation:  javac HI.java
 *  Execution:    java HI year < _HI.txt
 *
 *  % java HI 2004 < _HI.txt
 *
 *
 *************************************************************************/

public class HI {
    public static void main(String[] args) {

        // year of election
        int year = Integer.parseInt(args[0]);

        // scale coordinates and set window size
        double xmin = -160.555771;
        double xmax = -154.809372;
        double ymin = 18.913826;
        double ymax = 22.23601;
        StdDraw.setCanvasSize(1013, 800);
        StdDraw.setXscale(xmin, xmax);
        StdDraw.setYscale(ymin, ymax);

        // process data
        while (!StdIn.isEmpty()) {
            String name = StdIn.readLine();
            String usps = StdIn.readLine();
            int N = StdIn.readInt();
            Point[] points = new Point[N];
            for (int i = 0; i < N; i++)  {
                double x = StdIn.readDouble();
                double y = StdIn.readDouble();
                points[i] = new Point(x, y);
            }

            Polygon poly = new Polygon(points);
            Region region = new Region(name, usps, poly);
            VoteTally votes = new VoteTally(name, usps, year);
            StdDraw.setPenColor(StdDraw.BLACK);
            region.fill();
            StdDraw.setPenColor(StdDraw.WHITE);
            region.draw();

            // ignore empty line
            StdIn.readLine();
            StdIn.readLine();

        }

    }
}

Copyright © 2006, Robert Sedgewick and Kevin Wayne.
Last updated: Thu Aug 17 10:47:30 EDT 2006.