Money Transfer Abstract Class: Create an abstract class FundTransfer with the following methods,
Method | Description |
def __init__(total_amount) | Define Constructor which having a argument as total amount in the account. |
def transfer(amount) | This method is a abstract method implemented in all child classes. |
def validate(account_no,amount) | If the accountNumber has 10 digit and the amount is greater than 0, then return 1, otherwise return 0. |
Note:
Create another class NEFTTransfer with the following methods:
Method | Description |
def __init__(total_amount) | Call the base class Constructor which having a argument as total amount in the account. |
def transfer(amount) | NEFT transfer is chargeable by the bank. It is chargeable when transfer amount is: <=5000 : No Charge >5000 and <=20000 : 50 Rs >20000 and <=100000 : 100 Rs >100000 : 1000 Rs |
def validate(account_no,amount) | If the accountNumber has 10 digit and the amount is greater than 0, then return 1, otherwise return 0. |
Note: NEFTTransfer class inherits the FundTransfer class.
Create another class IMPSTransfer with the following method,
Method | Description |
def __init__(total_amount) | Call the base class Constructor which having a argument as total amount in the account. |
def transfer(amount) | In this method, calculate the service charge of 2% and display the same as shown in sample output. |
def validate(account_no,amount) | If the accountNumber has 10 digit and the amount is greater than 0, then return 1, otherwise return 0. |
Note: IMPSTransfer class inherits the FundTransfer class.
Create another class RTGSTransfer with the following method,
Method | Description |
def __init__(total_amount) | Call the base class Constructor which having a argument as total amount in the account. |
def transfer(amount) | In this method,check whether the amount is greater than 10000. If the amount>10000, then display the balance amount after transaction. Otherwise display the error message as “RTGS can be done for amount more than 10000”. |
def validate(account_no,amount) | If the accountNumber has 10 digit and the amount is greater than 0, then return 1, otherwise return 0. |
Note: RTGSTransfer class inherits the FundTransfer class.
In the main section, get the values of total amount type from the user. Based on the transfer type, call the corresponding class and display the corresponding output.
Note: If choice not matches with any transfer type, then print “Wrong Transfer Type“.
Note: If the transfer amount is bigger than the balance in the account, then print “Sorry!! Not Sufficient Balance“.
Note : If validate() method returns 1,then perform corresponding operation according to the selected transfer type. If validate() method returns 0, then print “Invalid Input“.
Input and Output Fotmat
Refer sample input and output for formatting specifications.
All text in bold corresponds to the input and the rest corresponds to output.
Sample Input and Output 1
Enter the Total Amount:
20000
1.NEFT Transfer
2.IMPS Transfer
3.RTGS Transfer
Enter your choice:
1
Enter the account number
8672237473
Enter the amount to be transfer
8000
Your Balance:11950
Sample Input and Output 2
Enter the Total Amount:
15000
1.NEFT Transfer
2.IMPS Transfer
3.RTGS Transfer
Enter your choice:
2
Enter the account number
9876456783
Enter the amount to be transfer
16000
Sorry!! Not Sufficient Balance
Sample Input and Output 3
Enter the Total Amount:
20000
1.NEFT Transfer
2.IMPS Transfer
3.RTGS Transfer
Enter your choice:
3
Enter the account number
9878787654
Enter the amount to be transfer
5000
RTGS can be done for amount more than 10000
Solution
class FundTransfer:
def __init__(self, total_amount):
self.total_amount = total_amount
def transfer(self, amount):
pass
def validate(self, account_no, amount):
pass
class NEFTTransfer(FundTransfer):
def transfer(self, amount):
if amount <= 5000:
print("Your Balance : {}".format(self.total_amount - amount))
elif amount > 5000 and amount <= 20000:
service_charge = self.total_amount - amount - 50
print("Your Balance : {}".format(service_charge))
elif amount > 20000 and amount <= 100000:
service_charge = self.total_amount - amount - 100
print("Your Balance : {}".format(service_charge))
else:
service_charge = self.total_amount - amount - 1000
print("Your Balance : {}".format(service_charge))
def validate(self, account_no, amount):
if len(account_no) == 10 and amount > 0:
return 1
else:
return 0
class IMPSTransfer(FundTransfer):
def transfer(self, amount):
if amount > self.total_amount:
print("Sorry!! Not Sufficient Balance")
else:
service_charge = amount*0.2
print("Your Balance : {}".format(self.total_amount-service_charge))
def validate(self, account_no, amount):
if len(account_no) == 10 and amount > 0:
return 1
else:
return 0
class RTGSTransfer(FundTransfer):
def transfer(self, amount):
if amount > 10000:
print("Balance:", self.total_amount - amount)
else:
print("RTGS can be done for amount more than 10000")
def validate(self, account_no, amount):
if len(account_no) == 10 and amount > 0:
return 1
else:
return 0
n = int(input("Enter the Total Amount:\n"))
print("1.NEFT Transfer \n2.IMPS Transfer \n3.RTGS Transfer")
choice = int(input("Enter your choice:\n"))
if choice == 1:
account_no = raw_input("Enter the account number\n")
amount = int(input("Enter the amount to be transfer\n"))
obj = NEFTTransfer(n)
if obj.validate(account_no, amount):
obj.transfer(amount)
else:
print("Invalid Input")
elif choice == 2:
account_no = raw_input("Enter the account number\n")
amount = int(input("Enter the amount to be transfer\n"))
obj = IMPSTransfer(n)
if obj.validate(account_no, amount):
obj.transfer(amount)
else:
print("Invalid Input")
elif choice == 3:
account_no = raw_input("Enter the account number\n")
amount = int(input("Enter the amount to be transfer\n"))
obj = RTGSTransfer(n)
if obj.validate(account_no, amount):
obj.transfer(amount)
else:
print("Invalid Input")
else:
print("Wrong Transfer Type")
Happy Learning – If you require any further information, feel free to contact me.