@@ -0,0 +1,1819 @@
+/**%0A * Demo of more compact, maintainable, table driven code.%0A */%0Apublic class GoodDemo %7B%0A %0A    /** cutoff quantify column in rate table */%0A    private static final int CUTOFF = 0;%0A %0A    /** rate column in rate table */%0A    private static final int RATE = 1;%0A %0A    /** quantity vs rate table */%0A    private static final double%5B%5D%5B%5D RATE_TBL = new double%5B%5D%5B%5D %7B // CUTOFF RATE%0A    new double%5B%5D %7B 10, 1.50 %7D, new double%5B%5D %7B 100, 1.00 %7D,%0A            new double%5B%5D %7B 1000, 0.95 %7D, new double%5B%5D %7B 2000, 0.94 %7D,%0A            new double%5B%5D %7B 5000, 0.93 %7D, new double%5B%5D %7B 10000, 0.92 %7D,%0A            new double%5B%5D %7B 20000, 0.91 %7D, new double%5B%5D %7B MAX_VALUE, 0.90 %7D, %7D;%0A %0A    /** list driven output tool */%0A    private static final Formatter printf = new Formatter(System.out);%0A %0A    /**%0A     * Program entry point.%0A     */%0A    public static void main(String%5B%5D argv) %7B%0A        double qty;%0A        double rate;%0A        for (qty = 5; qty %3C 100000; qty *= 5) %7B%0A            rate = getRate(qty);%0A            printf.format(%22Extended cost for %25.0f widgets: $%25.2f%5Cn%22, qty, (qty * rate));%0A        %7D // print each of several quantities%0A    %7D // __________%0A %0A    /**%0A     * Return the charge rate for a given volume of product.%0A     */%0A    private static double getRate(double qty) %7B%0A        for (double%5B%5D row : RATE_TBL) %7B%0A            if (qty %3C row%5BCUTOFF%5D) %7B%0A                return row%5BRATE%5D; // === found ===%0A            %7D // found quantity range?%0A        %7D // scan each row%0A        throw new RuntimeException(%22This can't happen%22);%0A    %7D // __________%0A %0A%7D /* Output%EF%BC%9A%0AExtended cost for 5 widgets: $7.50%0AExtended cost for 25 widgets: $25.00%0AExtended cost for 125 widgets: $118.75%0AExtended cost for 625 widgets: $593.75%0AExtended cost for 3125 widgets: $2906.25%0AExtended cost for 15625 widgets: $14218.75%0AExtended cost for 78125 widgets: $70312.50%0A

Create GoodDemoForTableDriven.java