
-----------------------------------
unoho
Wed Mar 03, 2010 7:57 pm

reading a particular line
-----------------------------------
Hi guys, this is a sample input file that my program is supposed to read. (also, i put it as attachment)
467343	23750.40
W 	250.00
D	1200.00		
W	75.00
I	120.74
W	375.00
D	580.00
I	245.50
W	400.00
W	600.00
D	450.50
W	35.65

where the first line is account number (467343) and opening balance($23750.40)

then i am supposed to input W(withdrawals) and D(Deposits) or I(interest) and do some calculation. Problem is that once i read the first line of the file, i can't read from the second line. It gives me an NoSuchElementException error.

Here is a sample code:
[code]
package hossaina_assn02;
import java.io.*;
import java.text.DecimalFormat;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws FileNotFoundException, IOException{
        int accountNumber, countDeposit=0, countWithdraw=0;
        double openingBalance=0, transValue=0, newBalance=0;
        double interest=0, deposit=0, withdraw=0;
        char transType;
        boolean isServiceCharged = false;

        BufferedReader inData = new BufferedReader(new FileReader("account.txt"));
        PrintWriter outData;
        String inputLine = inData.readLine();
        StringTokenizer tokens = new StringTokenizer(inputLine);
        DecimalFormat decFormat = new DecimalFormat("0.00");

        accountNumber = Integer.parseInt(tokens.nextToken());
        openingBalance = Double.parseDouble(tokens.nextToken());

        while((inputLine = inData.readLine())!=null){
            transType = tokens.nextToken().charAt(0);
            System.out.println(transType);
            transValue = Double.parseDouble(tokens.nextToken());
            switch (transType){
                case 'w':
                case 'W':
                    withdraw += transValue;
                    countWithdraw++;
                    break;
                case 'd':
                case 'D':
                    deposit += transValue;
                    countDeposit++;
                case 'i':
                case 'I':
                    interest += transValue;
                    break;
            }
            newBalance = openingBalance + deposit + interest - withdraw;
            if (newBalance 