PDA

View Full Version : damn i am tired



RL...
03-23-2010, 04:13 AM
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......

1990wade
03-23-2010, 04:20 AM
sowwy..................

RL...
03-23-2010, 04:24 AM
sowwy..................

mmaaaaaaaahhhhhhhhhhhhhhhhhh