Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Python: A bank issues two types of cards to customers: credit cards and de

ID: 3778388 • Letter: U

Question

Using Python:

A bank issues two types of cards to customers: credit cards and debit cards. Both types of cards have a card number and a name. Credit cards have interest rate and credit limit. Debit cards have PIN code and fund available to use.

Write a Python program to manage cards. Your project must follow these requirements.

Create a Card class. This class has two private instance variables: id and name. The __init__ method takes card number and customer name as two arguments and stores them in the instance variables. Define a displayIdName method to display id and name. Define two abstract methods inputInfo and displayInfo. These abstract methods have no real code. There is only one statement to raise a NotImplementedError exception.

Create a CreditCard class. This class is a derived class of the Card class. It has two additional private instance variables: interest_rate and credit_limit. Define an inputInfo method to input interest rate and credit limit, and a displayInfo method to display these two items.

Create a DebitCard class. This class is a derived class of the Card class. It has two additional private instance variables: pin and fund_available. Define an inputInfo method to input PIN code and fund available to use, and a displayInfo method to display these two items.

In the main module, ask user to enter name and card number. Ask the user whether it is a credit card or debit card. Create an object and call its inputInfo method to input information. Call the displayIdName method to display card number and name, and the displayInfo method to display other information.

Explanation / Answer

#!/usr/bin/python
import abc
class Card:
'Common base class for all cards'
def __init__(self, name, cardID):
self.name = name
self.id = cardID

def displayIdName(self):
print "Customer name : ",self.name, " ID : ", self.id;

@abc.abstractmethod
def inputInfo(self, rate, limit):
raise NotImplementedError("Please Implement this method")

@abc.abstractmethod
def displayInfo(self):
raise NotImplementedError("Please Implement this method")

class CreditCard(Card):

def __init__(self, name, cardID):
self.name = name
self.id = cardID   
def inputInfo(self, rate, limit):
self.rate = rate;
self.limit = limit;

def displayInfo(self):
print "Interest rate : ",self.rate, ", Credit Limit : ", self.limit;

class DebitCard(Card):

def __init__(self, name, cardID):
self.name = name
self.id = cardID   
def inputInfo(self, rate, limit):
self.pin = pin;
self.fundAvailable = fundAvailable;

def displayInfo(self):
print "Pin : ",self.pin, ", Fund Available : ", self.fundAvailable;

name = raw_input("Enter your name : ")
cardID = raw_input("Enter card number : ")

option = input("Choose : 1-> CreditCard 2-> DebitCard : ")
if(option == 1):
rate = input("Enter interest rate : ")
limit = input("Enter Credit Limit : ")
creditCard = CreditCard(name,cardID);
creditCard.inputInfo(rate,limit);
creditCard.displayIdName()
creditCard.displayInfo();   
elif(option == 2):
pin = input("Enter interest rate : ")
fundAvailable = input("Enter Credit Limit : ")
debitCard = DebitCard(name,cardID);
debitCard.inputInfo(pin,fundAvailable);
debitCard.displayIdName()
debitCard.displayInfo();

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote