A friend is working on some homework. He has to take account numbers from an input file, check for account duplicates, calculate the cost using piecewise formula, then add them by account to display as an itemized bill. It's essentially the same homework found [here](http://www.dreamincode.net/forums/topic/330308-getting-total-bill-per-account-for-a-phone-bill/).

It's hard since it's intro to java and I'm not very good. We're getting two errors: one is there's an Array out of bounds exception and two is the file checking. Since we use a for loop to calculate the account cost per call we can't keep track of previous account numbers to check. I suggested an ArrayList to keep hold of previous accounts and to check for duplicates but we can't figure out how to split into a separate ArrayList.

We have this code:

```
public static void main(String[] args) throws IOException, ParseException{

    ArrayList<String> acctHolder = new ArrayList<String>();
    String tmp = "";

    File fInput = new File("input_data.txt");

    Scanner scInput = null;
    scInput = new Scanner(fInput);         
    while (scInput.hasNextLine()){
        tmp = scInput.nextLine();
        acctHolder.add(tmp);
    }

    scInput.close();

    DecimalFormat twoDForm = new DecimalFormat("#.##");

    String acctNum = null;
    String timeMin = null;
    String totalTime = null;
    double feeCost = 0;
    double totalCost = 0;
    double finalTotal = 0;
    double sum = 0;

    final double DAYRATE = 0.12;
    final double NIGHTRATE = 0.05;
    final double BASEFEE = 20.0;

    ArrayList<Double> aTCost = new ArrayList<Double>();

    System.out.println("Invoice");
    System.out.println("*****************************");
    System.out.println("Account    \t     Amount Due");

    for(int i = 1; i < acctHolder.size(); i++)
    {

        String[] result = ((String) acctHolder.get(i)).split(" ");

        acctNum = result[0];
        timeMin = result[1];
        totalTime = result[2];

        double tTime = Double.parseDouble(totalTime);

        String morningTime = "08:00";
        String nightTime = "22:00";
        DateFormat timeMins = new SimpleDateFormat("kk:mm");
        Date callTime = timeMins.parse(timeMin);
        Date dawnTime = timeMins.parse(morningTime);
        Date niteTime = timeMins.parse(nightTime);

        if(callTime.compareTo(dawnTime) > 0 && callTime.compareTo(niteTime) < 0 )
        {
            feeCost = tTime * DAYRATE;   
            totalCost = feeCost + BASEFEE; 
        }
        else
        {
            feeCost = tTime * NIGHTRATE;
            //totalCost = feeCost + BASEFEE;   
        }

        aTCost.add(totalCost);

        //double sum = 0;
        for(Double d : aTCost)
            sum += d;

        System.out.println(acctNum + "               $"+ feeCost);

    }            
    //for(int i = 0; i < acctHolder)
    System.out.println("*****************************");
    System.out.println("Total                " + sum);

}

```