
import java.text.*;

public class Transaction{
	
	private DecimalFormat formatter = new DecimalFormat("$0.00");
	private int accountNumber; //the number of the account to which the transaction is being applied
	private double openingBalance; //the balance of the account before the transaction was applied
	private double closingBalance; //the balance of the account after the account was applied
	private TransactionType transactionType; //uses the TransactionType enum.
	
 	Transaction(TransactionType aTransactionType, int anAccountNumber, double anOpeningBalance, double   aClosingBalance){
		accountNumber = anAccountNumber;
		openingBalance = anOpeningBalance;
		closingBalance = aClosingBalance;
		transactionType = aTransactionType;
	}
	
	public String toString(){
		String result = new String("");
		
		if (transactionType == TransactionType.DEPOSIT){
			result = result + "Deposit to #" + accountNumber + "\t\t\tAmount: " + 
				formatter.format(closingBalance - openingBalance);
			if (closingBalance - openingBalance<1000)
				result = result + "\t\t\tBalance: " + formatter.format(closingBalance);
			else if (closingBalance - openingBalance<1000000)
				result = result + "\t\tBalance: " + formatter.format(closingBalance);
			else
				result = result + "\tBalance: " + formatter.format(closingBalance);
		}
		else if (transactionType == TransactionType.WITHDRAW){
			result = result + "Withdraw to #" + accountNumber + "\t\t\tAmount: " + 
				formatter.format(openingBalance - closingBalance);
			if (openingBalance - closingBalance<1000)
				result = result + "\t\t\tBalance: " + formatter.format(closingBalance);
			else if (openingBalance - closingBalance<1000000)
				result = result + "\t\tBalance: " + formatter.format(closingBalance);
			else
				result = result + "\tBalance: " + formatter.format(closingBalance);
		}
		else if (transactionType == TransactionType.SERVICE_CHARGE){
			result = result + "Service Charge to #" + accountNumber + "\t\tAmount: " + 
				formatter.format(openingBalance - closingBalance);
			if (closingBalance - openingBalance<1000)
				result = result + "\t\t\tBalance: " + formatter.format(closingBalance);
			else if (closingBalance - openingBalance<1000000)
				result = result + "\t\tBalance: " + formatter.format(closingBalance);
			else
				result = result + "\tBalance: " + formatter.format(closingBalance);
		}
		else{
			result = result + "Invalid Transaction to #" + accountNumber + "\tAmount: " + 
				formatter.format(0) + "\t\t\tBalance: " + formatter.format(closingBalance);
		}
		
		return result;
	}

}