/*
 * @topic T00705 Banking exception demo
 * @brief Java exception demo program
 */
package banking;
import java.util.Scanner;
public class Main
{
    public static void main(String args [])
    {
        // Pretend the customer just logged in into ATM
        Customer customer = new Customer(100.00);
        Account account = customer.getAccount();
        System.out.println("Hello! Available balance: $" + account.getBalance());

        // The only transaction supported is withdrawal.
        // Ask how much to withdraw:
        Scanner input = new Scanner(System.in);
        double amount = -1;
        while (amount == -1)
        {
            try
            {
                System.out.print("Please enter amount to withdraw: ");
                amount = input.nextDouble();
            }
            catch (java.util.InputMismatchException ex)
            {
                System.out.println("\t *** Bad input, please try again!");
                input.nextLine(); // advance to next line
            }
            finally
            {
                if (amount == 0)
                {
                    // Nothing to do!
                    System.out.println("\t Goodbye!");
                    return;
                }
            }
        }

        // Process transaction:
        long txnId = customer.processTransaction(amount );

        // Show results and exit:
        System.out.print("TXN: ");
        System.out.print(txnId);
        System.out.print(" Remaining balance: $");
        System.out.print(account.getBalance());

    } //main
} //Main