import java.io.File;
import java.text.Format;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
/*
 * CoinsArrayListExercise.java
 *
 * Created on March 5, 2005, 6:05 PM
 */

/**
 *
 * @author Bill Kraynek
 */
public class CoinsArrayListExercise  {
    
    /**
     * @param args the command line arguments
     */
     public static void main(String[] args) throws Exception {
        ArrayList<Coin> purse = new ArrayList<Coin>();
        Scanner fileScanner = new Scanner(new File("coinData.txt"));
        double totalCash = 0.0;
        while( fileScanner.hasNext() ) {
            String line = fileScanner.nextLine();
            Scanner lineScanner = new Scanner(line);
            Coin coin = new Coin(lineScanner.nextDouble(),lineScanner.next()); 
            purse.add(coin);
            totalCash += coin.getValue();
        }// end while
        Format currencyFmt = NumberFormat.getCurrencyInstance();
        JOptionPane.showMessageDialog(null,purse + "\nTotal cash is " + currencyFmt.format(totalCash));
        String out = "";
        for( Coin coin : purse ) {
            out += coin.getName() + " value " + coin.getValue() + "\n";
        }// end for
        out += "\nTotal cash is " + currencyFmt.format(totalCash);
        JTextArea outArea = new JTextArea(out,20,20);
        JOptionPane.showMessageDialog(null,new JScrollPane(outArea));
    }
    
}

