Solved

# It would be helpful if i could get a complete solution to the problem below.

Posted on 2009-02-10
509 Views
Create a class SavingsAccount. Use a static class variable to store the annualInterestRate for each of the savers. Each object of the class contains a private instance variable savingsBalance indicating the amount the saver currently has on deposit. Provide method calculateMonthlyInterest to calculate the monthly interest by multiplying the balance 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 driver program to test the class SavingsAccount.
Instantiate two different savingsAccount objects, saver1 and saver2, with balances of \$2000.00 and \$3000.00, respectively. Set annualInterestRate to 4%, then calculate the monthly interest and print the new balances for each of the savers. Then set the annualInterestRate to 5% and calculate the next months interest and print the new balances for each of the savers.
Write another class SpecialSavings that extends SavingsAccount to pay interest of 10% on accounts that have balances that exceed 10K. Also provided methods to deposit and take money out of savings account. Write a driver program to test the class SpecialSavings. Instantiate two different savingsAccount objects, saver1 and saver2, with balances of \$2000.00 and \$3000.00, respectively. Make a few deposits and withdrawals and show balance and interest earned for each account.

0
Question by:sangeeta74

LVL 15

Accepted Solution

Feel free to translate your homework to an appropriate language (C++ or Java based on description) ;)
``````class SavingsAccount(object):

annualInterestRate = 0.05

def __init__(self, balance):

self.savingsBalance = balance

def calculateMonthlyInterest(self):

return self.annualInterestRate * self.savingsBalance / 12

self.savingsBalance += self.calculateMonthlyInterest()

def modifyInterestRate(self, newRate):

self.annualInterestRate = newRate

class SpecialSavings(SavingsAccount):

def calculateMonthlyInterest(self):

if self.savingsBalance > 10000:

return self.savingsBalance / 1.2

else:

return 0

if __name__=='__main__':

saver1 = SavingsAccount(2000.)

saver2 = SavingsAccount(3000.)

SavingsAccount.annualInterestRate = 0.04

print 'new balance', saver1.savingsBalance, saver2.savingsBalance

SavingsAccount.annualInterestRate = 0.05

print 'new balance', saver1.savingsBalance, saver2.savingsBalance
``````
0

Author Closing Comment

Thanx.
0

## Featured Post

### Suggested Solutions

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…