/* * [PrepTennessee.java] * * Summary: One shot program to process tax data for Tennessee. Generates code for AmericanTax.java table. * * Copyright: (c) 1999-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2008-06-01 initial * 1.1 2010-12-06 new format of screen scraped file. * 1.2 2010-12-10 update to produce CSV file without state tax included. */ package com.mindprod.americantax; import com.mindprod.common18.ST; import com.mindprod.csv.CSVReader; import java.io.IOException; /** * One shot program to process tax data for Tennessee. Generates code for AmericanTax.java table. * * @author Roedy Green, Canadian Mind Products * @version 1.2 2010-12-10 update to produce CSV file without state tax included. * @since 2008-06-01 */ public final class PrepTennessee extends PrepStateBase { /** * upper bound on number of counties in Tennessee */ private static final int MAX_COUNTIES = 100; private final String[] countiesByNumber = new String[ MAX_COUNTIES ]; /* Tennessee sales tax home: http://tn.gov/revenue/tntaxes/salesandusee.htm download http://tn.gov/revenue/pubs/taxlist.pdf tennesseboth.pdf contains both the counties with tax and cities. To create counties list, export PDF to text, spit off page 4. Use regex to group elements into one lineper county CSV. Strip off %. It won't be in order. When you have massaged enough it will look like this: tennesseecounties.csv * #county rate countynumber * ANDERSON, 2.75, 01 * BEDFORD, 2.75, 02 * BENTON, 2.75, 03 * Copy all document and prune. Use regex to join lines. When doen it will look like this: * # city tax countynumber * ANDERSONVILLE, 2.75, 01 * CLINTON, 2.75, 01 * LAKE CITY, 2.75, 01 */ /** * Constructor */ private PrepTennessee() { super( "TN", "tennessee", 5.5, true /* counties */, true /* cities */, false /* files include state rate */, true /* convert to book case */, 2000 ); } /** * Default method to read and prepare one county record. * You must read, and add SalesTaxItem to salesTaxItems, and skipToNewLine * * @param c open CSV reader. * * @throws IOException if cannot read file */ void prepareCity( final CSVReader c ) throws IOException { /* * # city tax countynumber * ANDERSONVILLE, 2.75, 01 */ final String location = ST.toBookTitleCase( c.get() ); final double percent = c.getDouble(); // state tax not included, county tax included final int countyNumber = c.getInt(); c.skipToNextLine(); final String countyName = countiesByNumber[ countyNumber ]; assert countyName != null : "unknown county: " + countyNumber; salesTaxItems.add( new SalesTaxItem( countyName, location, percent ) ); } /** * Default method to read and prepare one county record. * You must read, and add SalesTaxItem to salesTaxItems, and skipToNewLine * * @param c open CSV reader. * * @throws IOException if cannot read file */ void prepareCounty( final CSVReader c ) throws IOException { // #county rate countynumber // ANDERSON, 2.75, 01 final String county = ST.toBookTitleCase( c.get() ); final double percent = c.getDouble(); // state tax not included, county tax included final int countyNumber = c.getInt(); c.skipToNextLine(); countiesByNumber[ countyNumber ] = county; salesTaxItems.add( new SalesTaxItem( county, "", percent ) ); } public static void main( String[] args ) throws IOException { new PrepTennessee().prepare(); } }