package inheritance;

public class CreditAccount extends AbstractAccount {

  private double creditLine;

  public CreditAccount(double creditLine) {
    this.setCreditLine(creditLine);
  }

  public double getCreditLine() {
    return creditLine;
  }

  public void setCreditLine(double creditLine) {
    if (creditLine < 0)
      throw new IllegalArgumentException();

    if (creditLine + super.getBalance() < 0)
      throw new IllegalStateException();

    this.creditLine = creditLine;
  }
  
  @Override
  public void internalWithdraw(double amount) {

    if (creditLine + super.getBalance() - amount < 0)
      throw new IllegalStateException();

    super.balance -= amount;
  }

}
