package hw03;

class Transaction {
	Currency startingBalance;
	char transactionType; // Either D for deposit or W for withdrawal or I for interest
	double transactionAmount;
	Currency endingBalance;
	static String[] monthName={ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

	public Transaction(Currency sbalance, char type, double amt) {
		startingBalance=sbalance;
		transactionType=type;
		transactionAmount=amt;
		if (transactionType=='W') {
			endingBalance=sbalance.add(-amt);
		} else { // Both deposits and interest get added to the balance
			endingBalance=sbalance.add(amt);
		}
	}

	public void printHeader(int acct,int month, int year) {
		System.out.println(" Transactions for account: " + acct + " for " + monthName[month] + " " + year);
		System.out.println(" | Start Bal.  | T | Amount      | End Bal.    |");
		System.out.println(" | ----------- + - + ----------- + ----------- |");
	}

	public void printLine() {
		System.out.println(String.format(" | $%10.02f | %c | $%10.02f | $%10.02f |",
			startingBalance.getAmount(),transactionType,transactionAmount,endingBalance.getAmount()));
	}
	public void printTrailer() {
		System.out.println(" | ----------- + - + ----------- + ----------- |");
		System.out.println("");
	}
}
