In: Computer Science
Using Python
You just started your summer internship with NU Bank as part of its growing development team. Your first assignment is to design and build two classes that are to be utilized in both the banks website and internal applications. The first is a loan class representing a loan contract. The second is a customer class representing the individual receiving the loan. You will be building the business logic classes, so you don’t have to worry about forms for communicating with the user or data access classes to communicate with the database. To test your classes, you will use them in a test application. The requirements for your classes and the testing application are as follows:
You are to design and build 2 components of the Loan Processing System (LPS). There will be one class to represent loan contracts, and another to represent customers.
Each class should have at least 2 members and 2 methods.
The LPS will need to be able to check that the customer is at least 21 years old. A method
(IsEligible) should return true if the customer is 21 or older and false otherwise. An associated
method (GetAge) should return the customer’s age in years.
When assigning the customer to the loan, the assignment should be rejected if the customer is
ineligible based on age.
The following pieces of information about each business object are important to track:
o Customer:
▪ Customer ID, First Name, Last Name, Email, Phone, Date of
Birth
o Loan:
▪ Loan ID, Agent Name, Loan Amount, Interest Rate, Customer
For purposes of testing, you will write a small application
o Gather information you need about the Customer via console
input
o Any information you need about the Loan can be hard-coded using
the constructor
(__init__) or properties of the class
o The application must do the following – utilizing instances of
your classes:
▪ Ask the user for any needed information
▪ Allow the user to save information to the Customer object.
▪ Allow the user to retrieve information from the Customer object.
▪ Test the ‘IsEligible’ functionality and output the customer age, along with the
loan information, if the assignment of the customer to the loan succeeds.
EXPLANATION:
NOTE: IN CASE OF ANY DOUBT , ASK IN THE COMMENTS
CODE:
import datetime
class Loan:
loans = 0
def __init__(self,customer):
Loan.loans +=1
self.loanId = "L0" +
str(Loan.loans)
self.agent = "XYZ"
self.LoanAmount = 0
self.intRate = 10
self.customer = customer
def setLoanAmt(self, amount):
self.LoanAmount = amount
def IsEligible(self, customer):
custAge = customer.GetAge()
if custAge >= 21:
return True
return False
class Customer:
def __init__(self):
self.firstName = ""
self.lastName = ""
self.email = ""
self.dob = ""
def GetAge(self):
if self.dob == "":
print("Date of
birth not given")
return
currentTime = datetime.datetime.today()
currentYear =
int(currentTime.year)
currentMonth =
int(currentTime.month)
currentDay =
int(currentTime.day)
# customer dob
custDay = int(self.dob[:2])
custMonth =
int(self.dob[3:5])
custYear = int(self.dob[6:11])
# getting age
age = currentYear - custYear
if custMonth >
currentMonth:
age -= 1
elif custMonth == currentMonth and
custDay > currentDay:
age -= 1
return age
if __name__ == "__main__":
print("Welcome to the NU Bank! \nEnter your details below to apply for loan")
customer = Customer()
firstName = input("Enter your first name: ")
lastName = input("Enter your last name: ")
email = input("Enter email: ")
dob = input("Enter Date of birth in format
(dd-mm-yyyy):")
customer.first = firstName
customer.last = lastName
customer.email = email
customer.dob = dob
age = customer.GetAge()
loan = Loan(customer)
loanAmt = int(input("Enter the amount you want in
Loan: "))
loan.setLoanAmt(loanAmt)
if loan.IsEligible(customer):
print("Congratulations! Your loan
has been sanctioned")
print("Your age is eligible for
this loan , your age is: ", age)
print("Your loan ID:",
loan.loanId)
print("Your loan agent: ",
loan.agent)
print("Your loan amount: ",
loan.LoanAmount)
print("Interest Rate: ",
loan.intRate)
else:
print("Sorry your age is below
eligibility criteria")
print("Your age is:", age)
SCREENSHOTS: