import java.awt.*;
import java.lang.*;
import java.io.*;
import java.util.*;

public class Account
{
  protected long accountNo, balance;


  public Account ()
  {
    this (0, 0);
  }

  public Account (long accountNo, long balance)
  {
    this.accountNo = accountNo;
    this.balance = balance;
  }


  public String toString ()
  {
    String out = new String();

    out += accountNo +"\t";
    out += balance +"\t";

    out.trim();
    return out;
  }

  public void setAccount (long accountNo, long balance)
  {
    this.accountNo = accountNo;
    this.balance = balance;
  }

  public void setAccount (String account)
  {
    String tempAccountNo = new String();
    String tempBalance = new String();

    int i, flag = 0, start = 0;
    boolean add = true;

    while (!(Character.isDigit(account.charAt(start))) && !(Character.isLetter(account.charAt(start))))
      start++;

    for (i = start; i < account.length(); i++)
    {
      if (!(Character.isDigit(account.charAt(i))) && !(Character.isLetter(account.charAt(i))))
      {
        add = false;
        flag++;
      }
      else
        add = true;

//System.out.println ("i == "+ i +"\taccount.charAt(i) == "+ account.charAt(i) +"\tflag == "+ flag +"\tadd == "+ add);
      if (add)
      {
        switch (flag)
        {
          case (0):
            tempAccountNo += account.charAt(i);
            break;
          case (1):
            tempBalance += account.charAt(i);
            break;
        }
      }
    }

    this.accountNo = Long.decode(tempAccountNo).longValue();
    this.balance = Long.decode(tempBalance).longValue();
  }


  public boolean checkAccount (Account acct)
  {
    return (this.accountNo == acct.accountNo);
  }

  public boolean checkAccount (long accountNo)
  {
    return (this.accountNo == accountNo);
  }

  public void deposit (long amt, long cardNo)
  {
    balance += amt;
    TransactionReport trpt = new TransactionReport (this.accountNo, cardNo, "D", amt, this.balance);
    trpt.addTransaction();
  }

  public boolean withdraw (long amt, long cardNo)
  {
    if (amt < this.balance)
    {
      this.balance -= amt;
      TransactionReport trpt = new TransactionReport (this.accountNo, cardNo, "W", amt, this.balance);
      trpt.addTransaction();
      return true;
    }
    else
      return false;
  }

  public boolean transferFund (long amt, long cardNo, Account destination)
  {
    if (amt < this.balance)
    {
      this.balance -= amt;
      destination.balance += amt;
      TransactionReport trpt = new TransactionReport (this.accountNo, destination.accountNo, cardNo, "TF", amt, this.balance);
      trpt.addTransaction();
      return true;
    }
    else
      return false;
  }
}
