// Arup Guha
// 1/16/2010
// Inherits from Card and manages a standard Credit Card.

public class CreditCard extends Card {

	// Properties of a regular Credit Card.	
	protected double balance;
	protected double creditLimit;
	protected double interestRate;
	
	// A regular CreditCard has a limit of $3000 and a interest rate of 14%.
	public CreditCard(String first, String last, int year) {
		super(first, last, year);
		balance = 0;
		creditLimit = 3000;
		interestRate = 14;
	}
	
	// Add 1000 to your credit limit each year!
	public void advanceYear() {
		super.advanceYear();
		creditLimit += 1000;
	}
	
	// Add Interest for one month.
	public void addInterest() {
		balance += interestRate/1200.0*balance;
	}
	
	// Adds a charge to your card (if you can afford it) of amount dollars.
	// If you can't false is returned and no purchase is made.
	public boolean charge(double amount) {
		
		// We can charge it. Do so.
		if (amount + balance <= creditLimit) {		
			balance += amount;
			return true;
		}
		
		// We can't...
		return false;
	}
	
	// Pays off amount from your card. Currently no error checking
	// is done in this method, so you can pay off more than you owe.
	public double payoff(double amount) {
		
		// Nothing to be done.
		if (amount < 0) return 0;
		
		// Reduce the balance in this case.
		if (amount <= balance) {
			balance -= amount;
			return amount;
		}
		
		// Pay off in full here.
		double retval = balance;
		balance = 0;
		return retval;
	}
	
	// Returns a string representation of a Credit Card.
	public String toString() {
		return super.toString() +"\n"+"Balance: "+ balance + " Limit: "+creditLimit;
	}
}