Results 1 to 3 of 3

Thread: damn i am tired

  1. #1
    ballin on a budget RL...'s Avatar
    Join Date
    May 2008
    Location
    ATL, GA
    Age
    38
    Posts
    5,893
    Rep Power
    41

    Default damn i am tired

    so 8 hours and 159 lines of code later my program is 95% done, now i jsut have to figure out how to use jptionpane to output the data instead of the println method

    import java.io.*; //Needed for the file classes
    import java.text.DecimalFormat; //Needed to use DecimalFormat
    import javax.swing.JOptionPane; //Needed for joptionpane

    /*
    This program reads data from a file and
    calculates the sales tax on the data
    */


    public class FileSum //class header
    {
    public static void main(String[] args) throws IOException //method header
    {
    String transInfo; //to hold a line read from the file
    double taxRate = .00; //to hold the tax rate based on location
    int number = 0; //to hold an int amount for the variavle transNum
    double amount = .00; //to hold transAmt
    String transDate = "", transNum = "", transAmount = ""; //to hold data from file
    char county = ' '; //to determine the county and thus the sales tax rate percentage
    String location = ""; //to hold the county of the transaction
    int space = 0; //to hold the amount of spaces in the file to seperate the data
    double totalTax = .00; // a counter to hold total sales tax
    double salesTax; //to hold the tax for each transaction

    DecimalFormat formatter = new DecimalFormat("#0.00"); //Needed for decimal format

    // Open the file.
    FileReader freader = new FileReader("test1sampledata.txt");
    BufferedReader inputFile = new BufferedReader(freader);

    // Read the first line from the file
    transInfo = inputFile.readLine();

    //to separate the data read from file to manipulate it

    while (transInfo != null)
    {
    transDate = "";
    transNum = "";
    transAmount = "";
    space = 0;

    for (int i = 0; i < transInfo.length(); i++)
    {
    if (space == 0)
    {
    if (transInfo.charAt(i) != ' ')
    {
    transDate += transInfo.charAt(i);
    }
    else
    {
    space = 1;
    i++;
    }
    }
    if (space == 1)
    {
    if (transInfo.charAt(i) != ' ')
    {
    transNum += transInfo.charAt(i);
    }
    else
    {
    space = 2;
    i++;
    }
    }
    if (space == 2)
    {
    if (transInfo.charAt(i) != ' ')
    {
    county = transInfo.charAt(i);
    }
    else
    {
    space = 3;
    i++;
    }
    }
    if (space == 3)
    {
    if (transInfo.charAt(i) != ' ')
    {
    transAmount += transInfo.charAt(i);
    }
    }
    }

    number = Integer.parseInt(transNum); //converts transNum to int value stored in variable number
    amount = Double.parseDouble(transAmount); //converts transAmount to double value stored in variable amount

    //determine which tax rate to use based on the county
    switch (county)
    {
    case 'A':
    location = "Atlanta";
    taxRate = .08;
    break;
    case 'C':
    location = "Cobb County";
    taxRate = .06;
    break;
    case 'D':
    location = "Dekalb County";
    taxRate = .07;
    break;
    case 'F':
    location = "Fulton County";
    taxRate = .07;
    break;
    case 'G':
    location = "Gwinnett County";
    taxRate = .06;
    break;
    case 'O':
    location = "Out of State";
    taxRate = .00;
    break;
    case 'X':
    location = "Exempt";
    taxRate = .00;
    break;
    default:
    location = "ERROR IN FILE";
    }

    //calculate the tax of each individual transaction
    salesTax = taxRate * amount;
    //calculate the total tax of all transactions added up
    totalTax += taxRate * amount;


    //print the results
    System.out.println("Date: " + transDate);
    System.out.println("Number: " + number);
    System.out.println("Location: " + location);
    System.out.println("Tax: " + formatter.format(taxRate));
    System.out.println("Amount: $" + formatter.format(amount));
    System.out.println("Amount of sales tax owed on this transaction is: &" + formatter.format(salesTax));

    /* /////////////////////////////////////////////////////////////$
    $ I can't believe it's not butter $
    $ Howmuchwoodwouldawoodchuckchuckifawoodchuckcouldch uckwood $
    */ /////////////////////////////////////////////////////////////$

    /*
    determining the end of the file by testing the value returned from
    the bufferedreader objects readline method
    */
    transInfo = inputFile.readLine();

    }
    System.out.println("The total amount of sales tax owed from all transactions is: $" + formatter.format(totalTax)) ;
    //close the file
    inputFile.close();
    }
    }

    hopefully you all have had a better night/morning than me so far....and i have to work at 9am and class at 5pm...yay......
    Last edited by RL...; 03-23-2010 at 05:23 AM.


  2. #2
    TOYOTA TACOMA!!!! 1990wade's Avatar
    Join Date
    Feb 2009
    Location
    BETWEEN MACON AND DUBLIN
    Age
    35
    Posts
    2,778
    Rep Power
    20

    Default

    sowwy..................





    I DRIVE A TRUCK THEREFORE MY DICK IS BIGGER THAN YOURS....

  3. #3
    ballin on a budget RL...'s Avatar
    Join Date
    May 2008
    Location
    ATL, GA
    Age
    38
    Posts
    5,893
    Rep Power
    41

    Default

    Quote Originally Posted by 1990wade View Post
    sowwy..................
    mmaaaaaaaahhhhhhhhhhhhhhhhhh


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
ImportAtlanta is a community of gearheads and car enthusiasts. It does not matter what kind of car or bike you drive, IA is an open community for any gearhead. Whether you're looking for advice on a performance build or posting your wheels for sale, you're welcome here!
Announcement
Welcome back to ImportAtlanta. We are currently undergoing many changes, so please report any issues you encounter with the site using the 'Contact Us' button below. Thank you!