Question

In: Computer Science

Python question Design a SavingsAccount class that stores a savings account's annual interest rate and balance....

Python question
Design a SavingsAccount class that stores a savings account's annual interest rate and balance. The class constructor should accept the amount of the savings account;s starting balance. The class should also have methods for subtracting the amount of a withdraw, adding the amount of a deposit, and adding the amount of monthly interest to the balance. The monthly interest rate is the annual interest rate divided by twelve. To add the monthly interest to the balance, multiply the monthly interest rate by the balance, and add the result to the balance.
Test the class in a program that calculates the balance of a savings account at the end of a period of time. it should ask the user for the annual interest rate, the starting balance, and the number of months that have passed since the account was established. A loop should then iterate once for every month, preforming the following:
a. ask the user for the amount deposited into the account during the month. use the class method to add this amount to the account balance.
b. ask the user for the amount withdrawn from the account during the month. use the class method to subtract this amount from the account balance.
c. use the class method to calculate the monthly interest.
After the last iteration, the program should display the ending balance, the total amount of deposits, the total amount of withdrawals, and the total interest earned. 
What I have so far:
class SavingsAccount:
    def __init__(self,balance):
        self.__balance = balance
        self.__annualRate = 0
        self.__monthInterest = 0

    def withdrawl(self, amt):
        self.__balance -= amt

    def deposit(self, amt):
        self.__balance += amt

    def set_interestRate(self,rate):
        self.__annualRate = rate

    #This method calculates mothly interest based on the annual interest rate and adds it to the balance
    def mth_interest(self):
        self.__monthInterest = self.__annualRate/12 * self.__balance
        self.__add_mth_interest(self.__monthInterest)
        return self.__monthInterest

    def __add_mth_interest(self, interest):
        self.__balance += interest

    def get_balance(self):
        return self.__balance

Solutions

Expert Solution

Thanks for the question.

Your class is all good, I have written the main function, that demonstrates your class.

Here is the updated code with screenshot.

===========================================================================

class SavingsAccount:
    def __init__(self, balance):
        self.__balance = balance
        self.__annualRate = 0
        self.__monthInterest = 0

    def withdrawl(self, amt):
        self.__balance -= amt

    def deposit(self, amt):
        self.__balance += amt

    def set_interestRate(self, rate):
        self.__annualRate = rate

    # This method calculates mothly interest based on the annual interest rate and adds it to the balance
    def mth_interest(self):
        self.__monthInterest = self.__annualRate / 1200 * self.__balance
        self.__add_mth_interest(self.__monthInterest)
        return self.__monthInterest

    def __add_mth_interest(self, interest):
        self.__balance += interest

    def get_balance(self):
        return self.__balance


def main():
    rate = float(input('Enter interest rate (%): '))
    balance = float(input('Enter starting balance: '))
    months = int(input('Enter the number of months: '))
    savingsAcct = SavingsAccount(balance)
    savingsAcct.set_interestRate(rate)

    total_deposit = 0
    total_withdrawn = 0
    interest_earned = 0
    for month in range(1, months + 1):
        amount = float(input('Enter amount deposited for month {}: '.format(month)))
        total_deposit += amount
        savingsAcct.deposit(amount)
        amount = float(input('Enter amount withdrawn for month {}: '.format(month)))
        total_withdrawn += amount
        savingsAcct.withdrawl(amount)
        interestEarned = savingsAcct.mth_interest()
        interest_earned += interestEarned

    print('Total Deposited Amount: ${:.2f}'.format(total_deposit))
    print('Total Withdrawn Amount: ${:.2f}'.format(total_withdrawn))
    print('Total Interest Earned : ${:.2f}'.format(interest_earned))
    print('Ending Balance        : ${:.2f}'.format(savingsAcct.get_balance()))
main()

======================================================================


Related Solutions

(java ) Create class SavingsAccount. Use a static variable annualInterestRate to store the annual interest rate...
(java ) Create class SavingsAccount. Use a static variable annualInterestRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable savingsBalance indicating the amount the saver currently has ondeposit. Provide method calculateMonthlyInterest to calculate the monthly www.oumstudents.tk interest by multiplying the savingsBalance by annualInterestRate divided by 12 this interest should be added to savingsBalance. Provide a static method modifyInterestRate that sets the annualInterestRate to a new value. Write a program...
Calculate the effective annual interest rate of the following savings schemes:
Calculate the effective annual interest rate of the following savings schemes:-12% annual interest compounded monthly.-18% annual interest compounded weekly. -Now calculate ie for the following data:-14% annual interest compounded monthly. Also semi annually.-10% annual interest compounded weekly. Also semi annually.-13% annual interest compounded weekly. Also for the next 2 years.-9% annual interest compounded semi annually. Now for the next 2 years.
A bank offers 9.00% on savings accounts. What is the effective annual rate if interest is...
A bank offers 9.00% on savings accounts. What is the effective annual rate if interest is compounded semi-annually? Answer format: Percentage Round to: 4 decimal places (Example: 9.2434%, % sign required. Will accept decimal format rounded to 6 decimal places (ex: 0.092434)) A bank offers 9.00% on savings accounts. What is the effective annual rate if interest is compounded quarterly? Answer format: Percentage Round to: 4 decimal places (Example: 9.2434%, % sign required. Will accept decimal format rounded to 6...
If you invest $7,000 into a savings account at an annual interest rate of 8% (APR),...
If you invest $7,000 into a savings account at an annual interest rate of 8% (APR), compounded semi-annually, how much will you have in the savings account after 11 years? Enter your response below (rounded to 2 decimal places).
If you invest $1,000 into a savings account at an annual interest rate of 3% (APR),...
If you invest $1,000 into a savings account at an annual interest rate of 3% (APR), compounded semi-annually, how much will you have in the savings account after 14 years?
You invest $7,000 into a savings account that pays an annual interest rate of 12.00%.
You invest $7,000 into a savings account that pays an annual interest rate of 12.00%. How much would you have in your account after 12 years?A.$20,549B.$24,010C.$27,272D.$30,343E.$33,231F.$35,942G.$38,483H.$40,861
A bank offers 9.00% on savings accounts. What is the effective annual rate if interest is...
A bank offers 9.00% on savings accounts. What is the effective annual rate if interest is compounded daily? Answer format: Percentage Round to: 4 decimal places (Example: 9.2434%, % sign required. Will accept decimal format rounded to 6 decimal places (ex: 0.092434)) A bank offers 9.00% on savings accounts. What is the effective annual rate if interest is compounded continuously? Answer format: Percentage Round to: 4 decimal places (Example: 9.2434%, % sign required. Will accept decimal format rounded to 6...
A bank offers 6.00% on savings accounts. What is the effective annual rate if interest is...
A bank offers 6.00% on savings accounts. What is the effective annual rate if interest is compounded daily? A bank offers 5.00% on savings accounts. What is the effective annual rate if interest is compounded continuously?
A bank offers 9.00% on savings accounts. What is the effective annual rate if interest is...
A bank offers 9.00% on savings accounts. What is the effective annual rate if interest is compounded monthly? Answer format: Percentage Round to: 4 decimal places (Example: 9.2434%, % sign required. Will accept decimal format rounded to 6 decimal places (ex: 0.092434))
If you deposit $7,000 into a savings account with an annual interest rate of 5% annually...
If you deposit $7,000 into a savings account with an annual interest rate of 5% annually which is compounded monthly, What would be the value of the investment after 10 years? Please show your work.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT