/**
 * Some client code for testing student ATM class definitions.
 * @author Derek Bridge 666 d.bridge@cs.ucc.ie
 */
public class CashFlow
{
    public static void main(String[] args)
    {   // These print statements let you see how far thro this main method
        // you get before an error is detected.
        System.out.print("a ");
        // Create an ATM in Ireland (denominations 5, 10, 20, 50)
        int[] euroDenoms = {5, 10, 20, 50};
        ATM atm1 = new ATM("euro", euroDenoms);
        System.out.print("b ");
        // Check the currency is correctly stored
        if (! atm1.getCurrency().equals("euro"))
        {   error();
        }
        System.out.print("c ");
        // Let's check it's empty
        if (atm1.getTotal() != 0)
        {   error();
        }
        System.out.print("d ");
        // How many of each kind of note does it contain?
        if (atm1.getQty(5) != 0 || atm1.getQty(10) != 0 ||
            atm1.getQty(20) != 0 || atm1.getQty(50) != 0)
        {   error();
        }
        System.out.print("e ");
        // Load it with three 5 euro notes.
        atm1.load(5, 3);
        System.out.print("f ");
        // Check these notes were loaded properly
        if (atm1.getQty(5) != 3 || atm1.getQty(10) != 0 ||
            atm1.getQty(20) != 0 || atm1.getQty(50) != 0 ||
            atm1.getTotal() != 15)
        {   error();
        }
        System.out.print("g ");
        // Do the same again for 10 and 50 euro notes.
        atm1.load(10, 2);
        atm1.load(50, 1);
        if (atm1.getQty(10) != 2 || atm1.getQty(50) != 1 ||
            atm1.getTotal() != 85)
        {   error();
        }
        System.out.print("h ");
        // Dispense 1 of the 10 euro notes.
        atm1.dispense(10, 1);
        System.out.print("i ");
        // Check this note was dispensed properly
        if (atm1.getQty(5) != 3 || atm1.getQty(10) != 1 ||
            atm1.getQty(20) != 0 || atm1.getQty(50) != 1 ||
            atm1.getTotal() != 75)
        {   error();
        }
        System.out.print("j ");
        // Do the same for 2 of the 5 euro notes
        atm1.dispense(5, 2);
        if (atm1.getQty(5) != 1 || atm1.getQty(10) != 1 ||
            atm1.getQty(20) != 0 || atm1.getQty(50) != 1 ||
            atm1.getTotal() != 65)
        {   error();
        }
        System.out.print("k ");
        // Now try to dispense 1 20 euro note (impossible!)
        atm1.dispense(20, 1);
        System.out.print("l ");
        // Check this left the ATM's contents unchanged
        if (atm1.getQty(5) != 1 || atm1.getQty(10) != 1 ||
            atm1.getQty(20) != 0 || atm1.getQty(50) != 1 ||
            atm1.getTotal() != 65)
        {   error();
        }
        System.out.print("m ");
        // Now try to find out how many 7 euro notes there are in this ATM
        if (atm1.getQty(7) != 0)
        {   error();
        }
        System.out.print("n ");
        // Similarly for 3 euro notes...
        if (atm1.getQty(3) != 0)
        {   error();
        }
        System.out.print("o ");
        // ...and 52 euro notes
        if (atm1.getQty(52) != 0)
        {   error();
        }
        System.out.print("p ");
        // Try to load a 3 euro note, a 7 euro note and a 52 euro note;
        // the contents should be unchanged
        atm1.load(3, 1);
        atm1.load(7, 1);
        atm1.load(52, 1);
        if (atm1.getQty(5) != 1 || atm1.getQty(10) != 1 ||
            atm1.getQty(20) != 0 || atm1.getQty(50) != 1 ||
            atm1.getTotal() != 65)
        {   error();
        }
        System.out.print("q ");
        // Try to dispense the same; the contents should be unchanged
        atm1.dispense(3, 1);
        atm1.dispense(7, 1);
        atm1.dispense(52, 1);
        if (atm1.getQty(5) != 1 || atm1.getQty(10) != 1 ||
            atm1.getQty(20) != 0 || atm1.getQty(50) != 1 ||
            atm1.getTotal() != 65)
        {   error();
        }
        System.out.print("r ");
        // Create an ATM in Chile (denominations 500, 1000, 2000, 5000, 10000)
        int[] chileDenoms = {500, 1000, 2000, 5000, 10000};
        ATM atm2 = new ATM("peso", chileDenoms);
        System.out.print("s ");
        // Check the currency in both ATMs is correctly stored
        if (! atm1.getCurrency().equals("euro") ||
            ! atm2.getCurrency().equals("peso"))
        {   error();
        }
        System.out.print("t ");
        // Load this new ATM and check the contents of both ATMs
        atm2.load(1000, 5);
        atm2.load(2000, 10);
        if (atm1.getQty(5) != 1 || atm1.getQty(10) != 1 ||
            atm1.getQty(20) != 0 || atm1.getQty(50) != 1 ||
            atm1.getTotal() != 65 || atm2.getQty(500) != 0 ||
            atm2.getQty(1000) != 5 || atm2.getQty(2000) != 10 ||
            atm2.getQty(5000) != 0 || atm2.getQty(10000) != 0 || 
            atm2.getTotal() != 25000)
        {   error();
        }
        System.out.println("u v w x y z ");
        System.out.println("\natm1.display()\n==============");
        atm1.display();
        System.out.println("\natm2.display()\n==============");
        atm2.display();
    }

    private static void error()
    {   System.out.println("There's an error in your ATM definition.");
        System.exit(1);
    }
}
