Solución
solution.tsTypeScript
class BankAccount:
def __init__(self, balance: float) -> None:
self.balance = balance
def deposit(self, amount: float) -> None:
self.balance += amount
def withdraw(self, amount: float) -> None:
if amount <= self.balance:
self.balance -= amount
class SavingsAccount(BankAccount):
def __init__(self, balance: float, interest_rate: float) -> None:
# Llama al constructor del padre con super() y guarda el interest_rate
super().__init__(balance)
self.interest_rate = interest_rate
def apply_interest(self) -> None:
# Incrementa el saldo según la tasa de interés
self.balance *= (1 + self.interest_rate)
def savings_after_interest(initial: float, rate: float, months: int) -> float:
# Crea SavingsAccount y aplica el interés months veces; retorna saldo final
savings = SavingsAccount(initial, rate)
for i in range(months):
savings.apply_interest()
return savings.balance0respuestas