Create a SavingsAccount class that behaves just like a BankAccount using inheritanceCreate a SavingsAccount class that behaves just like a BankAccount, but also has an interest rate and a method that increases the balance by the appropriate amount of interest (Hint:use Inheritance).Note: Refer to the displayed test cases for better understanding.Sample Test CasesTest Case 1:Expected Output:account·number:784569874account·holder·name:Raviinitial·balance:50000interest·rate:2Savings·Account·Created:Account·Number:784569874Account·Holder:RaviBalance:50000.0Interest·Rate:2.0%After·adding·interest:Balance:·51000.0Test Case 2:Expected Output:account·number:547981235account·holder·name:Ramanainitial·balance:90000interest·rate:2.5Savings·Account·Created:Account·Number:547981235Account·Holder:RamanaBalance:90000.0Interest·Rate:2.5%After·adding·interest:Balance:·92250.0
Question
Create a SavingsAccount class that behaves just like a BankAccount using inheritanceCreate a SavingsAccount class that behaves just like a BankAccount, but also has an interest rate and a method that increases the balance by the appropriate amount of interest (Hint:use Inheritance).Note: Refer to the displayed test cases for better understanding.Sample Test CasesTest Case 1:Expected Output:account·number:784569874account·holder·name:Raviinitial·balance:50000interest·rate:2Savings·Account·Created:Account·Number:784569874Account·Holder:RaviBalance:50000.0Interest·Rate:2.0%After·adding·interest:Balance:·51000.0Test Case 2:Expected Output:account·number:547981235account·holder·name:Ramanainitial·balance:90000interest·rate:2.5Savings·Account·Created:Account·Number:547981235Account·Holder:RamanaBalance:90000.0Interest·Rate:2.5%After·adding·interest:Balance:·92250.0
Solution
Here is a Python solution for your problem:
class BankAccount:
def __init__(self, account_number, account_holder_name, balance):
self.account_number = account_number
self.account_holder_name = account_holder_name
self.balance = balance
def display(self):
print(f"Account Number: {self.account_number}")
print(f"Account Holder: {self.account_holder_name}")
print(f"Balance: {self.balance}")
class SavingsAccount(BankAccount):
def __init__(self, account_number, account_holder_name, balance, interest_rate):
super().__init__(account_number, account_holder_name, balance)
self.interest_rate = interest_rate
def add_interest(self):
self.balance += (self.balance * self.interest_rate) / 100
def display(self):
super().display()
print(f"Interest Rate: {self.interest_rate}%")
# Test Case 1
print("Test Case 1:")
account1 = SavingsAccount(784569874, "Ravi", 50000, 2)
account1.display()
account1.add_interest()
print("After adding interest:")
account1.display()
# Test Case 2
print("\nTest Case 2:")
account2 = SavingsAccount(547981235, "Ramana", 90000, 2.5)
account2.display()
account2.add_interest()
print("After adding interest:")
account2.display()
This code first defines a BankAccount class with an __init__ method to initialize the account number, account holder name, and balance, and a display method to print these details.
Then it defines a SavingsAccount class that inherits from BankAccount and adds an interest rate attribute and an add_interest method that increases the balance by the appropriate amount of interest. The display method in SavingsAccount calls the display method in BankAccount (using super().display()) and then prints the interest rate.
The test cases create instances of SavingsAccount, display their details, add interest, and then display the updated details.
Similar Questions
Test time left: 01:48:03Create a SavingsAccount class that behaves just like a BankAccount using inheritanceCreate a SavingsAccount class that behaves just like a BankAccount, but also has an interest rate and a method that increases the balance by the appropriate amount of interest (Hint:use Inheritance).Note: Refer to the displayed test cases for better understanding.Sample Test CasesTest Case 1:Expected Output:account·number:784569874account·holder·name:Raviinitial·balance:50000interest·rate:2Savings·Account·Created:Account·Number:784569874Account·Holder:RaviBalance:50000.0Interest·Rate:2.0%After·adding·interest:Balance:·51000.0Test Case 2:Expected Output:account·number:547981235account·holder·name:Ramanainitial·balance:90000interest·rate:2.5Savings·Account·Created:Account·Number:547981235Account·Holder:RamanaBalance:90000.0Interest·Rate:2.5%After·adding·interest:Balance:·92250.0
Assume that a bank maintains two kinds of accounts for customers, one called as savings account and the other as current account. The saving account provides compound interest (9%) and withdrawal facilities but not cheque book facility. The current account provides cheque book facility but no interest. Current account holders should also maintains a minimum balance of 500 and if the balance falls below this level, a service charge (Rs. 50) is imposed. Create a class Account as abstract that stores customer name, account number and opening balance (Rs. 500). From this derive the classes Current and Saving to make them more specific to their requirements. Include necessary member functions in order to achieve the following tasks:Get the account details using constructor.Display the account details using friend function.Deposit an amount (Rs. 10000) for a customer and update the balanceCompute and deposit interest. Now display the balance using inline function.Withdraw amount (Rs. 10200) for a customer after checking the balance and update the balance.Check for the minimum balance (for current account holders), impose penalty, if necessary, and update the balance.Count the number of transactions carried out using static member variable and display the count value by static member function OUTPUTAmount deposited successfullyCurrent Balance:10500Interest deposited successfullyCurrent Balance:10695Insufficient balance. Penalty of 50 imposedCustomer Name:JohnAccount Number:123456Current Balance:10695Customer Name:JaneAccount Number:654321Current Balance:450Total number of transactions:3
A bank has decided to renew its policy; according to the new policy, you can only own a savings account with minimum savings of Rs.1000. Construct a class ‘SavingAmount’ with only one integer instance variable ‘saving’. The class will have the following methods in it: A setter method 'setInitialSaving' that will take an integer as a parameter and set the value of savings equal to that of the integer .A getter method 'getCurrentSaving' that will return the saving .An increment method that will increase the savings by Rs.1000 .A decrement method that will decrease the savings by Rs.100 .A method to check the savings of a person say 'checkSaving'. If the savings amount is greater than or equal to Rs.1000, print “Congratulations! You have saved a good amount”. If the amount is less than Rs.1000 and greater than or equal to 0, print “Insufficient saving!”. If the savings amount is less than 0, print “You are in debt”.Input: Your program should take the integer amount.Output: The output should be in the following format.Call the 'decrementSaving' method once.Call the incrementSaving' method once.Call the 'checkSaving' method.Display the total savings.Sample Input:20000 Sample Output:Congratulations! You have saved a good amountYour current savings are Rs 20900Sample Input:-1000 Sample Output:You are in debtYour current savings are Rs 100Sample Input:-100 Sample Output:Insufficient saving!Your current savings are Rs 800
Assume that a bank maintains two kinds of account for its customers, one called savings account and the other current account. The savings account provides compound interest and withdrawal facilities but no cheque book facility. The current account provides cheque book facility but no interest. Current account holders should also maintain a minimum balance and if the balance falls below this level, a service charge is imposed.Create a class Account that stores customer name, account number and type of account. From this derive the classes Curr-acct and Sav-acct to make them more specific to their requirements. Include the necessary methods in order to achieve the following tasks:Accept deposit from a customer and update the balance.Display the balance.Compute and deposit interest.Permit withdrawal and update the balance.Check for the minimum balance, impose penalty, if necessary, and update the balance.Write a java program to create a bank account with Name of the account holder, type of account(savings or current), Account number and Balance amount in the . Also, create 5 customers for the class Bank_account using array of objects. Access the customers to perform credit, debit and display of balance.Input 1:Enter the customers:ReenaSavings1231000RobinCurrent4562000PraveenSavings7893000SherinCurrent2342500DeenaSavings5672000
Write a java program to create a bank account with Name of the account holder, type of account(savings or current), Account number and Balance amount in the account. Also, create 5 customers for the class Bank_account using array of objects. Access the customers to perform credit, debit and display of balance. Input 1: Enter the customers: Reena Savings 123 1000 Robin Current 456 2000 Praveen Savings 789 3000 Sherin Current 234 2500 Deena Savings 567 2000 Enter choice: 1. Credit 2. Debit
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.