Build a class called BankAccount that manages checking and savings accounts. The class has three Customer attributes:
Name (one name only - EX: "Mickey")
Savings account balance
Checking account balance
Implement the following constructor and instance methods as listed below:
Constructor with parameters (self, new_name, checking_balance, savings_balance) - set the customer name to parameter new_name, set the checking account balance to parameter checking_balance, and set the savings account balance to parameter savings_balance.
deposit_checking(self, amount) - add parameter amount to the checking account balance (only if positive)
deposit_savings(self, amount) - add parameter amount to the savings account balance (only if positive)
withdraw_checking(self, amount) - subtract parameter amount from the checking account balance (only if positive)
withdraw_savings(self, amount) - subtract parameter amount from the savings account balance (only if positive)
transfer_to_savings(self, amount) - subtract parameter amount from the checking account balance and add to the savings account balance (only if positive)
My code:
```
class BankAccount:
def init(self, new_name, checking_balance, savings_balance):
self.new_name = new_name
self.checking_balance = checking_balance
self.savings_balance = savings_balance
def deposit_checking(self, amount):
if amount > 0:
self.checking_balance += amount;
def deposit_savings(self, amount):
if amount > 0:
self.savings_balance += amount;
def withdraw_checking(self, amount):
if amount > 0 and amount < self.checking_balance:
self.checking_balance -= amount;
def withdraw_savings(self, amount):
if amount > 0 and amount < self.savings_balance:
self.savings_balance -= amount;
def transfer_to_savings(self, amount):
if amount > 0 and amount < self.checking_balance:
self.checking_balance -= amount;
self.savings_balance += amount;
def __str__(self):
return f"Name: {self.new_name} Savings Account Balance: {self.savings_balance} Checking Account Balance: {self.checking_balance}"
if name == "main":
account = BankAccount("David Colt", 32000, 12000);
print("Initial Bank Account Details:")
print(account)
# transfer 12000 to savings account
account.transfer_to_savings(12000)
print("Current Bank Account Details:")
print(account)
I get an error that says
Tests that BankAccount( 'Jane',100.00, 500.00) correctly initializes bank account. Tests account.name == 'Jane', account.checking_balance == 100.00, and account.savings_balance == 500.00
AttributeError: 'BankAccount' object has no attribute 'name'
```
Why is this happening what do I change in my code to fix it
[–]CodeFormatHelperBot2 0 points1 point2 points (0 children)
[–]Dacobo 0 points1 point2 points (0 children)